hivetrace 1.3.3__py3-none-any.whl → 1.3.4__py3-none-any.whl
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.
- hivetrace/adapters/__init__.py +11 -0
- hivetrace/adapters/openai_agents/__init__.py +3 -0
- hivetrace/adapters/openai_agents/adapter.py +129 -0
- hivetrace/adapters/openai_agents/models.py +68 -0
- hivetrace/adapters/openai_agents/tracing.py +149 -0
- hivetrace/utils/uuid_generator.py +13 -0
- {hivetrace-1.3.3.dist-info → hivetrace-1.3.4.dist-info}/METADATA +114 -1
- {hivetrace-1.3.3.dist-info → hivetrace-1.3.4.dist-info}/RECORD +11 -7
- {hivetrace-1.3.3.dist-info → hivetrace-1.3.4.dist-info}/LICENSE +0 -0
- {hivetrace-1.3.3.dist-info → hivetrace-1.3.4.dist-info}/WHEEL +0 -0
- {hivetrace-1.3.3.dist-info → hivetrace-1.3.4.dist-info}/top_level.txt +0 -0
hivetrace/adapters/__init__.py
CHANGED
|
@@ -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,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 = {}
|
|
@@ -13,3 +13,16 @@ def generate_uuid() -> str:
|
|
|
13
13
|
- A newly generated UUID as a string
|
|
14
14
|
"""
|
|
15
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
|
+
Version: 1.3.4
|
|
4
4
|
Summary: Hivetrace SDK for monitoring LLM applications
|
|
5
5
|
Home-page: http://hivetrace.ai
|
|
6
6
|
Author: Raft
|
|
@@ -19,6 +19,7 @@ Requires-Dist: langchain-community ==0.3.18 ; extra == 'all'
|
|
|
19
19
|
Requires-Dist: langchain-openai ==0.2.5 ; extra == 'all'
|
|
20
20
|
Requires-Dist: langchain ==0.3.19 ; extra == 'all'
|
|
21
21
|
Requires-Dist: langchain-experimental ==0.3.4 ; extra == 'all'
|
|
22
|
+
Requires-Dist: openai-agents >=0.1.0 ; extra == 'all'
|
|
22
23
|
Requires-Dist: python-dotenv >=1.0.1 ; extra == 'all'
|
|
23
24
|
Provides-Extra: base
|
|
24
25
|
Requires-Dist: httpx >=0.28.1 ; extra == 'base'
|
|
@@ -30,6 +31,8 @@ Requires-Dist: langchain-community ==0.3.18 ; extra == 'langchain'
|
|
|
30
31
|
Requires-Dist: langchain-openai ==0.2.5 ; extra == 'langchain'
|
|
31
32
|
Requires-Dist: langchain ==0.3.19 ; extra == 'langchain'
|
|
32
33
|
Requires-Dist: langchain-experimental ==0.3.4 ; extra == 'langchain'
|
|
34
|
+
Provides-Extra: openai_agents
|
|
35
|
+
Requires-Dist: openai-agents >=0.1.0 ; extra == 'openai_agents'
|
|
33
36
|
|
|
34
37
|
# Hivetrace SDK
|
|
35
38
|
|
|
@@ -735,3 +738,113 @@ HIVETRACE_APP_ID=your-application-id
|
|
|
735
738
|
|
|
736
739
|
## License
|
|
737
740
|
This project is licensed under the Apache License 2.0.
|
|
741
|
+
|
|
742
|
+
# OpenAI Agents Integration
|
|
743
|
+
|
|
744
|
+
## Overview
|
|
745
|
+
|
|
746
|
+
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.
|
|
747
|
+
|
|
748
|
+
## Quick Start
|
|
749
|
+
|
|
750
|
+
### Prerequisites
|
|
751
|
+
|
|
752
|
+
- HiveTrace SDK installed: `pip install hivetrace[openai_agents]`
|
|
753
|
+
- OpenAI Agents SDK installed: `pip install openai-agents`
|
|
754
|
+
- Valid HiveTrace application ID and access token
|
|
755
|
+
|
|
756
|
+
### Basic Setup
|
|
757
|
+
|
|
758
|
+
**Step 1: Initialize the SDK (optional)**
|
|
759
|
+
|
|
760
|
+
```python
|
|
761
|
+
from hivetrace import HivetraceSDK
|
|
762
|
+
from hivetrace.adapters.openai_agents import HivetraceOpenAIAgentProcessor
|
|
763
|
+
|
|
764
|
+
# Initialize SDK
|
|
765
|
+
hivetrace = HivetraceSDK(
|
|
766
|
+
config={
|
|
767
|
+
"HIVETRACE_URL": "https://your-hivetrace-instance.com",
|
|
768
|
+
"HIVETRACE_ACCESS_TOKEN": "your-access-token",
|
|
769
|
+
},
|
|
770
|
+
async_mode=False,
|
|
771
|
+
)
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
**Step 2: Set Up the Tracing Processor**
|
|
775
|
+
|
|
776
|
+
The `HivetraceOpenAIAgentProcessor` hooks into the OpenAI Agents SDK tracing system and automatically logs all agent and tool activity to HiveTrace.
|
|
777
|
+
|
|
778
|
+
```python
|
|
779
|
+
from agents import Agent, Runner, function_tool, set_trace_processors
|
|
780
|
+
from hivetrace.adapters.openai_agents import HivetraceOpenAIAgentProcessor
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
set_trace_processors(
|
|
784
|
+
HivetraceOpenAIAgentProcessor(
|
|
785
|
+
hivetrace_instance=hivetrace,
|
|
786
|
+
application_id="your-hivetrace-app-id",
|
|
787
|
+
)
|
|
788
|
+
)
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
or setup environment variables HIVETRACE_URL, HIVETRACE_ACCESS_TOKEN, HIVETRACE_APPLICATION_ID for easier configuration:
|
|
792
|
+
|
|
793
|
+
```python
|
|
794
|
+
from agents import Agent, Runner, function_tool, set_trace_processors
|
|
795
|
+
from hivetrace.adapters.openai_agents import HivetraceOpenAIAgentProcessor
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
set_trace_processors([HivetraceOpenAIAgentProcessor()])
|
|
799
|
+
```
|
|
800
|
+
|
|
801
|
+
**Step 3: Call your agents**
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
```python
|
|
805
|
+
from agents.tracing.create import trace
|
|
806
|
+
|
|
807
|
+
# Define your agent and tools as usual
|
|
808
|
+
@function_tool
|
|
809
|
+
def get_weather(city: str):
|
|
810
|
+
return f"The weather in {city} is sunny."
|
|
811
|
+
|
|
812
|
+
agent = Agent(
|
|
813
|
+
name="WeatherAgent",
|
|
814
|
+
instructions="You provide weather updates.",
|
|
815
|
+
tools=[get_weather],
|
|
816
|
+
)
|
|
817
|
+
|
|
818
|
+
# Run the agent
|
|
819
|
+
import asyncio
|
|
820
|
+
async def main():
|
|
821
|
+
with trace(
|
|
822
|
+
workflow_name="Agent workflow",
|
|
823
|
+
metadata={
|
|
824
|
+
"session_id": "your-session-id",
|
|
825
|
+
"user_id": "your-user-id",
|
|
826
|
+
},
|
|
827
|
+
):
|
|
828
|
+
result = await Runner.run(agent, "What's the weather in Paris?")
|
|
829
|
+
print(result.final_output)
|
|
830
|
+
|
|
831
|
+
asyncio.run(main())
|
|
832
|
+
```
|
|
833
|
+
|
|
834
|
+
## Environment Variables
|
|
835
|
+
|
|
836
|
+
Set up your environment variables for easier configuration:
|
|
837
|
+
|
|
838
|
+
```bash
|
|
839
|
+
# .env file
|
|
840
|
+
HIVETRACE_URL=https://your-hivetrace-instance.com
|
|
841
|
+
HIVETRACE_ACCESS_TOKEN=your-access-token
|
|
842
|
+
HIVETRACE_APP_ID=your-application-id
|
|
843
|
+
```
|
|
844
|
+
|
|
845
|
+
---
|
|
846
|
+
|
|
847
|
+
## Advanced Usage
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
You now have complete monitoring of your OpenAI Agents system integrated with HiveTrace!
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
hivetrace/__init__.py,sha256=lA2xegZE0gBleteGHVY6YfbByLQMhsKBJhKhEvxozzo,896
|
|
2
2
|
hivetrace/crewai_adapter.py,sha256=NeMH37GaUUZFEfpRQnrpbM8HhS1FgfU4I6SSXtqU19s,215
|
|
3
3
|
hivetrace/hivetrace.py,sha256=iJOkHJudejopmt0rnFsPBVivylXBcnHSEvkItrpqLMA,9126
|
|
4
|
-
hivetrace/adapters/__init__.py,sha256=
|
|
4
|
+
hivetrace/adapters/__init__.py,sha256=lWWh3KWDghlAz8H9U8TOGaoRv76QQyKg46zvkuVWG7Y,1033
|
|
5
5
|
hivetrace/adapters/base_adapter.py,sha256=zN2HV3Kb8d5DS_Jua76iwIEkK05ot4y7nScmoSwvaG0,5400
|
|
6
6
|
hivetrace/adapters/crewai/__init__.py,sha256=cHxroLbjZAH5HX763SEc4cRZrfJGQ6XjETJRx6LFjWY,239
|
|
7
7
|
hivetrace/adapters/crewai/adapter.py,sha256=K_29a71KRWysplA6J3r-Z5CPM-kOVdOhHbNleFuHpao,17879
|
|
@@ -15,12 +15,16 @@ hivetrace/adapters/langchain/behavior_tracker.py,sha256=ETNQjoIDtk3Cde5DiOfMln_C
|
|
|
15
15
|
hivetrace/adapters/langchain/callback.py,sha256=LJXzJDwAECOQIlZqkVvSCn1KzBjUVSQpzA5iJ9lH1z0,19730
|
|
16
16
|
hivetrace/adapters/langchain/decorators.py,sha256=yocDjsDup8omiMYFX2Dx8mws45bTKsMGhF6-nuDwmfk,3193
|
|
17
17
|
hivetrace/adapters/langchain/models.py,sha256=Pk4cQRrdSu9q8Mp49dU6oeUIesw1f1gG5rt1R9HjLMo,1435
|
|
18
|
+
hivetrace/adapters/openai_agents/__init__.py,sha256=T-SEEfPEYQpWljoK6D5g3UPFJXBPs8wSQYITrh-32jQ,128
|
|
19
|
+
hivetrace/adapters/openai_agents/adapter.py,sha256=tpgNnXU0Gr7Iu022CpjJ5Tear94etImh9vN_AaViCXE,5317
|
|
20
|
+
hivetrace/adapters/openai_agents/models.py,sha256=THbpcD-J6BnMVZ4vYzymzmr-iezAV2crCr-Sd8wdWzw,1379
|
|
21
|
+
hivetrace/adapters/openai_agents/tracing.py,sha256=W35siEaZTmzH3R3dufs0hNTlNWe5EPynxRmu3TXZm5M,5146
|
|
18
22
|
hivetrace/adapters/utils/__init__.py,sha256=AkdJzecQlhT3hHFOIO5zWbAIEXvbgH_5vmzlPViedt0,142
|
|
19
23
|
hivetrace/adapters/utils/logging.py,sha256=UxCMFvlpP6vJfzRwMYhhJIi7RTWdgVK2sWtCeEB67_w,1126
|
|
20
24
|
hivetrace/utils/__init__.py,sha256=DxWV8tC4i5w4bMrvVuUM53_i7qHkfcduOAZF6nH6s7w,127
|
|
21
|
-
hivetrace/utils/uuid_generator.py,sha256=
|
|
22
|
-
hivetrace-1.3.
|
|
23
|
-
hivetrace-1.3.
|
|
24
|
-
hivetrace-1.3.
|
|
25
|
-
hivetrace-1.3.
|
|
26
|
-
hivetrace-1.3.
|
|
25
|
+
hivetrace/utils/uuid_generator.py,sha256=69yokLJxDYqHt0BQsgtPoyhqARnItAYvw4UDqtgCFok,509
|
|
26
|
+
hivetrace-1.3.4.dist-info/LICENSE,sha256=8d3g3prbWPDLQ5AV0dtyWfYTj5QPl8MJ_wlr2l8pjEU,11333
|
|
27
|
+
hivetrace-1.3.4.dist-info/METADATA,sha256=8tm6hPahNxBXPi6xK6aPz1U6GicGL5h1_EtOm0J_60o,21265
|
|
28
|
+
hivetrace-1.3.4.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
29
|
+
hivetrace-1.3.4.dist-info/top_level.txt,sha256=F6mZCzZ5CSftMc-M0NeOYWbwyTzjybR72P4qSBMyZZM,10
|
|
30
|
+
hivetrace-1.3.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|