Skip to content

Commit 9eb2b4a

Browse files
committed
wip
1 parent 878d04d commit 9eb2b4a

File tree

1 file changed

+15
-51
lines changed

1 file changed

+15
-51
lines changed

temporalio/contrib/openai_agents/README.md

Lines changed: 15 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ This document is organized as follows:
1717
- **[Hello World Agent](#hello-world-durable-agent).** Your first durable agent example.
1818
- **[Background Concepts](#core-concepts).** Background on durable execution and AI agents.
1919
- **[Full Example](#full-example)** Complete example.
20-
- **[Usage Guide].**
21-
[TODO: Complete links]
20+
- **[Tool Calling](#tool-calling).**
21+
- **[Feature Support](#feature-support).**
2222

2323

2424
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*.
140140
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.
141141

142142
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.
146145

147146

148147
```text
@@ -180,7 +179,7 @@ See the [Temporal documentation](https://docs.temporal.io/evaluate/understanding
180179

181180
## Complete Example
182181

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.
184183
To see it run, we also need a client to launch it.
185184
We show these files below.
186185

@@ -273,9 +272,11 @@ We also configure the client with the `OpenAIAgentsPlugin` to ensure serializati
273272

274273
To run this example, see the detailed instructions in the [Temporal Python Samples Repository](https://github.com/temporalio/samples-python/tree/main/openai_agents).
275274

276-
## Using Temporal Activities as OpenAI Agents Tools
275+
## Tool Calling
277276

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`.
279280
This allows your agent to leverage Temporal's durable execution for tool calls.
280281

281282
In the example below, we apply the `@activity.defn` decorator to the `get_weather` function to create a Temporal activity.
@@ -317,9 +318,9 @@ class WeatherAgent:
317318
return result.final_output
318319
```
319320

320-
## Calling Tools Directly
321+
### Calling OpenAI Agents Tools inside Temporal Workflows
321322

322-
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.
323324

324325
```python
325326
from temporalio import workflow
@@ -345,51 +346,14 @@ class MathAssistantAgent:
345346
return result.final_output
346347
```
347348

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.
350350

351+
Such function tools are, however, regular Temporal workflow code, from which you can always invoke an activity if needed.
351352

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).
353354

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:
356355

357-
```python
358-
@workflow.defn
359-
class CustomerServiceWorkflow:
360-
def __init__(self):
361-
self.current_agent = self.init_agents()
362-
363-
def init_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-
async def run(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
391357

392358

393-
## Additional Examples
394359

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

Comments
 (0)