Skip to content
Merged
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
6 changes: 2 additions & 4 deletions openai_agents/run_agents_as_tools_workflow.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import asyncio

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

from openai_agents.workflows.agents_as_tools_workflow import AgentsAsToolsWorkflow

Expand All @@ -12,7 +10,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,
data_converter=pydantic_data_converter,
)

# 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.pydantic import pydantic_data_converter
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,
data_converter=pydantic_data_converter,
)

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

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

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


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

# 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,9 +1,7 @@
import asyncio

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

from openai_agents.workflows.research_bot_workflow import ResearchWorkflow

Expand All @@ -12,7 +10,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,
data_converter=pydantic_data_converter,
)

# 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,9 +1,7 @@
import asyncio

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

from openai_agents.workflows.tools_workflow import ToolsWorkflow

Expand All @@ -12,7 +10,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,
data_converter=pydantic_data_converter,
)

# Execute a workflow
Expand Down
9 changes: 4 additions & 5 deletions openai_agents/run_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
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 (
from temporalio.contrib.openai_agents import (
ModelActivity,
ModelActivityParameters,
set_open_ai_agent_temporal_overrides,
)
from temporalio.contrib.pydantic import pydantic_data_converter
Expand All @@ -32,7 +32,6 @@ async def main():
data_converter=pydantic_data_converter,
)

model_activity = ModelActivity(model_provider=None)
worker = Worker(
client,
task_queue="openai-agents-task-queue",
Expand All @@ -44,7 +43,7 @@ async def main():
AgentsAsToolsWorkflow,
],
activities=[
model_activity.invoke_model_activity,
ModelActivity().invoke_model_activity,
get_weather,
],
)
Expand Down
4 changes: 1 addition & 3 deletions openai_agents/workflows/agents_as_tools_workflow.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from agents import Agent, ItemHelpers, MessageOutputItem, RunConfig, Runner, trace
from temporalio import workflow

with workflow.unsafe.imports_passed_through():
from agents import Agent, ItemHelpers, MessageOutputItem, RunConfig, Runner, trace

"""
This example shows the agents-as-tools pattern. The frontline agent receives a user message and
then picks which agents to call, as tools. In this case, it picks from a set of translation
Expand Down
36 changes: 17 additions & 19 deletions openai_agents/workflows/customer_service_workflow.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
from __future__ import annotations as _annotations

from agents import (
Agent,
HandoffOutputItem,
ItemHelpers,
MessageOutputItem,
RunConfig,
Runner,
ToolCallItem,
ToolCallOutputItem,
TResponseInputItem,
trace,
)
from temporalio import workflow

with workflow.unsafe.imports_passed_through():
from agents import (
Agent,
HandoffOutputItem,
ItemHelpers,
MessageOutputItem,
RunConfig,
Runner,
ToolCallItem,
ToolCallOutputItem,
TResponseInputItem,
trace,
)

from openai_agents.workflows.customer_service import (
AirlineAgentContext,
ProcessUserMessageInput,
init_agents,
)
from openai_agents.workflows.customer_service import (
AirlineAgentContext,
ProcessUserMessageInput,
init_agents,
)


@workflow.defn
Expand Down
5 changes: 1 addition & 4 deletions openai_agents/workflows/hello_world_workflow.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from agents import Agent, Runner
from temporalio import workflow

# Import agent Agent and Runner
with workflow.unsafe.imports_passed_through():
from agents import Agent, Runner


@workflow.defn
class HelloWorldAgent:
Expand Down
11 changes: 4 additions & 7 deletions openai_agents/workflows/tools_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

from datetime import timedelta

from agents import Agent, Runner
from temporalio import workflow
from temporalio.contrib.openai_agents.temporal_tools import activity_as_tool
from temporalio.contrib import openai_agents as temporal_agents

# Import our activity, passing it through the sandbox
with workflow.unsafe.imports_passed_through():
from agents import Agent, Runner

from openai_agents.workflows.get_weather_activity import get_weather
from openai_agents.workflows.get_weather_activity import get_weather


@workflow.defn
Expand All @@ -20,7 +17,7 @@ async def run(self, question: str) -> str:
name="Hello world",
instructions="You are a helpful agent.",
tools=[
activity_as_tool(
temporal_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 @@ -55,7 +55,7 @@ open-telemetry = [
]
openai-agents = [
"openai-agents >= 0.0.19",
"temporalio[openai-agents] >= 1.13.0",
"temporalio[openai-agents] >= 1.14.1",
]
pydantic-converter = ["pydantic>=2.10.6,<3"]
sentry = ["sentry-sdk>=1.11.0,<2"]
Expand Down
Loading
Loading