Skip to content

Commit 3d9bfee

Browse files
authored
Disallow use of sqlite sessions, but pass through others (#993)
1 parent da6616a commit 3d9bfee

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()
@@ -85,6 +90,7 @@ async def run(
8590
hooks=hooks,
8691
run_config=updated_run_config,
8792
previous_response_id=previous_response_id,
93+
session=session,
8894
)
8995

9096
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

@@ -1978,3 +1979,44 @@ def test_summary_extraction():
19781979
)
19791980
)
19801981
assert _extract_summary(input) == "Second message"
1982+
1983+
1984+
@workflow.defn
1985+
class SessionWorkflow:
1986+
@workflow.run
1987+
async def run(self) -> None:
1988+
agent: Agent = Agent(
1989+
name="Assistant",
1990+
instructions="You are a helpful assistant.",
1991+
)
1992+
await Runner.run(
1993+
agent,
1994+
"My phone number is 650-123-4567. Where do you think I live?",
1995+
session=SQLiteSession(session_id="id"),
1996+
)
1997+
1998+
1999+
async def test_session(client: Client):
2000+
new_config = client.config()
2001+
new_config["plugins"] = [
2002+
openai_agents.OpenAIAgentsPlugin(
2003+
model_provider=TestModelProvider(TestHelloModel()),
2004+
)
2005+
]
2006+
client = Client(**new_config)
2007+
2008+
async with new_worker(
2009+
client,
2010+
SessionWorkflow,
2011+
) as worker:
2012+
workflow_handle = await client.start_workflow(
2013+
SessionWorkflow.run,
2014+
id=f"session-{uuid.uuid4()}",
2015+
task_queue=worker.task_queue,
2016+
execution_timeout=timedelta(seconds=1.0),
2017+
retry_policy=RetryPolicy(maximum_attempts=1),
2018+
)
2019+
await assert_task_fail_eventually(
2020+
workflow_handle,
2021+
message_contains="Temporal workflows don't support SQLite sessions",
2022+
)

0 commit comments

Comments
 (0)