Skip to content

Commit 0b42324

Browse files
authored
improve tracing for openai agents (temporalio#205)
* improve tracing for openai agents * follow openai agents examples more closely
1 parent 0ddc00e commit 0b42324

4 files changed

Lines changed: 6 additions & 5 deletions

File tree

openai_agents/run_customer_service_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ async def main():
3232
# Query the workflow for the chat history
3333
# If the workflow is not open, start a new one
3434
start = False
35+
history = []
3536
try:
3637
history = await handle.query(
3738
CustomerServiceWorkflow.get_chat_history,
3839
reject_condition=QueryRejectCondition.NOT_OPEN,
3940
)
40-
except WorkflowQueryRejectedError as e:
41+
except WorkflowQueryRejectedError:
4142
start = True
4243
except RPCError as e:
4344
if e.status == RPCStatusCode.NOT_FOUND:

openai_agents/run_hello_world_workflow.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from temporalio.contrib.pydantic import pydantic_data_converter
55

66
from openai_agents.workflows.hello_world_workflow import HelloWorldAgent
7-
from openai_agents.workflows.research_bot_workflow import ResearchWorkflow
87

98

109
async def main():

openai_agents/run_worker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from temporalio.contrib.openai_agents import (
88
ModelActivity,
99
ModelActivityParameters,
10+
OpenAIAgentsTracingInterceptor,
1011
set_open_ai_agent_temporal_overrides,
1112
)
1213
from temporalio.contrib.pydantic import pydantic_data_converter
@@ -46,6 +47,7 @@ async def main():
4647
ModelActivity().invoke_model_activity,
4748
get_weather,
4849
],
50+
interceptors=[OpenAIAgentsTracingInterceptor()],
4951
)
5052
await worker.run()
5153

openai_agents/workflows/research_agents/research_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
with workflow.unsafe.imports_passed_through():
88
# TODO: Restore progress updates
9-
from agents import RunConfig, Runner, custom_span, gen_trace_id, trace
9+
from agents import RunConfig, Runner, custom_span, trace
1010

1111
from openai_agents.workflows.research_agents.planner_agent import (
1212
WebSearchItem,
@@ -28,8 +28,7 @@ def __init__(self):
2828
self.writer_agent = new_writer_agent()
2929

3030
async def run(self, query: str) -> str:
31-
trace_id = gen_trace_id()
32-
with trace("Research trace", trace_id=trace_id):
31+
with trace("Research trace"):
3332
search_plan = await self._plan_searches(query)
3433
search_results = await self._perform_searches(search_plan)
3534
report = await self._write_report(query, search_results)

0 commit comments

Comments
 (0)