Skip to content

Commit 16ca5b2

Browse files
committed
Example with new plugin PR
1 parent 6cb8ce4 commit 16ca5b2

9 files changed

Lines changed: 175 additions & 205 deletions

openai_agents/run_agents_as_tools_workflow.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
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-
)
7-
84
from openai_agents.workflows.agents_as_tools_workflow import AgentsAsToolsWorkflow
5+
from temporalio.contrib.openai_agents import Plugin
96

107

118
async def main():
129
# Create client connected to server at the given address
1310
client = await Client.connect(
1411
"localhost:7233",
15-
data_converter=open_ai_data_converter,
12+
plugins=[Plugin()],
1613
)
1714

1815
# 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.openai_agents import Plugin
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+
plugins=[Plugin()],
3028
)
3129

3230
handle = client.get_workflow_handle(args.conversation_id)

openai_agents/run_hello_world_workflow.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
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-
)
74

5+
from openai_agents.workflows.research_bot_workflow import ResearchWorkflow
86
from openai_agents.workflows.hello_world_workflow import HelloWorldAgent
9-
7+
from temporalio.contrib.openai_agents import Plugin
108

119
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+
plugins=[Plugin()],
1614
)
1715

1816
# Execute a workflow

openai_agents/run_research_workflow.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
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-
)
74

85
from openai_agents.workflows.research_bot_workflow import ResearchWorkflow
6+
from temporalio.contrib.openai_agents import Plugin
97

108

119
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+
plugins=[Plugin()],
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,18 +1,16 @@
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-
)
74

85
from openai_agents.workflows.tools_workflow import ToolsWorkflow
6+
from temporalio.contrib.openai_agents import Plugin
97

108

119
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+
plugins=[Plugin()],
1614
)
1715

1816
# Execute a workflow

openai_agents/run_worker.py

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
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 (
10-
set_open_ai_agent_temporal_overrides,
11-
)
7+
from temporalio.contrib.openai_agents import Plugin
128
from temporalio.contrib.pydantic import pydantic_data_converter
139
from temporalio.worker import Worker
1410

@@ -21,34 +17,27 @@
2117

2218

2319
async def main():
24-
with set_open_ai_agent_temporal_overrides(
25-
model_params=ModelActivityParameters(
26-
start_to_close_timeout=timedelta(seconds=60),
27-
),
28-
):
29-
# Create client connected to server at the given address
30-
client = await Client.connect(
31-
"localhost:7233",
32-
data_converter=pydantic_data_converter,
33-
)
34-
35-
model_activity = ModelActivity(model_provider=None)
36-
worker = Worker(
37-
client,
38-
task_queue="openai-agents-task-queue",
39-
workflows=[
40-
HelloWorldAgent,
41-
ToolsWorkflow,
42-
ResearchWorkflow,
43-
CustomerServiceWorkflow,
44-
AgentsAsToolsWorkflow,
45-
],
46-
activities=[
47-
model_activity.invoke_model_activity,
48-
get_weather,
49-
],
50-
)
51-
await worker.run()
20+
# Create client connected to server at the given address
21+
client = await Client.connect(
22+
"localhost:7233",
23+
plugins=[Plugin()],
24+
)
25+
26+
worker = Worker(
27+
client,
28+
task_queue="openai-agents-task-queue",
29+
workflows=[
30+
HelloWorldAgent,
31+
ToolsWorkflow,
32+
ResearchWorkflow,
33+
CustomerServiceWorkflow,
34+
AgentsAsToolsWorkflow,
35+
],
36+
activities=[
37+
get_weather,
38+
],
39+
)
40+
await worker.run()
5241

5342

5443
if __name__ == "__main__":

openai_agents/workflows/tools_workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from datetime import timedelta
44

55
from temporalio import workflow
6-
from temporalio.contrib.openai_agents.temporal_tools import activity_as_tool
6+
from temporalio.contrib import openai_agents
77

88
# Import our activity, passing it through the sandbox
99
with workflow.unsafe.imports_passed_through():
@@ -20,7 +20,7 @@ async def run(self, question: str) -> str:
2020
name="Hello world",
2121
instructions="You are a helpful agent.",
2222
tools=[
23-
activity_as_tool(
23+
openai_agents.workflow.activity_as_tool(
2424
get_weather, start_to_close_timeout=timedelta(seconds=10)
2525
)
2626
],

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ open-telemetry = [
5050
]
5151
openai-agents = [
5252
"openai-agents >= 0.0.19",
53-
"temporalio[openai-agents] >= 1.13.0",
53+
"temporalio[openai-agents]@git+https://github.com/temporalio/sdk-python@openai/plugin",
5454
]
5555
pydantic-converter = ["pydantic>=2.10.6,<3"]
5656
sentry = ["sentry-sdk>=1.11.0,<2"]

0 commit comments

Comments
 (0)