Skip to content

Commit ab37f2d

Browse files
committed
.
1 parent 7e26532 commit ab37f2d

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

deepeval/openai_agents/callback_handler.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from deepeval.tracing.tracing import (
22
Observer,
33
SpanType,
4+
current_trace_context,
45
)
56
from deepeval.openai_agents.extractors import *
67

@@ -39,6 +40,11 @@ def on_trace_start(self, trace: Trace) -> None:
3940
observer.__enter__()
4041

4142
def on_trace_end(self, trace: Trace) -> None:
43+
# set thread id if exists
44+
current_trace = current_trace_context.get()
45+
thread_id = getattr(trace, "group_id", None)
46+
current_trace.thread_id = thread_id
47+
4248
observer = self.root_span_observers.pop(trace.trace_id, None)
4349
if observer:
4450
observer.__exit__(None, None, None)
@@ -56,6 +62,7 @@ def on_span_start(self, span: Span) -> None:
5662
self.span_observers[span.span_id] = observer
5763
observer.__enter__()
5864

65+
5966
def on_span_end(self, span: Span) -> None:
6067
observer = self.span_observers.pop(span.span_id, None)
6168
if observer:

tests/integrations/openai_agents/test_openai_agent.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from tests.integrations.openai_agents.streaming_agent import streaming_agent
1818
from tests.integrations.openai_agents.research_agent import research_agent
1919
from tests.integrations.openai_agents.remote_agent import remote_agent
20+
from tests.integrations.openai_agents.thread_agent import thread_agent
2021
from tests.integrations.openai_agents.git_mcp_agent import git_agent
2122

2223
add_trace_processor(DeepEvalTracingProcessor())
@@ -28,12 +29,13 @@
2829

2930
asyncio.run(git_agent())
3031
# asyncio.run(customer_service_agent())
31-
# asyncio.run(research_agent())
32-
# asyncio.run(code_interpreter_agent())
33-
# asyncio.run(remote_agent())
34-
# asyncio.run(streaming_agent())
35-
# asyncio.run(streaming_guardrails_agent())
36-
# asyncio.run(output_guardrails_agent())
32+
asyncio.run(research_agent())
33+
asyncio.run(code_interpreter_agent())
34+
asyncio.run(remote_agent())
35+
asyncio.run(streaming_agent())
36+
asyncio.run(streaming_guardrails_agent())
37+
asyncio.run(output_guardrails_agent())
38+
asyncio.run(thread_agent())
3739

3840
##########################################
3941
# Test Async
@@ -51,4 +53,5 @@ async def gather_research_agents():
5153
async def gather_streaming_agents():
5254
tasks = [streaming_agent() for _ in range(4)]
5355
await asyncio.gather(*tasks)
54-
# asyncio.run(gather_streaming_agents())
56+
# asyncio.run(gather_streaming_agents())
57+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
from agents import Agent, Runner, trace
3+
4+
thread_id = "unique_thread_id"
5+
6+
async def thread_agent():
7+
agent = Agent(name="Assistant", instructions="Reply very concisely.")
8+
9+
with trace(workflow_name="Conversation", group_id=thread_id):
10+
# First turn
11+
result = await Runner.run(agent, "What city is the Golden Gate Bridge in?")
12+
print(result.final_output)
13+
# San Francisco
14+
15+
# Second turn
16+
new_input = result.to_input_list() + [{"role": "user", "content": "What state is it in?"}]
17+
result = await Runner.run(agent, new_input)
18+
print(result.final_output)
19+
# California

0 commit comments

Comments
 (0)