Skip to content

Example with new plugin PR #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions openai_agents/run_agents_as_tools_workflow.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import asyncio

from temporalio.client import Client
from temporalio.contrib.openai_agents.open_ai_data_converter import (
open_ai_data_converter,
)

from openai_agents.workflows.agents_as_tools_workflow import AgentsAsToolsWorkflow
from temporalio.contrib.openai_agents import Plugin


async def main():
# Create client connected to server at the given address
client = await Client.connect(
"localhost:7233",
data_converter=open_ai_data_converter,
plugins=[Plugin()],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we probably want to encourage plugin authors to name this object like OpenAIAgentsPlugin so that even if imported using from ... import ... it's still clear at the usage site what plugin it is.

Alternatively we could reference it as openai_agents.Plugin, but I think encouraging the fully-qualified plugin object name makes sense.

)

# Execute a workflow
Expand Down
6 changes: 2 additions & 4 deletions openai_agents/run_customer_service_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
WorkflowUpdateFailedError,
)
from temporalio.common import QueryRejectCondition
from temporalio.contrib.openai_agents.open_ai_data_converter import (
open_ai_data_converter,
)
from temporalio.contrib.openai_agents import Plugin
from temporalio.service import RPCError, RPCStatusCode

from openai_agents.workflows.customer_service_workflow import (
Expand All @@ -26,7 +24,7 @@ async def main():
# Create client connected to server at the given address
client = await Client.connect(
"localhost:7233",
data_converter=open_ai_data_converter,
plugins=[Plugin()],
)

handle = client.get_workflow_handle(args.conversation_id)
Expand Down
8 changes: 3 additions & 5 deletions openai_agents/run_hello_world_workflow.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import asyncio

from temporalio.client import Client
from temporalio.contrib.openai_agents.open_ai_data_converter import (
open_ai_data_converter,
)

from openai_agents.workflows.research_bot_workflow import ResearchWorkflow
from openai_agents.workflows.hello_world_workflow import HelloWorldAgent

from temporalio.contrib.openai_agents import Plugin

async def main():
# Create client connected to server at the given address
client = await Client.connect(
"localhost:7233",
data_converter=open_ai_data_converter,
plugins=[Plugin()],
)

# Execute a workflow
Expand Down
6 changes: 2 additions & 4 deletions openai_agents/run_research_workflow.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import asyncio

from temporalio.client import Client
from temporalio.contrib.openai_agents.open_ai_data_converter import (
open_ai_data_converter,
)

from openai_agents.workflows.research_bot_workflow import ResearchWorkflow
from temporalio.contrib.openai_agents import Plugin


async def main():
# Create client connected to server at the given address
client = await Client.connect(
"localhost:7233",
data_converter=open_ai_data_converter,
plugins=[Plugin()],
)

# Execute a workflow
Expand Down
6 changes: 2 additions & 4 deletions openai_agents/run_tools_workflow.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import asyncio

from temporalio.client import Client
from temporalio.contrib.openai_agents.open_ai_data_converter import (
open_ai_data_converter,
)

from openai_agents.workflows.tools_workflow import ToolsWorkflow
from temporalio.contrib.openai_agents import Plugin


async def main():
# Create client connected to server at the given address
client = await Client.connect(
"localhost:7233",
data_converter=open_ai_data_converter,
plugins=[Plugin()],
)

# Execute a workflow
Expand Down
55 changes: 22 additions & 33 deletions openai_agents/run_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
from datetime import timedelta

from temporalio.client import Client
from temporalio.contrib.openai_agents.invoke_model_activity import ModelActivity
from temporalio.contrib.openai_agents.model_parameters import ModelActivityParameters
from temporalio.contrib.openai_agents.temporal_openai_agents import (
set_open_ai_agent_temporal_overrides,
)
from temporalio.contrib.openai_agents import Plugin
from temporalio.contrib.pydantic import pydantic_data_converter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import not needed anymore either

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[I like using a ruff IDE extension and setting format-on-save to true.]

from temporalio.worker import Worker

Expand All @@ -21,34 +17,27 @@


async def main():
with set_open_ai_agent_temporal_overrides(
model_params=ModelActivityParameters(
start_to_close_timeout=timedelta(seconds=60),
),
):
# Create client connected to server at the given address
client = await Client.connect(
"localhost:7233",
data_converter=pydantic_data_converter,
)

model_activity = ModelActivity(model_provider=None)
worker = Worker(
client,
task_queue="openai-agents-task-queue",
workflows=[
HelloWorldAgent,
ToolsWorkflow,
ResearchWorkflow,
CustomerServiceWorkflow,
AgentsAsToolsWorkflow,
],
activities=[
model_activity.invoke_model_activity,
get_weather,
],
)
await worker.run()
# Create client connected to server at the given address
client = await Client.connect(
"localhost:7233",
plugins=[Plugin()],
)

worker = Worker(
client,
task_queue="openai-agents-task-queue",
workflows=[
HelloWorldAgent,
ToolsWorkflow,
ResearchWorkflow,
CustomerServiceWorkflow,
AgentsAsToolsWorkflow,
],
activities=[
get_weather,
],
)
await worker.run()


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions openai_agents/workflows/tools_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import timedelta

from temporalio import workflow
from temporalio.contrib.openai_agents.temporal_tools import activity_as_tool
from temporalio.contrib import openai_agents

# Import our activity, passing it through the sandbox
with workflow.unsafe.imports_passed_through():
Expand All @@ -20,7 +20,7 @@ async def run(self, question: str) -> str:
name="Hello world",
instructions="You are a helpful agent.",
tools=[
activity_as_tool(
openai_agents.workflow.activity_as_tool(
get_weather, start_to_close_timeout=timedelta(seconds=10)
)
],
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ open-telemetry = [
]
openai-agents = [
"openai-agents >= 0.0.19",
"temporalio[openai-agents] >= 1.13.0",
"temporalio[openai-agents]@git+https://github.com/temporalio/sdk-python@openai/plugin",
]
pydantic-converter = ["pydantic>=2.10.6,<3"]
sentry = ["sentry-sdk>=1.11.0,<2"]
Expand Down
Loading
Loading