You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The [samples repository](https://github.com/temporalio/samples-python/tree/main/openai_agents) contains examples including basic usage, common agent patterns, and more complete samples.
@@ -140,9 +140,8 @@ We refer to that coordinating logic as *agent orchestration*.
140
140
As a general rule, agent orchestration code executes within the Temporal workflow, whereas model calls and any I/O-bound tool invocations execute as Temporal activities.
141
141
142
142
The diagram below shows the overall architecture of an agentic application in Temporal.
143
-
The Temporal Server is responsible to tracking program execution and making sure associated state is preserved reliably.
144
-
Temporal Server manages data in encrypted form.
145
-
All data processing occurs on the Worker, which runs the workflow and activities.
143
+
The Temporal Server is responsible to tracking program execution and making sure associated state is preserved reliably (i.e., stored to a database, possibly replicated across cloud regions).
144
+
Temporal Server manages data in encrypted form, so all data processing occurs on the Worker, which runs the workflow and activities.
146
145
147
146
148
147
```text
@@ -180,7 +179,7 @@ See the [Temporal documentation](https://docs.temporal.io/evaluate/understanding
180
179
181
180
## Complete Example
182
181
183
-
To make the [Hello World durable agent](#hello-world-durable-agent) available in Temporal, we need to create a worker program.
182
+
To make the [Hello World durable agent](#hello-world-durable-agent)shown earlier available in Temporal, we need to create a worker program.
184
183
To see it run, we also need a client to launch it.
185
184
We show these files below.
186
185
@@ -273,9 +272,11 @@ We also configure the client with the `OpenAIAgentsPlugin` to ensure serializati
273
272
274
273
To run this example, see the detailed instructions in the [Temporal Python Samples Repository](https://github.com/temporalio/samples-python/tree/main/openai_agents).
275
274
276
-
## Using Temporal Activities as OpenAI Agents Tools
275
+
## Tool Calling
277
276
278
-
One of the powerful features of this integration is the ability to convert Temporal activities into OpenAI Agents tools using `activity_as_tool`.
277
+
### Temporal Activities as OpenAI Agents Tools
278
+
279
+
One of the powerful features of this integration is the ability to convert Temporal activities into agent tools using `activity_as_tool`.
279
280
This allows your agent to leverage Temporal's durable execution for tool calls.
280
281
281
282
In the example below, we apply the `@activity.defn` decorator to the `get_weather` function to create a Temporal activity.
For simple computations that don't involve external calls you can call the tool directly from the workflow:
323
+
For simple computations that don't involve external calls you can call the tool directly from the workflow by using the standard OpenAI Agents SDK `@functiontool` annotation.
323
324
324
325
```python
325
326
from temporalio import workflow
@@ -345,51 +346,14 @@ class MathAssistantAgent:
345
346
return result.final_output
346
347
```
347
348
348
-
Note that any tools designed to run in the workflow must respect the workflow execution restrictions, meaning no I/O or non-deterministic operations.
349
-
Of course, you can always invoke an activity from the workflow if needed.
349
+
Note that any tools that run in the workflow must respect the workflow execution restrictions, meaning no I/O or non-deterministic operations.
350
350
351
+
Such function tools are, however, regular Temporal workflow code, from which you can always invoke an activity if needed.
351
352
352
-
## Agent Handoffs
353
+
You can find additional examples in the [Temporal Python Samples Repository](https://github.com/temporalio/samples-python/tree/main/openai_agents).
353
354
354
-
The OpenAI Agents SDK supports agent handoffs, where one agent transfers control of execution to another agent.
355
-
In this example, one Temporal workflow wraps the multi-agent system:
356
355
357
-
```python
358
-
@workflow.defn
359
-
classCustomerServiceWorkflow:
360
-
def__init__(self):
361
-
self.current_agent =self.init_agents()
362
-
363
-
definit_agents(self):
364
-
faq_agent = Agent(
365
-
name="FAQ Agent",
366
-
instructions="Answer frequently asked questions",
367
-
)
368
-
369
-
booking_agent = Agent(
370
-
name="Booking Agent",
371
-
instructions="Help with booking and seat changes",
372
-
)
373
-
374
-
triage_agent = Agent(
375
-
name="Triage Agent",
376
-
instructions="Route customers to the right agent",
377
-
handoffs=[faq_agent, booking_agent],
378
-
)
379
-
380
-
return triage_agent
381
-
382
-
@workflow.run
383
-
asyncdefrun(self, customer_message: str) -> str:
384
-
result =await Runner.run(
385
-
starting_agent=self.current_agent,
386
-
input=customer_message,
387
-
context=self.context,
388
-
)
389
-
return result.final_output
390
-
```
356
+
## Feature Support
391
357
392
358
393
-
## Additional Examples
394
359
395
-
You can find additional examples in the [Temporal Python Samples Repository](https://github.com/temporalio/samples-python/tree/main/openai_agents).
0 commit comments