Skip to content

Commit e54b5d1

Browse files
committed
Provide defaults
2 parents 46949cb + 3d9bfee commit e54b5d1

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
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(

temporalio/contrib/pydantic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class PydanticJSONPlainPayloadConverter(EncodingPayloadConverter):
5353
See https://docs.pydantic.dev/latest/api/standard_library_types/
5454
"""
5555

56-
def __init__(self, to_json_options: Optional[ToJsonOptions]):
56+
def __init__(self, to_json_options: Optional[ToJsonOptions] = None):
5757
"""Create a new payload converter."""
5858
self._schema_serializer = SchemaSerializer(any_schema())
5959
self._to_json_options = to_json_options
@@ -106,7 +106,7 @@ class PydanticPayloadConverter(CompositePayloadConverter):
106106
:py:class:`PydanticJSONPlainPayloadConverter`.
107107
"""
108108

109-
def __init__(self, to_json_options: Optional[ToJsonOptions]) -> None:
109+
def __init__(self, to_json_options: Optional[ToJsonOptions] = None) -> None:
110110
"""Initialize object"""
111111
json_payload_converter = PydanticJSONPlainPayloadConverter(to_json_options)
112112
super().__init__(

tests/contrib/openai_agents/test_openai.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
OutputGuardrailTripwireTriggered,
3535
RunContextWrapper,
3636
Runner,
37+
SQLiteSession,
3738
Tool,
3839
TResponseInputItem,
3940
Usage,
@@ -90,7 +91,7 @@
9091
from tests.contrib.openai_agents.research_agents.research_manager import (
9192
ResearchManager,
9293
)
93-
from tests.helpers import new_worker
94+
from tests.helpers import assert_task_fail_eventually, new_worker
9495
from tests.helpers.nexus import create_nexus_endpoint, make_nexus_endpoint_name
9596

9697

@@ -1996,6 +1997,47 @@ def test_summary_extraction():
19961997
assert _extract_summary(input) == "Second message"
19971998

19981999

2000+
@workflow.defn
2001+
class SessionWorkflow:
2002+
@workflow.run
2003+
async def run(self) -> None:
2004+
agent: Agent = Agent(
2005+
name="Assistant",
2006+
instructions="You are a helpful assistant.",
2007+
)
2008+
await Runner.run(
2009+
agent,
2010+
"My phone number is 650-123-4567. Where do you think I live?",
2011+
session=SQLiteSession(session_id="id"),
2012+
)
2013+
2014+
2015+
async def test_session(client: Client):
2016+
new_config = client.config()
2017+
new_config["plugins"] = [
2018+
openai_agents.OpenAIAgentsPlugin(
2019+
model_provider=TestModelProvider(TestHelloModel()),
2020+
)
2021+
]
2022+
client = Client(**new_config)
2023+
2024+
async with new_worker(
2025+
client,
2026+
SessionWorkflow,
2027+
) as worker:
2028+
workflow_handle = await client.start_workflow(
2029+
SessionWorkflow.run,
2030+
id=f"session-{uuid.uuid4()}",
2031+
task_queue=worker.task_queue,
2032+
execution_timeout=timedelta(seconds=1.0),
2033+
retry_policy=RetryPolicy(maximum_attempts=1),
2034+
)
2035+
await assert_task_fail_eventually(
2036+
workflow_handle,
2037+
message_contains="Temporal workflows don't support SQLite sessions",
2038+
)
2039+
2040+
19992041
async def test_lite_llm(client: Client, env: WorkflowEnvironment):
20002042
if not os.environ.get("OPENAI_API_KEY"):
20012043
pytest.skip("No openai API key")

0 commit comments

Comments
 (0)