|
| 1 | +import os |
1 | 2 | import sys |
2 | 3 | import uuid |
3 | 4 | from dataclasses import dataclass |
|
19 | 20 | set_open_ai_agent_temporal_overrides, |
20 | 21 | ) |
21 | 22 | from temporalio.contrib.openai_agents.temporal_tools import activity_as_tool |
| 23 | +from temporalio.contrib.openai_agents.trace_interceptor import ( |
| 24 | + OpenAIAgentsTracingInterceptor, |
| 25 | +) |
22 | 26 | from tests.helpers import new_worker |
23 | 27 |
|
24 | 28 | with workflow.unsafe.imports_passed_through(): |
@@ -167,6 +171,32 @@ async def test_hello_world_agent(client: Client): |
167 | 171 | assert result == "test" |
168 | 172 |
|
169 | 173 |
|
| 174 | +async def test_end_to_end(client: Client): |
| 175 | + if "OPENAI_API_KEY" not in os.environ: |
| 176 | + pytest.skip("No openai API key") |
| 177 | + |
| 178 | + new_config = client.config() |
| 179 | + new_config["data_converter"] = open_ai_data_converter |
| 180 | + client = Client(**new_config) |
| 181 | + |
| 182 | + model_params = ModelActivityParameters(start_to_close_timeout=timedelta(seconds=10)) |
| 183 | + with set_open_ai_agent_temporal_overrides(model_params): |
| 184 | + async with new_worker( |
| 185 | + client, |
| 186 | + HelloWorldAgent, |
| 187 | + activities=[ModelActivity().invoke_model_activity], |
| 188 | + interceptors=[OpenAIAgentsTracingInterceptor()], |
| 189 | + ) as worker: |
| 190 | + result = await client.execute_workflow( |
| 191 | + HelloWorldAgent.run, |
| 192 | + "Tell me about recursion in programming. Include the word 'function'", |
| 193 | + id=f"hello-workflow-{uuid.uuid4()}", |
| 194 | + task_queue=worker.task_queue, |
| 195 | + execution_timeout=timedelta(seconds=30), |
| 196 | + ) |
| 197 | + assert "function" in result.lower() |
| 198 | + |
| 199 | + |
170 | 200 | @dataclass |
171 | 201 | class Weather: |
172 | 202 | city: str |
@@ -225,7 +255,7 @@ class ToolsWorkflow: |
225 | 255 | @workflow.run |
226 | 256 | async def run(self, question: str) -> str: |
227 | 257 | agent = Agent( |
228 | | - name="Hello world", |
| 258 | + name="Tools Workflow", |
229 | 259 | instructions="You are a helpful agent.", |
230 | 260 | tools=[ |
231 | 261 | activity_as_tool( |
@@ -255,6 +285,7 @@ async def test_tool_workflow(client: Client): |
255 | 285 | client, |
256 | 286 | ToolsWorkflow, |
257 | 287 | activities=[model_activity.invoke_model_activity, get_weather], |
| 288 | + interceptors=[OpenAIAgentsTracingInterceptor()], |
258 | 289 | ) as worker: |
259 | 290 | workflow_handle = await client.start_workflow( |
260 | 291 | ToolsWorkflow.run, |
@@ -476,6 +507,7 @@ async def test_research_workflow(client: Client): |
476 | 507 | client, |
477 | 508 | ResearchWorkflow, |
478 | 509 | activities=[model_activity.invoke_model_activity, get_weather], |
| 510 | + interceptors=[OpenAIAgentsTracingInterceptor()], |
479 | 511 | ) as worker: |
480 | 512 | workflow_handle = await client.start_workflow( |
481 | 513 | ResearchWorkflow.run, |
@@ -686,6 +718,7 @@ async def test_agents_as_tools_workflow(client: Client): |
686 | 718 | client, |
687 | 719 | AgentsAsToolsWorkflow, |
688 | 720 | activities=[model_activity.invoke_model_activity], |
| 721 | + interceptors=[OpenAIAgentsTracingInterceptor()], |
689 | 722 | ) as worker: |
690 | 723 | workflow_handle = await client.start_workflow( |
691 | 724 | AgentsAsToolsWorkflow.run, |
@@ -1043,6 +1076,7 @@ async def test_customer_service_workflow(client: Client): |
1043 | 1076 | client, |
1044 | 1077 | CustomerServiceWorkflow, |
1045 | 1078 | activities=[model_activity.invoke_model_activity], |
| 1079 | + interceptors=[OpenAIAgentsTracingInterceptor()], |
1046 | 1080 | ) as worker: |
1047 | 1081 | workflow_handle = await client.start_workflow( |
1048 | 1082 | CustomerServiceWorkflow.run, |
|
0 commit comments