hivetrace 1.3.3__tar.gz → 1.3.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. {hivetrace-1.3.3 → hivetrace-1.3.5}/PKG-INFO +112 -1
  2. {hivetrace-1.3.3 → hivetrace-1.3.5}/README.md +111 -1
  3. hivetrace-1.3.5/hivetrace/__init__.py +145 -0
  4. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace/adapters/__init__.py +11 -0
  5. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace/adapters/base_adapter.py +42 -6
  6. hivetrace-1.3.5/hivetrace/adapters/crewai/adapter.py +438 -0
  7. hivetrace-1.3.5/hivetrace/adapters/crewai/decorators.py +56 -0
  8. hivetrace-1.3.5/hivetrace/adapters/crewai/monitored_crew.py +155 -0
  9. hivetrace-1.3.5/hivetrace/adapters/crewai/tool_wrapper.py +69 -0
  10. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace/adapters/langchain/__init__.py +3 -0
  11. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace/adapters/langchain/adapter.py +67 -0
  12. hivetrace-1.3.5/hivetrace/adapters/langchain/api.py +264 -0
  13. hivetrace-1.3.5/hivetrace/adapters/openai_agents/__init__.py +3 -0
  14. hivetrace-1.3.5/hivetrace/adapters/openai_agents/adapter.py +129 -0
  15. hivetrace-1.3.5/hivetrace/adapters/openai_agents/models.py +68 -0
  16. hivetrace-1.3.5/hivetrace/adapters/openai_agents/tracing.py +150 -0
  17. hivetrace-1.3.5/hivetrace/client/__init__.py +15 -0
  18. hivetrace-1.3.5/hivetrace/client/async_client.py +114 -0
  19. hivetrace-1.3.5/hivetrace/client/base.py +180 -0
  20. hivetrace-1.3.5/hivetrace/client/sync_client.py +116 -0
  21. hivetrace-1.3.5/hivetrace/errors/__init__.py +55 -0
  22. hivetrace-1.3.5/hivetrace/errors/api.py +35 -0
  23. hivetrace-1.3.5/hivetrace/errors/base.py +30 -0
  24. hivetrace-1.3.5/hivetrace/errors/network.py +32 -0
  25. hivetrace-1.3.5/hivetrace/errors/validation.py +37 -0
  26. hivetrace-1.3.5/hivetrace/handlers/__init__.py +14 -0
  27. hivetrace-1.3.5/hivetrace/handlers/error_handler.py +119 -0
  28. hivetrace-1.3.5/hivetrace/handlers/response_builder.py +80 -0
  29. hivetrace-1.3.5/hivetrace/models/__init__.py +50 -0
  30. hivetrace-1.3.5/hivetrace/models/requests.py +88 -0
  31. hivetrace-1.3.5/hivetrace/models/responses.py +102 -0
  32. hivetrace-1.3.5/hivetrace/utils/__init__.py +37 -0
  33. hivetrace-1.3.5/hivetrace/utils/error_helpers.py +78 -0
  34. hivetrace-1.3.5/hivetrace/utils/uuid_generator.py +19 -0
  35. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace.egg-info/PKG-INFO +112 -1
  36. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace.egg-info/SOURCES.txt +21 -2
  37. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace.egg-info/requires.txt +4 -0
  38. {hivetrace-1.3.3 → hivetrace-1.3.5}/setup.py +10 -2
  39. hivetrace-1.3.3/hivetrace/__init__.py +0 -36
  40. hivetrace-1.3.3/hivetrace/adapters/crewai/adapter.py +0 -507
  41. hivetrace-1.3.3/hivetrace/adapters/crewai/decorators.py +0 -65
  42. hivetrace-1.3.3/hivetrace/adapters/crewai/monitored_crew.py +0 -182
  43. hivetrace-1.3.3/hivetrace/adapters/crewai/tool_wrapper.py +0 -95
  44. hivetrace-1.3.3/hivetrace/crewai_adapter.py +0 -9
  45. hivetrace-1.3.3/hivetrace/hivetrace.py +0 -270
  46. hivetrace-1.3.3/hivetrace/utils/__init__.py +0 -7
  47. hivetrace-1.3.3/hivetrace/utils/uuid_generator.py +0 -15
  48. {hivetrace-1.3.3 → hivetrace-1.3.5}/LICENSE +0 -0
  49. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace/adapters/crewai/__init__.py +0 -0
  50. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace/adapters/crewai/monitored_agent.py +0 -0
  51. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace/adapters/langchain/behavior_tracker.py +0 -0
  52. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace/adapters/langchain/callback.py +0 -0
  53. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace/adapters/langchain/decorators.py +0 -0
  54. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace/adapters/langchain/models.py +0 -0
  55. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace/adapters/utils/__init__.py +0 -0
  56. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace/adapters/utils/logging.py +0 -0
  57. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace.egg-info/dependency_links.txt +0 -0
  58. {hivetrace-1.3.3 → hivetrace-1.3.5}/hivetrace.egg-info/top_level.txt +0 -0
  59. {hivetrace-1.3.3 → hivetrace-1.3.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hivetrace
3
- Version: 1.3.3
3
+ Version: 1.3.5
4
4
  Summary: Hivetrace SDK for monitoring LLM applications
5
5
  Home-page: http://hivetrace.ai
6
6
  Author: Raft
@@ -13,6 +13,7 @@ Provides-Extra: all
13
13
  Provides-Extra: base
14
14
  Provides-Extra: crewai
15
15
  Provides-Extra: langchain
16
+ Provides-Extra: openai_agents
16
17
  License-File: LICENSE
17
18
 
18
19
  # Hivetrace SDK
@@ -719,3 +720,113 @@ HIVETRACE_APP_ID=your-application-id
719
720
 
720
721
  ## License
721
722
  This project is licensed under the Apache License 2.0.
723
+
724
+ # OpenAI Agents Integration
725
+
726
+ ## Overview
727
+
728
+ HiveTrace SDK provides seamless integration with the [OpenAI Agents SDK](https://openai.github.io/openai-agents-python/) for monitoring agent interactions, tool usage, handoffs, and task executions in your OpenAI Agents-based applications.
729
+
730
+ ## Quick Start
731
+
732
+ ### Prerequisites
733
+
734
+ - HiveTrace SDK installed: `pip install hivetrace[openai_agents]`
735
+ - OpenAI Agents SDK installed: `pip install openai-agents`
736
+ - Valid HiveTrace application ID and access token
737
+
738
+ ### Basic Setup
739
+
740
+ **Step 1: Initialize the SDK (optional)**
741
+
742
+ ```python
743
+ from hivetrace import HivetraceSDK
744
+ from hivetrace.adapters.openai_agents import HivetraceOpenAIAgentProcessor
745
+
746
+ # Initialize SDK
747
+ hivetrace = HivetraceSDK(
748
+ config={
749
+ "HIVETRACE_URL": "https://your-hivetrace-instance.com",
750
+ "HIVETRACE_ACCESS_TOKEN": "your-access-token",
751
+ },
752
+ async_mode=False,
753
+ )
754
+ ```
755
+
756
+ **Step 2: Set Up the Tracing Processor**
757
+
758
+ The `HivetraceOpenAIAgentProcessor` hooks into the OpenAI Agents SDK tracing system and automatically logs all agent and tool activity to HiveTrace.
759
+
760
+ ```python
761
+ from agents import Agent, Runner, function_tool, set_trace_processors
762
+ from hivetrace.adapters.openai_agents import HivetraceOpenAIAgentProcessor
763
+
764
+
765
+ set_trace_processors(
766
+ HivetraceOpenAIAgentProcessor(
767
+ hivetrace_instance=hivetrace,
768
+ application_id="your-hivetrace-app-id",
769
+ )
770
+ )
771
+ ```
772
+
773
+ or setup environment variables HIVETRACE_URL, HIVETRACE_ACCESS_TOKEN, HIVETRACE_APPLICATION_ID for easier configuration:
774
+
775
+ ```python
776
+ from agents import Agent, Runner, function_tool, set_trace_processors
777
+ from hivetrace.adapters.openai_agents import HivetraceOpenAIAgentProcessor
778
+
779
+
780
+ set_trace_processors([HivetraceOpenAIAgentProcessor()])
781
+ ```
782
+
783
+ **Step 3: Call your agents**
784
+
785
+
786
+ ```python
787
+ from agents.tracing.create import trace
788
+
789
+ # Define your agent and tools as usual
790
+ @function_tool
791
+ def get_weather(city: str):
792
+ return f"The weather in {city} is sunny."
793
+
794
+ agent = Agent(
795
+ name="WeatherAgent",
796
+ instructions="You provide weather updates.",
797
+ tools=[get_weather],
798
+ )
799
+
800
+ # Run the agent
801
+ import asyncio
802
+ async def main():
803
+ with trace(
804
+ workflow_name="Agent workflow",
805
+ metadata={
806
+ "session_id": "your-session-id",
807
+ "user_id": "your-user-id",
808
+ },
809
+ ):
810
+ result = await Runner.run(agent, "What's the weather in Paris?")
811
+ print(result.final_output)
812
+
813
+ asyncio.run(main())
814
+ ```
815
+
816
+ ## Environment Variables
817
+
818
+ Set up your environment variables for easier configuration:
819
+
820
+ ```bash
821
+ # .env file
822
+ HIVETRACE_URL=https://your-hivetrace-instance.com
823
+ HIVETRACE_ACCESS_TOKEN=your-access-token
824
+ HIVETRACE_APP_ID=your-application-id
825
+ ```
826
+
827
+ ---
828
+
829
+ ## Advanced Usage
830
+
831
+
832
+ You now have complete monitoring of your OpenAI Agents system integrated with HiveTrace!
@@ -701,4 +701,114 @@ HIVETRACE_APP_ID=your-application-id
701
701
  ```
702
702
 
703
703
  ## License
704
- This project is licensed under the Apache License 2.0.
704
+ This project is licensed under the Apache License 2.0.
705
+
706
+ # OpenAI Agents Integration
707
+
708
+ ## Overview
709
+
710
+ HiveTrace SDK provides seamless integration with the [OpenAI Agents SDK](https://openai.github.io/openai-agents-python/) for monitoring agent interactions, tool usage, handoffs, and task executions in your OpenAI Agents-based applications.
711
+
712
+ ## Quick Start
713
+
714
+ ### Prerequisites
715
+
716
+ - HiveTrace SDK installed: `pip install hivetrace[openai_agents]`
717
+ - OpenAI Agents SDK installed: `pip install openai-agents`
718
+ - Valid HiveTrace application ID and access token
719
+
720
+ ### Basic Setup
721
+
722
+ **Step 1: Initialize the SDK (optional)**
723
+
724
+ ```python
725
+ from hivetrace import HivetraceSDK
726
+ from hivetrace.adapters.openai_agents import HivetraceOpenAIAgentProcessor
727
+
728
+ # Initialize SDK
729
+ hivetrace = HivetraceSDK(
730
+ config={
731
+ "HIVETRACE_URL": "https://your-hivetrace-instance.com",
732
+ "HIVETRACE_ACCESS_TOKEN": "your-access-token",
733
+ },
734
+ async_mode=False,
735
+ )
736
+ ```
737
+
738
+ **Step 2: Set Up the Tracing Processor**
739
+
740
+ The `HivetraceOpenAIAgentProcessor` hooks into the OpenAI Agents SDK tracing system and automatically logs all agent and tool activity to HiveTrace.
741
+
742
+ ```python
743
+ from agents import Agent, Runner, function_tool, set_trace_processors
744
+ from hivetrace.adapters.openai_agents import HivetraceOpenAIAgentProcessor
745
+
746
+
747
+ set_trace_processors(
748
+ HivetraceOpenAIAgentProcessor(
749
+ hivetrace_instance=hivetrace,
750
+ application_id="your-hivetrace-app-id",
751
+ )
752
+ )
753
+ ```
754
+
755
+ or setup environment variables HIVETRACE_URL, HIVETRACE_ACCESS_TOKEN, HIVETRACE_APPLICATION_ID for easier configuration:
756
+
757
+ ```python
758
+ from agents import Agent, Runner, function_tool, set_trace_processors
759
+ from hivetrace.adapters.openai_agents import HivetraceOpenAIAgentProcessor
760
+
761
+
762
+ set_trace_processors([HivetraceOpenAIAgentProcessor()])
763
+ ```
764
+
765
+ **Step 3: Call your agents**
766
+
767
+
768
+ ```python
769
+ from agents.tracing.create import trace
770
+
771
+ # Define your agent and tools as usual
772
+ @function_tool
773
+ def get_weather(city: str):
774
+ return f"The weather in {city} is sunny."
775
+
776
+ agent = Agent(
777
+ name="WeatherAgent",
778
+ instructions="You provide weather updates.",
779
+ tools=[get_weather],
780
+ )
781
+
782
+ # Run the agent
783
+ import asyncio
784
+ async def main():
785
+ with trace(
786
+ workflow_name="Agent workflow",
787
+ metadata={
788
+ "session_id": "your-session-id",
789
+ "user_id": "your-user-id",
790
+ },
791
+ ):
792
+ result = await Runner.run(agent, "What's the weather in Paris?")
793
+ print(result.final_output)
794
+
795
+ asyncio.run(main())
796
+ ```
797
+
798
+ ## Environment Variables
799
+
800
+ Set up your environment variables for easier configuration:
801
+
802
+ ```bash
803
+ # .env file
804
+ HIVETRACE_URL=https://your-hivetrace-instance.com
805
+ HIVETRACE_ACCESS_TOKEN=your-access-token
806
+ HIVETRACE_APP_ID=your-application-id
807
+ ```
808
+
809
+ ---
810
+
811
+ ## Advanced Usage
812
+
813
+
814
+ You now have complete monitoring of your OpenAI Agents system integrated with HiveTrace!
@@ -0,0 +1,145 @@
1
+ """
2
+ HiveTrace SDK - Python client for monitoring LLM applications.
3
+ """
4
+
5
+ # Main clients
6
+ from .client import AsyncHivetraceSDK, BaseHivetraceSDK, SyncHivetraceSDK
7
+
8
+ # Exceptions (only exception classes)
9
+ from .errors import (
10
+ APIError,
11
+ ConfigurationError,
12
+ ConnectionError,
13
+ HiveTraceError,
14
+ HTTPError,
15
+ InvalidFormatError,
16
+ InvalidParameterError,
17
+ JSONDecodeError,
18
+ MissingConfigError,
19
+ MissingParameterError,
20
+ NetworkError,
21
+ RateLimitError,
22
+ RequestError,
23
+ TimeoutError,
24
+ UnauthorizedError,
25
+ ValidationError,
26
+ )
27
+
28
+ # Handlers
29
+ from .handlers import ErrorHandler, ResponseBuilder
30
+
31
+ # Data models (Pydantic)
32
+ from .models import (
33
+ FunctionCallRequest,
34
+ HivetraceResponse,
35
+ InputRequest,
36
+ OutputRequest,
37
+ ProcessResponse,
38
+ SuccessResponse,
39
+ )
40
+
41
+ # Utils
42
+ from .utils import (
43
+ generate_uuid,
44
+ get_error_details,
45
+ get_error_type,
46
+ get_status_code,
47
+ is_connection_error,
48
+ is_error_response,
49
+ is_http_error,
50
+ is_json_decode_error,
51
+ is_request_error,
52
+ is_success_response,
53
+ is_timeout_error,
54
+ is_validation_error,
55
+ )
56
+
57
+ __all__ = [
58
+ # Main classes
59
+ "AsyncHivetraceSDK",
60
+ "SyncHivetraceSDK",
61
+ "BaseHivetraceSDK",
62
+ # Exceptions
63
+ "HiveTraceError",
64
+ "ConfigurationError",
65
+ "MissingConfigError",
66
+ "UnauthorizedError",
67
+ "ValidationError",
68
+ "InvalidParameterError",
69
+ "MissingParameterError",
70
+ "InvalidFormatError",
71
+ "NetworkError",
72
+ "ConnectionError",
73
+ "TimeoutError",
74
+ "RequestError",
75
+ "APIError",
76
+ "HTTPError",
77
+ "JSONDecodeError",
78
+ "RateLimitError",
79
+ # Models
80
+ "HivetraceResponse",
81
+ "SuccessResponse",
82
+ "ProcessResponse",
83
+ "InputRequest",
84
+ "OutputRequest",
85
+ "FunctionCallRequest",
86
+ # Handlers
87
+ "ErrorHandler",
88
+ "ResponseBuilder",
89
+ # Utils
90
+ "generate_uuid",
91
+ "is_error_response",
92
+ "is_success_response",
93
+ "get_error_type",
94
+ "get_error_details",
95
+ "get_status_code",
96
+ "is_connection_error",
97
+ "is_timeout_error",
98
+ "is_http_error",
99
+ "is_json_decode_error",
100
+ "is_request_error",
101
+ "is_validation_error",
102
+ ]
103
+
104
+ # Optional adapters
105
+ try:
106
+ from hivetrace.adapters.crewai import CrewAIAdapter as _CrewAIAdapter
107
+ from hivetrace.adapters.crewai import trace as _crewai_trace
108
+
109
+ CrewAIAdapter = _CrewAIAdapter
110
+ crewai_trace = _crewai_trace
111
+ trace = _crewai_trace
112
+
113
+ __all__.extend(["CrewAIAdapter", "crewai_trace", "trace"])
114
+ except ImportError:
115
+ pass
116
+
117
+ try:
118
+ from hivetrace.adapters.langchain import (
119
+ LangChainAdapter as _LangChainAdapter,
120
+ )
121
+ from hivetrace.adapters.langchain import (
122
+ run_with_tracing as _run_with_tracing,
123
+ )
124
+ from hivetrace.adapters.langchain import (
125
+ run_with_tracing_async as _run_with_tracing_async,
126
+ )
127
+ from hivetrace.adapters.langchain import (
128
+ trace as _langchain_trace,
129
+ )
130
+
131
+ LangChainAdapter = _LangChainAdapter
132
+ langchain_trace = _langchain_trace
133
+ run_with_tracing = _run_with_tracing
134
+ run_with_tracing_async = _run_with_tracing_async
135
+
136
+ __all__.extend(
137
+ [
138
+ "LangChainAdapter",
139
+ "langchain_trace",
140
+ "run_with_tracing",
141
+ "run_with_tracing_async",
142
+ ]
143
+ )
144
+ except ImportError:
145
+ pass
@@ -30,3 +30,14 @@ try:
30
30
  __all__.extend(["LangChainAdapter", "langchain_trace"])
31
31
  except ImportError:
32
32
  pass
33
+
34
+ try:
35
+ from hivetrace.adapters.openai_agents import (
36
+ HivetraceOpenAIAgentProcessor as _HivetraceOpenAIAgentProcessor,
37
+ )
38
+
39
+ HivetraceOpenAIAgentProcessor = _HivetraceOpenAIAgentProcessor
40
+
41
+ __all__.extend(["HivetraceOpenAIAgentProcessor"])
42
+ except ImportError:
43
+ pass
@@ -54,8 +54,14 @@ class BaseAdapter:
54
54
  - additional_params_from_caller: Additional parameters to include in the log
55
55
  """
56
56
  final_additional_params = additional_params_from_caller or {}
57
- final_additional_params.setdefault("user_id", self.user_id)
58
- final_additional_params.setdefault("session_id", self.session_id)
57
+ if hasattr(self, "user_id") and self.user_id is not None and self.user_id != "":
58
+ final_additional_params.setdefault("user_id", self.user_id)
59
+ if (
60
+ hasattr(self, "session_id")
61
+ and self.session_id is not None
62
+ and self.session_id != ""
63
+ ):
64
+ final_additional_params.setdefault("session_id", self.session_id)
59
65
 
60
66
  log_kwargs = {
61
67
  "application_id": self.application_id,
@@ -71,19 +77,49 @@ class BaseAdapter:
71
77
  if tool_call_details is None:
72
78
  print("Warning: tool_call_details is None for function_call")
73
79
  return
74
- log_kwargs.update(tool_call_details)
80
+ merged_tool_details = dict(tool_call_details)
81
+ ap = dict(merged_tool_details.get("additional_parameters", {}) or {})
82
+ if (
83
+ hasattr(self, "user_id")
84
+ and self.user_id is not None
85
+ and self.user_id != ""
86
+ ):
87
+ ap.setdefault("user_id", self.user_id)
88
+ if (
89
+ hasattr(self, "session_id")
90
+ and self.session_id is not None
91
+ and self.session_id != ""
92
+ ):
93
+ ap.setdefault("session_id", self.session_id)
94
+ if ap:
95
+ merged_tool_details["additional_parameters"] = ap
96
+ log_kwargs.update(merged_tool_details)
75
97
  else:
76
98
  print(f"Error: Unsupported log_method_name_stem: {log_method_name_stem}")
77
99
  return
78
100
 
79
- method_to_call_name = f"{log_method_name_stem}{'_async' if is_async else ''}"
101
+ # Both SyncHivetraceSDK and AsyncHivetraceSDK expose the same method names
102
+ # (input/output/function_call). In async mode they are coroutines.
103
+ method_to_call_name = log_method_name_stem
80
104
 
81
105
  try:
82
106
  actual_log_method = getattr(self.trace, method_to_call_name)
83
107
  if is_async:
84
108
  import asyncio
85
-
86
- asyncio.create_task(actual_log_method(**log_kwargs))
109
+ import inspect
110
+
111
+ try:
112
+ maybe_coro = actual_log_method(**log_kwargs)
113
+ except TypeError:
114
+ # Fallback: call without kwargs if signature mismatch (defensive)
115
+ maybe_coro = actual_log_method()
116
+
117
+ if inspect.isawaitable(maybe_coro):
118
+ asyncio.create_task(maybe_coro)
119
+ else:
120
+ # If the method is unexpectedly sync in async mode, call directly
121
+ # to avoid dropping the log.
122
+ pass
87
123
  else:
88
124
  actual_log_method(**log_kwargs)
89
125
  except AttributeError: