hivetrace 1.3.3__tar.gz → 1.3.4__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 (36) hide show
  1. {hivetrace-1.3.3 → hivetrace-1.3.4}/PKG-INFO +112 -1
  2. {hivetrace-1.3.3 → hivetrace-1.3.4}/README.md +111 -1
  3. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/__init__.py +11 -0
  4. hivetrace-1.3.4/hivetrace/adapters/openai_agents/__init__.py +3 -0
  5. hivetrace-1.3.4/hivetrace/adapters/openai_agents/adapter.py +129 -0
  6. hivetrace-1.3.4/hivetrace/adapters/openai_agents/models.py +68 -0
  7. hivetrace-1.3.4/hivetrace/adapters/openai_agents/tracing.py +149 -0
  8. hivetrace-1.3.4/hivetrace/utils/uuid_generator.py +28 -0
  9. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace.egg-info/PKG-INFO +112 -1
  10. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace.egg-info/SOURCES.txt +4 -0
  11. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace.egg-info/requires.txt +4 -0
  12. {hivetrace-1.3.3 → hivetrace-1.3.4}/setup.py +10 -2
  13. hivetrace-1.3.3/hivetrace/utils/uuid_generator.py +0 -15
  14. {hivetrace-1.3.3 → hivetrace-1.3.4}/LICENSE +0 -0
  15. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/__init__.py +0 -0
  16. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/base_adapter.py +0 -0
  17. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/crewai/__init__.py +0 -0
  18. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/crewai/adapter.py +0 -0
  19. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/crewai/decorators.py +0 -0
  20. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/crewai/monitored_agent.py +0 -0
  21. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/crewai/monitored_crew.py +0 -0
  22. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/crewai/tool_wrapper.py +0 -0
  23. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/langchain/__init__.py +0 -0
  24. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/langchain/adapter.py +0 -0
  25. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/langchain/behavior_tracker.py +0 -0
  26. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/langchain/callback.py +0 -0
  27. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/langchain/decorators.py +0 -0
  28. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/langchain/models.py +0 -0
  29. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/utils/__init__.py +0 -0
  30. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/adapters/utils/logging.py +0 -0
  31. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/crewai_adapter.py +0 -0
  32. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/hivetrace.py +0 -0
  33. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace/utils/__init__.py +0 -0
  34. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace.egg-info/dependency_links.txt +0 -0
  35. {hivetrace-1.3.3 → hivetrace-1.3.4}/hivetrace.egg-info/top_level.txt +0 -0
  36. {hivetrace-1.3.3 → hivetrace-1.3.4}/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.4
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!
@@ -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
@@ -0,0 +1,3 @@
1
+ from hivetrace.adapters.openai_agents.tracing import HivetraceOpenAIAgentProcessor
2
+
3
+ __all__ = ["HivetraceOpenAIAgentProcessor"]
@@ -0,0 +1,129 @@
1
+ import uuid
2
+
3
+ from hivetrace.adapters.base_adapter import BaseAdapter
4
+ from hivetrace.adapters.openai_agents.models import AgentCall, Call
5
+
6
+
7
+ class OpenaiAgentsAdapter(BaseAdapter):
8
+ def __init__(self, *args, **kwargs):
9
+ super().__init__(*args, **kwargs)
10
+
11
+ def log_traces(self, trace_calls: dict[str, Call | None], conversation_uuid: str):
12
+ _trace_calls = self._join_handoff_spans(trace_calls)
13
+ _trace_calls = self._join_agent_calling_tool_spans(_trace_calls)
14
+ source_agent = _trace_calls[list(_trace_calls.keys())[0]]
15
+ self._log_start_message(source_agent, conversation_uuid)
16
+
17
+ for trace_call in _trace_calls.values():
18
+ if trace_call is None or trace_call.span_parent_id is None:
19
+ continue
20
+
21
+ parent_agent: AgentCall = _trace_calls[trace_call.span_parent_id]
22
+ if trace_call.type == "agent":
23
+ additional_params = {
24
+ "agent_conversation_id": conversation_uuid,
25
+ "is_final_answer": False,
26
+ "agents": {
27
+ trace_call.agent_uuid: {
28
+ "agent_parent_id": parent_agent.agent_uuid,
29
+ "name": trace_call.name,
30
+ "description": trace_call.instructions,
31
+ },
32
+ },
33
+ }
34
+ self.output(
35
+ message=trace_call.output,
36
+ additional_params=additional_params,
37
+ )
38
+
39
+ elif trace_call.type == "tool":
40
+ self._prepare_and_log(
41
+ log_method_name_stem="function_call",
42
+ is_async=False,
43
+ tool_call_details={
44
+ "application_id": self.application_id,
45
+ "tool_call_id": str(uuid.uuid4()),
46
+ "func_name": trace_call.name,
47
+ "func_args": f"{trace_call.input}",
48
+ "func_result": f"{trace_call.output}",
49
+ "additional_parameters": {
50
+ "agent_conversation_id": conversation_uuid,
51
+ "agents": {
52
+ parent_agent.agent_uuid: {
53
+ "name": parent_agent.name,
54
+ "description": parent_agent.instructions,
55
+ },
56
+ },
57
+ },
58
+ },
59
+ )
60
+ self._log_final_message(source_agent, conversation_uuid)
61
+
62
+ def _join_agent_calling_tool_spans(
63
+ self, trace_calls: dict[str, Call | None]
64
+ ) -> dict[str, Call | None]:
65
+ for span_id, span in trace_calls.items():
66
+ if span.type == "agent" and span.span_parent_id is not None:
67
+ parent = trace_calls[span.span_parent_id]
68
+ if parent.type == "tool":
69
+ trace_calls[span.span_parent_id] = None
70
+ trace_calls[span_id].span_parent_id = parent.span_parent_id
71
+ trace_calls[span_id].input = (
72
+ parent.input if span.input is None else span.input
73
+ )
74
+ trace_calls[span_id].output = (
75
+ parent.output if span.output is None else span.output
76
+ )
77
+ return trace_calls
78
+
79
+ def _join_handoff_spans(
80
+ self, trace_calls: dict[str, Call | None]
81
+ ) -> dict[str, Call | None]:
82
+ for span in reversed(trace_calls.values()):
83
+ if span.type == "handoff" and span.span_parent_id is not None:
84
+ parent = trace_calls[span.span_parent_id]
85
+ child = next(
86
+ (
87
+ call
88
+ for call in trace_calls.values()
89
+ if call.name == span.to_agent
90
+ ),
91
+ None,
92
+ )
93
+ if parent is None:
94
+ continue
95
+ child.span_parent_id = span.span_parent_id
96
+ if parent.output is None:
97
+ parent.output = child.output
98
+ if parent.input is None:
99
+ parent.input = child.input
100
+ return trace_calls
101
+
102
+ def _log_start_message(self, trace_call: AgentCall, conversation_uuid: str):
103
+ self.input(
104
+ message=trace_call.input,
105
+ additional_params={
106
+ "agent_conversation_id": conversation_uuid,
107
+ "agents": {
108
+ trace_call.agent_uuid: {
109
+ "name": trace_call.name,
110
+ "description": trace_call.instructions,
111
+ },
112
+ },
113
+ },
114
+ )
115
+
116
+ def _log_final_message(self, trace_call: AgentCall, conversation_uuid: str):
117
+ self.output(
118
+ message=trace_call.output,
119
+ additional_params={
120
+ "agent_conversation_id": conversation_uuid,
121
+ "is_final_answer": True,
122
+ "agents": {
123
+ trace_call.agent_uuid: {
124
+ "name": trace_call.name,
125
+ "description": trace_call.instructions,
126
+ },
127
+ },
128
+ },
129
+ )
@@ -0,0 +1,68 @@
1
+ """
2
+ Models for OpenAI Agents hivetrace adapter.
3
+ """
4
+
5
+ from dataclasses import dataclass
6
+ from typing import Literal, Optional
7
+
8
+ from hivetrace.utils.uuid_generator import generate_agent_uuid
9
+
10
+
11
+ @dataclass
12
+ class Call:
13
+ """
14
+ Base class for all calls.
15
+ """
16
+
17
+ span_parent_id: Optional[str] = None
18
+ type: Literal["agent", "tool", "handoff"] = "agent"
19
+ name: str = ""
20
+ input: Optional[str] = None
21
+ output: Optional[str] = None
22
+ instructions: Optional[str] = None
23
+ from_agent: Optional[str] = None
24
+ to_agent: Optional[str] = None
25
+
26
+ def to_dict(self):
27
+ return {
28
+ "span_parent_id": self.span_parent_id,
29
+ "type": self.type,
30
+ "name": self.name,
31
+ "input": self.input,
32
+ "output": self.output,
33
+ "instructions": self.instructions,
34
+ "from_agent": self.from_agent,
35
+ "to_agent": self.to_agent,
36
+ }
37
+
38
+
39
+ @dataclass
40
+ class AgentCall(Call):
41
+ """
42
+ Call for an agent.
43
+ """
44
+
45
+ type: Literal["agent"] = "agent"
46
+
47
+ @property
48
+ def agent_uuid(self) -> str:
49
+ return generate_agent_uuid(self.name)
50
+
51
+
52
+ @dataclass
53
+ class ToolCall(Call):
54
+ """
55
+ Call for a tool.
56
+ """
57
+
58
+ type: Literal["tool"] = "tool"
59
+
60
+
61
+ @dataclass
62
+ class HandoffCall(Call):
63
+ """
64
+ Call for a handoff.
65
+ """
66
+
67
+ type: Literal["handoff"] = "handoff"
68
+ name: str = "handoff_call"
@@ -0,0 +1,149 @@
1
+ """
2
+ Tracing processor for OpenAI Agents.
3
+ """
4
+
5
+ import os
6
+
7
+ from agents.tracing import TracingProcessor
8
+ from agents.tracing.span_data import (
9
+ AgentSpanData,
10
+ FunctionSpanData,
11
+ HandoffSpanData,
12
+ ResponseSpanData,
13
+ )
14
+ from agents.tracing.spans import Span
15
+ from agents.tracing.traces import Trace
16
+ from openai.types.responses import ResponseFunctionToolCall, ResponseOutputMessage
17
+
18
+ from hivetrace import HivetraceSDK
19
+ from hivetrace.adapters.openai_agents.adapter import OpenaiAgentsAdapter
20
+ from hivetrace.adapters.openai_agents.models import (
21
+ AgentCall,
22
+ Call,
23
+ HandoffCall,
24
+ ToolCall,
25
+ )
26
+ from hivetrace.utils.uuid_generator import generate_uuid
27
+
28
+
29
+ class HivetraceOpenAIAgentProcessor(TracingProcessor):
30
+ """
31
+ Tracing processor for OpenAI Agents.
32
+
33
+ This class is responsible for tracing the execution of OpenAI Agents.
34
+ It is used to log the traces of the agents and tools.
35
+
36
+ Attributes:
37
+ conversation_uuid: str
38
+ The UUID of the conversation.
39
+
40
+ adapter: OpenaiAgentsAdapter
41
+ The adapter for the OpenAI Agents.
42
+
43
+ _trace_calls: dict[str, Call | None]
44
+ The trace calls.
45
+ """
46
+
47
+ conversation_uuid: str = ""
48
+
49
+ def __init__(
50
+ self,
51
+ hivetrace_instance: HivetraceSDK | None = None,
52
+ application_id: str | None = os.getenv("HIVETRACE_APPLICATION_ID"),
53
+ ):
54
+ if not application_id:
55
+ raise ValueError("HIVETRACE_APPLICATION_ID is not set")
56
+
57
+ if not hivetrace_instance:
58
+ hivetrace_instance = HivetraceSDK(
59
+ config={
60
+ "HIVETRACE_URL": os.getenv("HIVETRACE_URL"),
61
+ "HIVETRACE_ACCESS_TOKEN": os.getenv("HIVETRACE_ACCESS_TOKEN"),
62
+ },
63
+ async_mode=False,
64
+ )
65
+ self.adapter = OpenaiAgentsAdapter(
66
+ hivetrace=hivetrace_instance,
67
+ application_id=application_id,
68
+ )
69
+ self._trace_calls: dict[str, Call | None] = {}
70
+
71
+ def on_trace_start(self, trace: Trace):
72
+ metadata = trace.metadata or {}
73
+ self.adapter.user_id = metadata.get("user_id", generate_uuid())
74
+ self.adapter.session_id = metadata.get("session_id", generate_uuid())
75
+ self.conversation_uuid = generate_uuid()
76
+
77
+ def on_trace_end(self, _: Trace):
78
+ self.adapter.log_traces(self._trace_calls, self.conversation_uuid)
79
+
80
+ def on_span_start(self, span: Span):
81
+ if span.span_id not in self._trace_calls:
82
+ # Save start of agent call
83
+ if (
84
+ isinstance(span.span_data, AgentSpanData)
85
+ and span.span_data.type == "agent"
86
+ ):
87
+ self._trace_calls[span.span_id] = AgentCall(
88
+ span_parent_id=span.parent_id,
89
+ name=getattr(span.span_data, "name", "Unknown"),
90
+ )
91
+
92
+ # Save start of tool call
93
+ elif (
94
+ isinstance(span.span_data, FunctionSpanData)
95
+ and span.span_data.type == "function"
96
+ ):
97
+ self._trace_calls[span.span_id] = ToolCall(
98
+ span_parent_id=span.parent_id,
99
+ name=getattr(span.span_data, "name", "Unknown"),
100
+ )
101
+
102
+ def on_span_end(self, span: Span):
103
+ # Save end of handoff call
104
+ if (
105
+ isinstance(span.span_data, HandoffSpanData)
106
+ and span.span_data.type == "handoff"
107
+ ):
108
+ if (
109
+ span.span_data.from_agent is not None
110
+ and span.span_data.to_agent is not None
111
+ ):
112
+ self._trace_calls[span.span_id] = HandoffCall(
113
+ span_parent_id=span.parent_id,
114
+ from_agent=span.span_data.from_agent,
115
+ to_agent=span.span_data.to_agent,
116
+ )
117
+
118
+ # Save input and output for tool
119
+ if (
120
+ isinstance(span.span_data, FunctionSpanData)
121
+ and span.span_data.type == "function"
122
+ ):
123
+ self._trace_calls[span.span_id].input = span.span_data.input
124
+ self._trace_calls[span.span_id].output = span.span_data.output
125
+
126
+ # Save input and output for agent
127
+ elif (
128
+ isinstance(span.span_data, ResponseSpanData)
129
+ and span.span_data.type == "response"
130
+ ):
131
+ response = span.span_data.response
132
+ if not response or not response.output:
133
+ return
134
+ if isinstance(response.output[0], ResponseOutputMessage):
135
+ self._trace_calls[span.parent_id].input = span.span_data.input[0][
136
+ "content"
137
+ ]
138
+ self._trace_calls[span.parent_id].output = (
139
+ response.output[0].content[0].text
140
+ )
141
+ self._trace_calls[span.parent_id].instructions = response.instructions
142
+ elif isinstance(response.output[0], ResponseFunctionToolCall):
143
+ self._trace_calls[span.parent_id].instructions = response.instructions
144
+
145
+ def shutdown(self):
146
+ self._trace_calls = {}
147
+
148
+ def force_flush(self):
149
+ self._trace_calls = {}
@@ -0,0 +1,28 @@
1
+ """
2
+ UUID generation and management utilities.
3
+ """
4
+
5
+ import uuid
6
+
7
+
8
+ def generate_uuid() -> str:
9
+ """
10
+ Generate a new UUID string.
11
+
12
+ Returns:
13
+ - A newly generated UUID as a string
14
+ """
15
+ return str(uuid.uuid4())
16
+
17
+
18
+ def generate_agent_uuid(agent_name: str) -> str:
19
+ """
20
+ Generate a UUID for an agent from its name.
21
+
22
+ Parameters:
23
+ - agent_name: The name of the agent
24
+
25
+ Returns:
26
+ - A UUID for the agent as a string
27
+ """
28
+ return str(uuid.uuid3(uuid.NAMESPACE_DNS, agent_name))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hivetrace
3
- Version: 1.3.3
3
+ Version: 1.3.4
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!
@@ -24,6 +24,10 @@ hivetrace/adapters/langchain/behavior_tracker.py
24
24
  hivetrace/adapters/langchain/callback.py
25
25
  hivetrace/adapters/langchain/decorators.py
26
26
  hivetrace/adapters/langchain/models.py
27
+ hivetrace/adapters/openai_agents/__init__.py
28
+ hivetrace/adapters/openai_agents/adapter.py
29
+ hivetrace/adapters/openai_agents/models.py
30
+ hivetrace/adapters/openai_agents/tracing.py
27
31
  hivetrace/adapters/utils/__init__.py
28
32
  hivetrace/adapters/utils/logging.py
29
33
  hivetrace/utils/__init__.py
@@ -8,6 +8,7 @@ langchain-community==0.3.18
8
8
  langchain-openai==0.2.5
9
9
  langchain==0.3.19
10
10
  langchain_experimental==0.3.4
11
+ openai-agents>=0.1.0
11
12
  python-dotenv>=1.0.1
12
13
 
13
14
  [base]
@@ -22,3 +23,6 @@ langchain-community==0.3.18
22
23
  langchain-openai==0.2.5
23
24
  langchain==0.3.19
24
25
  langchain_experimental==0.3.4
26
+
27
+ [openai_agents]
28
+ openai-agents>=0.1.0
@@ -22,9 +22,13 @@ crewai_requires = [
22
22
  "crewai>=0.95.0",
23
23
  ]
24
24
 
25
+ openai_agents_requires = [
26
+ "openai-agents>=0.1.0",
27
+ ]
28
+
25
29
  setup(
26
30
  name="hivetrace",
27
- version="1.3.3",
31
+ version="1.3.4",
28
32
  author="Raft",
29
33
  author_email="sales@raftds.com",
30
34
  description="Hivetrace SDK for monitoring LLM applications",
@@ -37,7 +41,11 @@ setup(
37
41
  "base": base_requires,
38
42
  "langchain": langchain_requires,
39
43
  "crewai": crewai_requires,
40
- "all": base_requires + langchain_requires + crewai_requires,
44
+ "openai_agents": openai_agents_requires,
45
+ "all": base_requires
46
+ + langchain_requires
47
+ + crewai_requires
48
+ + openai_agents_requires,
41
49
  },
42
50
  classifiers=[
43
51
  "License :: OSI Approved :: Apache Software License",
@@ -1,15 +0,0 @@
1
- """
2
- UUID generation and management utilities.
3
- """
4
-
5
- import uuid
6
-
7
-
8
- def generate_uuid() -> str:
9
- """
10
- Generate a new UUID string.
11
-
12
- Returns:
13
- - A newly generated UUID as a string
14
- """
15
- return str(uuid.uuid4())
File without changes
File without changes