Skip to content

Commit 153ee19

Browse files
authored
Updated openai agents samples to work with latest SDK. (#204)
* Stage changes for next update to openai integration * Update temporalio to latest * Formatting * remove passthrough * Run isort
1 parent ffb2b5a commit 153ee19

12 files changed

+795
-690
lines changed

openai_agents/run_agents_as_tools_workflow.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import asyncio
22

33
from temporalio.client import Client
4-
from temporalio.contrib.openai_agents.open_ai_data_converter import (
5-
open_ai_data_converter,
6-
)
4+
from temporalio.contrib.pydantic import pydantic_data_converter
75

86
from openai_agents.workflows.agents_as_tools_workflow import AgentsAsToolsWorkflow
97

@@ -12,7 +10,7 @@ async def main():
1210
# Create client connected to server at the given address
1311
client = await Client.connect(
1412
"localhost:7233",
15-
data_converter=open_ai_data_converter,
13+
data_converter=pydantic_data_converter,
1614
)
1715

1816
# Execute a workflow

openai_agents/run_customer_service_client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
WorkflowUpdateFailedError,
88
)
99
from temporalio.common import QueryRejectCondition
10-
from temporalio.contrib.openai_agents.open_ai_data_converter import (
11-
open_ai_data_converter,
12-
)
10+
from temporalio.contrib.pydantic import pydantic_data_converter
1311
from temporalio.service import RPCError, RPCStatusCode
1412

1513
from openai_agents.workflows.customer_service_workflow import (
@@ -26,7 +24,7 @@ async def main():
2624
# Create client connected to server at the given address
2725
client = await Client.connect(
2826
"localhost:7233",
29-
data_converter=open_ai_data_converter,
27+
data_converter=pydantic_data_converter,
3028
)
3129

3230
handle = client.get_workflow_handle(args.conversation_id)

openai_agents/run_hello_world_workflow.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import asyncio
22

33
from temporalio.client import Client
4-
from temporalio.contrib.openai_agents.open_ai_data_converter import (
5-
open_ai_data_converter,
6-
)
4+
from temporalio.contrib.pydantic import pydantic_data_converter
75

86
from openai_agents.workflows.hello_world_workflow import HelloWorldAgent
7+
from openai_agents.workflows.research_bot_workflow import ResearchWorkflow
98

109

1110
async def main():
1211
# Create client connected to server at the given address
1312
client = await Client.connect(
1413
"localhost:7233",
15-
data_converter=open_ai_data_converter,
14+
data_converter=pydantic_data_converter,
1615
)
1716

1817
# Execute a workflow

openai_agents/run_research_workflow.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import asyncio
22

33
from temporalio.client import Client
4-
from temporalio.contrib.openai_agents.open_ai_data_converter import (
5-
open_ai_data_converter,
6-
)
4+
from temporalio.contrib.pydantic import pydantic_data_converter
75

86
from openai_agents.workflows.research_bot_workflow import ResearchWorkflow
97

@@ -12,7 +10,7 @@ async def main():
1210
# Create client connected to server at the given address
1311
client = await Client.connect(
1412
"localhost:7233",
15-
data_converter=open_ai_data_converter,
13+
data_converter=pydantic_data_converter,
1614
)
1715

1816
# Execute a workflow

openai_agents/run_tools_workflow.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import asyncio
22

33
from temporalio.client import Client
4-
from temporalio.contrib.openai_agents.open_ai_data_converter import (
5-
open_ai_data_converter,
6-
)
4+
from temporalio.contrib.pydantic import pydantic_data_converter
75

86
from openai_agents.workflows.tools_workflow import ToolsWorkflow
97

@@ -12,7 +10,7 @@ async def main():
1210
# Create client connected to server at the given address
1311
client = await Client.connect(
1412
"localhost:7233",
15-
data_converter=open_ai_data_converter,
13+
data_converter=pydantic_data_converter,
1614
)
1715

1816
# Execute a workflow

openai_agents/run_worker.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from datetime import timedelta
55

66
from temporalio.client import Client
7-
from temporalio.contrib.openai_agents.invoke_model_activity import ModelActivity
8-
from temporalio.contrib.openai_agents.model_parameters import ModelActivityParameters
9-
from temporalio.contrib.openai_agents.temporal_openai_agents import (
7+
from temporalio.contrib.openai_agents import (
8+
ModelActivity,
9+
ModelActivityParameters,
1010
set_open_ai_agent_temporal_overrides,
1111
)
1212
from temporalio.contrib.pydantic import pydantic_data_converter
@@ -32,7 +32,6 @@ async def main():
3232
data_converter=pydantic_data_converter,
3333
)
3434

35-
model_activity = ModelActivity(model_provider=None)
3635
worker = Worker(
3736
client,
3837
task_queue="openai-agents-task-queue",
@@ -44,7 +43,7 @@ async def main():
4443
AgentsAsToolsWorkflow,
4544
],
4645
activities=[
47-
model_activity.invoke_model_activity,
46+
ModelActivity().invoke_model_activity,
4847
get_weather,
4948
],
5049
)

openai_agents/workflows/agents_as_tools_workflow.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1+
from agents import Agent, ItemHelpers, MessageOutputItem, RunConfig, Runner, trace
12
from temporalio import workflow
23

3-
with workflow.unsafe.imports_passed_through():
4-
from agents import Agent, ItemHelpers, MessageOutputItem, RunConfig, Runner, trace
5-
64
"""
75
This example shows the agents-as-tools pattern. The frontline agent receives a user message and
86
then picks which agents to call, as tools. In this case, it picks from a set of translation

openai_agents/workflows/customer_service_workflow.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
from __future__ import annotations as _annotations
22

3+
from agents import (
4+
Agent,
5+
HandoffOutputItem,
6+
ItemHelpers,
7+
MessageOutputItem,
8+
RunConfig,
9+
Runner,
10+
ToolCallItem,
11+
ToolCallOutputItem,
12+
TResponseInputItem,
13+
trace,
14+
)
315
from temporalio import workflow
416

5-
with workflow.unsafe.imports_passed_through():
6-
from agents import (
7-
Agent,
8-
HandoffOutputItem,
9-
ItemHelpers,
10-
MessageOutputItem,
11-
RunConfig,
12-
Runner,
13-
ToolCallItem,
14-
ToolCallOutputItem,
15-
TResponseInputItem,
16-
trace,
17-
)
18-
19-
from openai_agents.workflows.customer_service import (
20-
AirlineAgentContext,
21-
ProcessUserMessageInput,
22-
init_agents,
23-
)
17+
from openai_agents.workflows.customer_service import (
18+
AirlineAgentContext,
19+
ProcessUserMessageInput,
20+
init_agents,
21+
)
2422

2523

2624
@workflow.defn

openai_agents/workflows/hello_world_workflow.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1+
from agents import Agent, Runner
12
from temporalio import workflow
23

3-
# Import agent Agent and Runner
4-
with workflow.unsafe.imports_passed_through():
5-
from agents import Agent, Runner
6-
74

85
@workflow.defn
96
class HelloWorldAgent:

openai_agents/workflows/tools_workflow.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
from datetime import timedelta
44

5+
from agents import Agent, Runner
56
from temporalio import workflow
6-
from temporalio.contrib.openai_agents.temporal_tools import activity_as_tool
7+
from temporalio.contrib import openai_agents as temporal_agents
78

8-
# Import our activity, passing it through the sandbox
9-
with workflow.unsafe.imports_passed_through():
10-
from agents import Agent, Runner
11-
12-
from openai_agents.workflows.get_weather_activity import get_weather
9+
from openai_agents.workflows.get_weather_activity import get_weather
1310

1411

1512
@workflow.defn
@@ -20,7 +17,7 @@ async def run(self, question: str) -> str:
2017
name="Hello world",
2118
instructions="You are a helpful agent.",
2219
tools=[
23-
activity_as_tool(
20+
temporal_agents.workflow.activity_as_tool(
2421
get_weather, start_to_close_timeout=timedelta(seconds=10)
2522
)
2623
],

0 commit comments

Comments
 (0)