Skip to content
9 changes: 7 additions & 2 deletions temporalio/contrib/openai_agents/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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.

Expand All @@ -61,6 +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.
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:
Expand Down Expand Up @@ -151,7 +154,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,
)


Expand All @@ -161,6 +164,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.

Expand All @@ -177,6 +181,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.
Expand Down Expand Up @@ -237,7 +242,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,
)


Expand Down
Loading