Workflow-specific primitives for working with the OpenAI Agents SDK in a workflow context
Exception |
|
Error that occurs when a tool output could not be serialized. |
Function | activity |
Convert a single Temporal activity function to an OpenAI agent tool. |
Function | nexus |
Convert a Nexus operation into an OpenAI agent tool. |
Function | stateful |
A stateful MCP server implementation for Temporal workflows. |
Function | stateless |
A stateless MCP server implementation for Temporal workflows. |
Callable
, *, task_queue: str | None
= None, schedule_to_close_timeout: timedelta | None
= None, schedule_to_start_timeout: timedelta | None
= None, start_to_close_timeout: timedelta | None
= None, heartbeat_timeout: timedelta | None
= None, retry_policy: RetryPolicy | None
= None, cancellation_type: ActivityCancellationType
= ActivityCancellationType.TRY_CANCEL, activity_id: str | None
= None, versioning_intent: VersioningIntent | None
= None, summary: str | None
= None, priority: Priority
= Priority.default, strict_json_schema: bool
= True) -> Tool
:
(source)
¶
Convert a single Temporal activity function to an OpenAI agent tool.
Warning
This API is experimental and may change in future versions. Use with caution in production environments.
This function takes a Temporal activity function and converts it into an OpenAI agent tool that can be used by the agent to execute the activity during workflow execution. The tool will automatically handle the conversion of inputs and outputs between the agent and the activity. Note that if you take a context, mutation will not be persisted, as the activity may not be running in the same location.
Example
>>> @activity.defn >>> def process_data(input: str) -> str: ... return f"Processed: {input}" >>> >>> # Create tool with custom activity options >>> tool = activity_as_tool( ... process_data, ... start_to_close_timeout=timedelta(seconds=30), ... retry_policy=RetryPolicy(maximum_attempts=3), ... heartbeat_timeout=timedelta(seconds=10) ... ) >>> # Use tool with an OpenAI agent
Parameters | |
fn:Callable | A Temporal activity function to convert to a tool. |
taskstr | None | Undocumented |
scheduletimedelta | None | Undocumented |
scheduletimedelta | None | Undocumented |
starttimedelta | None | Undocumented |
heartbeattimedelta | None | Undocumented |
retryRetryPolicy | None | Undocumented |
cancellationActivityCancellationType | Undocumented |
activitystr | None | Undocumented |
versioningVersioningIntent | None | Undocumented |
summary:str | None | Undocumented |
priority:Priority | Undocumented |
strictbool | Whether the tool should follow a strict schema. See https://openai.github.io/openai-agents-python/ref/tool/#agents.tool.FunctionTool.strict_json_schema |
refer to workflow start | |
Returns | |
Tool | An OpenAI agent tool that wraps the provided activity. |
Raises | |
ApplicationError | If the function is not properly decorated as a Temporal activity. |
nexusrpc.Operation[ Any, Any]
, *, service: type[ Any]
, endpoint: str
, schedule_to_close_timeout: timedelta | None
= None, strict_json_schema: bool
= True) -> Tool
:
(source)
¶
Convert a Nexus operation into an OpenAI agent tool.
Warning
This API is experimental and may change in future versions. Use with caution in production environments.
This function takes a Nexus operation and converts it into an OpenAI agent tool that can be used by the agent to execute the operation during workflow execution. The tool will automatically handle the conversion of inputs and outputs between the agent and the operation.
Example
>>> @nexusrpc.service ... class WeatherService: ... get_weather_object_nexus_operation: nexusrpc.Operation[WeatherInput, Weather] >>> >>> # Create tool with custom activity options >>> tool = nexus_operation_as_tool( ... WeatherService.get_weather_object_nexus_operation, ... service=WeatherService, ... endpoint="weather-service", ... ) >>> # Use tool with an OpenAI agent
Parameters | |
operation:nexusrpc.Operation[ | Undocumented |
service:type[ | The Nexus service class that contains the operation. |
endpoint:str | The Nexus endpoint to use for the operation. |
scheduletimedelta | None | Undocumented |
strictbool | Whether the tool should follow a strict schema |
fn | A Nexus operation to convert into a tool. |
Returns | |
Tool | An OpenAI agent tool that wraps the provided operation. |
str
, config: ActivityConfig | None
= None, server_session_config: ActivityConfig | None
= None) -> AbstractAsyncContextManager[ MCPServer]
:
(source)
¶
A stateful MCP server implementation for Temporal workflows.
Warning
This API is experimental and may change in future versions. Use with caution in production environments.
This wraps an MCP server to maintain a persistent connection throughout the workflow execution. It creates a dedicated worker that stays connected to the MCP server and processes operations on a dedicated task queue.
This approach is more efficient for workflows that make multiple MCP calls, as it avoids connection overhead, but requires more resources to maintain the persistent connection and worker.
The caller will have to handle cases where the dedicated worker fails, as Temporal is unable to seamlessly recreate any lost state in that case.
Parameters | |
name:str | A string name for the server. Should match that provided in the plugin. |
config:ActivityConfig | None | Optional activity configuration for MCP operation activities. Defaults to 1-minute start-to-close and 30-second schedule-to-start timeouts. |
serverActivityConfig | None | Optional activity configuration for the connection activity. Defaults to 1-hour start-to-close timeout. |
Returns | |
AbstractAsyncContextManager[ | Undocumented |
str
, config: ActivityConfig | None
= None, cache_tools_list: bool
= False) -> MCPServer
:
(source)
¶
A stateless MCP server implementation for Temporal workflows.
Warning
This API is experimental and may change in future versions. Use with caution in production environments.
This uses a TemporalMCPServer of the same name registered with the OpenAIAgents plugin to implement durable MCP operations statelessly.
This approach is suitable for simple use cases where connection overhead is acceptable and you don't need to maintain state between operations. It should be preferred to stateful when possible due to its superior durability guarantees.
Parameters | |
name:str | A string name for the server. Should match that provided in the plugin. |
config:ActivityConfig | None | Optional activity configuration for MCP operation activities. Defaults to 1-minute start-to-close timeout. |
cachebool | If true, the list of tools will be cached for the duration of the server |
Returns | |
MCPServer | Undocumented |