From 64e0ee2e7ef688275613b14198f629b26dda6751 Mon Sep 17 00:00:00 2001 From: Tim Conley Date: Thu, 11 Sep 2025 09:29:06 -0700 Subject: [PATCH 1/4] Expose strict_json_schema in activity_as_tool --- temporalio/contrib/openai_agents/workflow.py | 4 +++- uv.lock | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/temporalio/contrib/openai_agents/workflow.py b/temporalio/contrib/openai_agents/workflow.py index 2f69866ce..82b114925 100644 --- a/temporalio/contrib/openai_agents/workflow.py +++ b/temporalio/contrib/openai_agents/workflow.py @@ -44,6 +44,7 @@ def activity_as_tool( versioning_intent: Optional[VersioningIntent] = None, summary: Optional[str] = None, priority: Priority = Priority.default, + strict_json_schema: bool = True, ) -> Tool: """Convert a single Temporal activity function to an OpenAI agent tool. @@ -59,6 +60,7 @@ def activity_as_tool( Args: fn: A Temporal activity function to convert to a tool. + strict_json_schema: Whether the tool should follow a strict schema For other arguments, refer to :py:mod:`workflow` :py:meth:`start_activity` Returns: @@ -149,7 +151,7 @@ async def run_activity(ctx: RunContextWrapper[Any], input: str) -> Any: description=schema.description or "", params_json_schema=schema.params_json_schema, on_invoke_tool=run_activity, - strict_json_schema=True, + strict_json_schema=strict_json_schema, ) diff --git a/uv.lock b/uv.lock index 63a083a0c..fbf2f9470 100644 --- a/uv.lock +++ b/uv.lock @@ -2847,7 +2847,7 @@ requires-dist = [ { name = "eval-type-backport", marker = "python_full_version < '3.10' and extra == 'openai-agents'", specifier = ">=0.2.2" }, { name = "grpcio", marker = "extra == 'grpc'", specifier = ">=1.48.2,<2" }, { name = "nexus-rpc", specifier = "==1.1.0" }, - { name = "openai-agents", marker = "extra == 'openai-agents'", specifier = ">=0.2.11" }, + { name = "openai-agents", marker = "extra == 'openai-agents'", specifier = ">=0.2.11,<0.3" }, { name = "opentelemetry-api", marker = "extra == 'opentelemetry'", specifier = ">=1.11.1,<2" }, { name = "opentelemetry-sdk", marker = "extra == 'opentelemetry'", specifier = ">=1.11.1,<2" }, { name = "protobuf", specifier = ">=3.20,<6" }, @@ -2866,7 +2866,7 @@ dev = [ { name = "maturin", specifier = ">=1.8.2" }, { name = "mypy", specifier = "==1.4.1" }, { name = "mypy-protobuf", specifier = ">=3.3.0,<4" }, - { name = "openai-agents", extras = ["litellm"], specifier = ">=0.2.11" }, + { name = "openai-agents", extras = ["litellm"], specifier = ">=0.2.11,<0.3" }, { name = "psutil", specifier = ">=5.9.3,<6" }, { name = "pydocstyle", specifier = ">=6.3.0,<7" }, { name = "pydoctor", specifier = ">=24.11.1,<25" }, From d2788f215f4f90a7f7699436f7912de8ba7e93e2 Mon Sep 17 00:00:00 2001 From: Tim Conley Date: Thu, 11 Sep 2025 09:30:06 -0700 Subject: [PATCH 2/4] Revert lock --- uv.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uv.lock b/uv.lock index fbf2f9470..63a083a0c 100644 --- a/uv.lock +++ b/uv.lock @@ -2847,7 +2847,7 @@ requires-dist = [ { name = "eval-type-backport", marker = "python_full_version < '3.10' and extra == 'openai-agents'", specifier = ">=0.2.2" }, { name = "grpcio", marker = "extra == 'grpc'", specifier = ">=1.48.2,<2" }, { name = "nexus-rpc", specifier = "==1.1.0" }, - { name = "openai-agents", marker = "extra == 'openai-agents'", specifier = ">=0.2.11,<0.3" }, + { name = "openai-agents", marker = "extra == 'openai-agents'", specifier = ">=0.2.11" }, { name = "opentelemetry-api", marker = "extra == 'opentelemetry'", specifier = ">=1.11.1,<2" }, { name = "opentelemetry-sdk", marker = "extra == 'opentelemetry'", specifier = ">=1.11.1,<2" }, { name = "protobuf", specifier = ">=3.20,<6" }, @@ -2866,7 +2866,7 @@ dev = [ { name = "maturin", specifier = ">=1.8.2" }, { name = "mypy", specifier = "==1.4.1" }, { name = "mypy-protobuf", specifier = ">=3.3.0,<4" }, - { name = "openai-agents", extras = ["litellm"], specifier = ">=0.2.11,<0.3" }, + { name = "openai-agents", extras = ["litellm"], specifier = ">=0.2.11" }, { name = "psutil", specifier = ">=5.9.3,<6" }, { name = "pydocstyle", specifier = ">=6.3.0,<7" }, { name = "pydoctor", specifier = ">=24.11.1,<25" }, From 634c383ccc49c8aa11c5f7e801d1655eef6dbbc0 Mon Sep 17 00:00:00 2001 From: Tim Conley Date: Thu, 11 Sep 2025 10:27:10 -0700 Subject: [PATCH 3/4] Add to nexus as well --- temporalio/contrib/openai_agents/workflow.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/temporalio/contrib/openai_agents/workflow.py b/temporalio/contrib/openai_agents/workflow.py index 82b114925..561b5178a 100644 --- a/temporalio/contrib/openai_agents/workflow.py +++ b/temporalio/contrib/openai_agents/workflow.py @@ -161,6 +161,7 @@ def nexus_operation_as_tool( service: Type[Any], endpoint: str, schedule_to_close_timeout: Optional[timedelta] = None, + strict_json_schema: bool = True, ) -> Tool: """Convert a Nexus operation into an OpenAI agent tool. @@ -177,6 +178,7 @@ def nexus_operation_as_tool( fn: A Nexus operation to convert into a tool. service: The Nexus service class that contains the operation. endpoint: The Nexus endpoint to use for the operation. + strict_json_schema: Whether the tool should follow a strict schema Returns: An OpenAI agent tool that wraps the provided operation. @@ -237,7 +239,7 @@ async def run_operation(ctx: RunContextWrapper[Any], input: str) -> Any: description=schema.description or "", params_json_schema=schema.params_json_schema, on_invoke_tool=run_operation, - strict_json_schema=True, + strict_json_schema=strict_json_schema, ) From 118464ff5ad0ada5c5e704b2577c5a16068182fa Mon Sep 17 00:00:00 2001 From: tconley1428 Date: Thu, 25 Sep 2025 11:25:16 -0700 Subject: [PATCH 4/4] Update workflow.py --- temporalio/contrib/openai_agents/workflow.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/temporalio/contrib/openai_agents/workflow.py b/temporalio/contrib/openai_agents/workflow.py index ed49f68f5..51eff86a3 100644 --- a/temporalio/contrib/openai_agents/workflow.py +++ b/temporalio/contrib/openai_agents/workflow.py @@ -62,7 +62,8 @@ def activity_as_tool( Args: fn: A Temporal activity function to convert to a tool. - strict_json_schema: Whether the tool should follow a strict schema + strict_json_schema: Whether the tool should follow a strict schema. + See https://openai.github.io/openai-agents-python/ref/tool/#agents.tool.FunctionTool.strict_json_schema For other arguments, refer to :py:mod:`workflow` :py:meth:`start_activity` Returns: