Skip to content

Commit 21af352

Browse files
authored
Merge branch 'main' into openai/respect_model_name_in_agent
2 parents 1d1eeb9 + 3d9bfee commit 21af352

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

temporalio/contrib/openai_agents/_openai_runner.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
RunConfig,
88
RunResult,
99
RunResultStreaming,
10+
SQLiteSession,
1011
TContext,
1112
Tool,
1213
TResponseInputItem,
@@ -61,6 +62,10 @@ async def run(
6162
hooks = kwargs.get("hooks")
6263
run_config = kwargs.get("run_config")
6364
previous_response_id = kwargs.get("previous_response_id")
65+
session = kwargs.get("session")
66+
67+
if isinstance(session, SQLiteSession):
68+
raise ValueError("Temporal workflows don't support SQLite sessions.")
6469

6570
if run_config is None:
6671
run_config = RunConfig()
@@ -86,6 +91,7 @@ async def run(
8691
hooks=hooks,
8792
run_config=updated_run_config,
8893
previous_response_id=previous_response_id,
94+
session=session,
8995
)
9096

9197
def run_sync(

tests/contrib/openai_agents/test_openai.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
OutputGuardrailTripwireTriggered,
2727
RunContextWrapper,
2828
Runner,
29+
SQLiteSession,
2930
Tool,
3031
TResponseInputItem,
3132
Usage,
@@ -74,7 +75,7 @@
7475
from tests.contrib.openai_agents.research_agents.research_manager import (
7576
ResearchManager,
7677
)
77-
from tests.helpers import new_worker
78+
from tests.helpers import assert_task_fail_eventually, new_worker
7879
from tests.helpers.nexus import create_nexus_endpoint, make_nexus_endpoint_name
7980

8081

@@ -2023,3 +2024,44 @@ def test_summary_extraction():
20232024
)
20242025
)
20252026
assert _extract_summary(input) == "Second message"
2027+
2028+
2029+
@workflow.defn
2030+
class SessionWorkflow:
2031+
@workflow.run
2032+
async def run(self) -> None:
2033+
agent: Agent = Agent(
2034+
name="Assistant",
2035+
instructions="You are a helpful assistant.",
2036+
)
2037+
await Runner.run(
2038+
agent,
2039+
"My phone number is 650-123-4567. Where do you think I live?",
2040+
session=SQLiteSession(session_id="id"),
2041+
)
2042+
2043+
2044+
async def test_session(client: Client):
2045+
new_config = client.config()
2046+
new_config["plugins"] = [
2047+
openai_agents.OpenAIAgentsPlugin(
2048+
model_provider=TestModelProvider(TestHelloModel()),
2049+
)
2050+
]
2051+
client = Client(**new_config)
2052+
2053+
async with new_worker(
2054+
client,
2055+
SessionWorkflow,
2056+
) as worker:
2057+
workflow_handle = await client.start_workflow(
2058+
SessionWorkflow.run,
2059+
id=f"session-{uuid.uuid4()}",
2060+
task_queue=worker.task_queue,
2061+
execution_timeout=timedelta(seconds=1.0),
2062+
retry_policy=RetryPolicy(maximum_attempts=1),
2063+
)
2064+
await assert_task_fail_eventually(
2065+
workflow_handle,
2066+
message_contains="Temporal workflows don't support SQLite sessions",
2067+
)

0 commit comments

Comments
 (0)