From ae39ae9ad20b920e896aab0a4cf5676d70a7aef2 Mon Sep 17 00:00:00 2001 From: Francesc Campoy Date: Tue, 24 Nov 2026 14:17:04 -0800 Subject: [PATCH] Update Python integration docs for the GA samples --- .../python/integrations/deepagents.mdx | 66 ++++++++++++------- .../python/integrations/google-adk.mdx | 9 +-- .../python/integrations/openai-agents.mdx | 26 ++++++-- .../python/integrations/strands-agents.mdx | 22 +++---- 4 files changed, 75 insertions(+), 48 deletions(-) diff --git a/docs/develop/python/integrations/deepagents.mdx b/docs/develop/python/integrations/deepagents.mdx index 3125a88b17..bc4cf96e0a 100644 --- a/docs/develop/python/integrations/deepagents.mdx +++ b/docs/develop/python/integrations/deepagents.mdx @@ -178,6 +178,8 @@ Activity: - `tool_as_activity(tool, ...)` wraps a LangChain tool whose body does I/O so its execution runs as a `deepagents.invoke_tool` Activity. +Call `tool_as_activity` at module level. Options set on a plugin created later do not change an existing wrapper. + An unwrapped, non-builtin tool runs in-Workflow, and the plugin emits a best-effort warning at agent construction (the warning fires through the plugin's `create_deep_agent` seam, so code paths that bypass that seam construct without it). @@ -187,19 +189,23 @@ This sample wraps an existing activity and an I/O tool, and builds the agent wit which wraps the model name in a durable `TemporalModel` and scopes `activity_options` to this agent's model calls: -[deepagents_plugin/react_agent/workflow.py](https://github.com/temporalio/samples-python/blob/main/deepagents_plugin/react_agent/workflow.py) +[deepagents_plugin/react_agent/tools.py](https://github.com/temporalio/samples-python/blob/main/deepagents_plugin/react_agent/tools.py) ```py +from datetime import timedelta + +from langchain_core.tools import tool +from temporalio import activity +from temporalio.deepagents import activity_as_tool, tool_as_activity +from temporalio.workflow import ActivityConfig + + @activity.defn async def get_weather(city: str) -> str: """Return the current weather for a city.""" # A real implementation would call a weather API here; this is a stand-in. return f"It is sunny and 22C in {city}." -``` - - -[deepagents_plugin/react_agent/workflow.py](https://github.com/temporalio/samples-python/blob/main/deepagents_plugin/react_agent/workflow.py) -```py + @tool def web_search(query: str) -> str: """Search the web for a query and return a short result.""" @@ -208,18 +214,30 @@ def web_search(query: str) -> str: return f"Top result for {query!r}: Temporal makes code durable." +# An existing Temporal activity, exposed to the agent as a tool. +weather_tool = activity_as_tool( + get_weather, + activity_options=ActivityConfig(start_to_close_timeout=timedelta(seconds=30)), +) +# A LangChain tool whose body does I/O, moved into an activity. +search_tool = tool_as_activity(web_search, start_to_close_timeout=timedelta(seconds=30)) +``` + + + +[deepagents_plugin/react_agent/workflow.py](https://github.com/temporalio/samples-python/blob/main/deepagents_plugin/react_agent/workflow.py) +```py +# The tools module calls tool_as_activity(...) at import, which registers the +# tool in the worker process. Pass it through the sandbox so that registration +# happens once and the activity runs the real tool. +with workflow.unsafe.imports_passed_through(): + from deepagents_plugin.react_agent.tools import search_tool, weather_tool + + @workflow.defn class ReactAgent: @workflow.run async def run(self, question: str) -> str: - weather_tool = activity_as_tool( - get_weather, - start_to_close_timeout=timedelta(seconds=30), - ) - search_tool = tool_as_activity( - web_search, - start_to_close_timeout=timedelta(seconds=30), - ) agent = create_temporal_deep_agent( model="anthropic:claude-sonnet-4-5", tools=[weather_tool, search_tool], @@ -343,14 +361,16 @@ memory, rehydrated by deterministic replay, and the stable Workflow ID is used a [deepagents_plugin/human_in_the_loop/workflow.py](https://github.com/temporalio/samples-python/blob/main/deepagents_plugin/human_in_the_loop/workflow.py) ```py -from datetime import timedelta - from deepagents import create_deep_agent from langchain_core.runnables import RunnableConfig from langgraph.checkpoint.memory import InMemorySaver from langgraph.types import Command from temporalio import workflow -from temporalio.deepagents import tool_as_activity + +# tools.py calls tool_as_activity(...) at module level, so the worker registers +# the tool once, at import. +with workflow.unsafe.imports_passed_through(): + from deepagents_plugin.human_in_the_loop.tools import trip_tool @workflow.defn @@ -362,13 +382,6 @@ class HumanInTheLoopAgent: @workflow.run async def run(self, city: str) -> str: - def book_trip(city: str) -> str: - """Book a trip to a city (requires human approval).""" - return f"Booked a trip to {city}." - - trip_tool = tool_as_activity( - book_trip, start_to_close_timeout=timedelta(seconds=30) - ) agent = create_deep_agent( model="anthropic:claude-sonnet-4-5", tools=[trip_tool], @@ -422,6 +435,7 @@ Long conversations bloat Workflow history until it hits Temporal's limits. `run_ state_snapshot=...)` snapshots state and continues into a fresh run when a turn ends with pending todos and the server recommends continuing (`workflow.info().is_continue_as_new_suggested()`, the default and recommended mode). Pass `continue_as_new_after=N` to trigger on a fixed history-event count instead. +Add `TodoListMiddleware` to record the pending todos that `run_deep_agent` checks. - **Carries forward:** the accumulated messages and the agent's state files (the graph's `files` state). Repeated identical calls are not deduplicated: a call the agent makes again after the continue-as-new runs its own Activity. @@ -439,6 +453,7 @@ straight through, not re-wrapped, or the carried conversation is corrupted. from typing import Any from deepagents import create_deep_agent +from langchain.agents.middleware import TodoListMiddleware from temporalio import workflow from temporalio.deepagents import run_deep_agent @@ -455,6 +470,9 @@ class LongResearchAgent: "You are a research agent. Break large tasks into todos and work " "through them until the research is complete." ), + # run_deep_agent continues as new only while todos are pending, and + # this middleware is what records them. + middleware=[TodoListMiddleware()], ) result = await run_deep_agent( agent, diff --git a/docs/develop/python/integrations/google-adk.mdx b/docs/develop/python/integrations/google-adk.mdx index a67fbe2022..67189c4cba 100644 --- a/docs/develop/python/integrations/google-adk.mdx +++ b/docs/develop/python/integrations/google-adk.mdx @@ -20,7 +20,7 @@ you write an ordinary ADK agent and run it as a Workflow, without managing sessi The `GoogleAdkPlugin` is what ties them together. It runs each model call and tool call as a Temporal Activity, configures the payload converter that serializes ADK objects, and makes ADK's runtime deterministic so the Workflow can -replay. You add the same plugin to your Client and your Worker, and the rest of your agent code stays standard ADK. +replay. You add the plugin to your Client, and the rest of your agent code stays standard ADK. ## Prerequisites @@ -101,10 +101,9 @@ class HelloWorldAgentWorkflow: Everything other than `TemporalModel` is normal ADK. You build an `Agent`, drive it with a runner, and read the events it produces. -## Add the plugin to your Worker and Client +## Add the plugin to your Client -Build one `GoogleAdkPlugin` and pass the same instance to both the Client and the Worker. The Client side links the code -that starts a Workflow to the Workflow itself, and the Worker side runs the agent. +Pass `GoogleAdkPlugin` to the Client. Workers built from that Client inherit the plugin. {/* SNIPSTART google-adk-agents-basic-worker */} [google_adk_agents/basic/run_worker.py](https://github.com/temporalio/samples-python/blob/main/google_adk_agents/basic/run_worker.py) @@ -119,7 +118,6 @@ worker = Worker( client, task_queue="google-adk-agents-basic", workflows=[HelloWorldAgentWorkflow], - plugins=[plugin], ) await worker.run() ``` @@ -200,7 +198,6 @@ worker = Worker( task_queue="google-adk-agents-tools", workflows=[WeatherAgentWorkflow], activities=[get_weather], - plugins=[plugin], ) await worker.run() ``` diff --git a/docs/develop/python/integrations/openai-agents.mdx b/docs/develop/python/integrations/openai-agents.mdx index 3b4a1a7051..0f1119be3d 100644 --- a/docs/develop/python/integrations/openai-agents.mdx +++ b/docs/develop/python/integrations/openai-agents.mdx @@ -520,10 +520,12 @@ Sandbox support is pre-release and may change before general availability. plugin dispatches every sandbox operation—creating the session, each command, each read and write, PTY interaction, and teardown—as its own Temporal Activity. Each one is individually retryable and visible in Workflow history, and the session state is serialized with the Workflow. On a hosted backend, a Worker restart part-way through a run resumes -against the same session. On the Docker and Unix-local backends, a Worker restart in the middle of a step loses the -sandbox, and the step's next operation fails with the non-retryable `ApplicationError` type `SandboxLost`. +against the same session. A Docker or Unix-local sandbox stays on the Worker that created it. This sample sets a +schedule-to-start timeout so an operation fails if that Worker is unavailable. If a Worker receives an operation for a +sandbox it no longer has, it raises the non-retryable `ApplicationError` type `SandboxLost`. -Register a `SandboxClientProvider` for each backend you want to reach, under a unique name: +Register an `OnHostSandboxClientProvider` for Docker and Unix-local backends, with a unique `worker_name` per Worker +process. Use `SandboxClientProvider` for hosted backends: [openai_agents/sandbox/run_worker.py](https://github.com/temporalio/samples-python/blob/main/openai_agents/sandbox/run_worker.py) @@ -538,8 +540,16 @@ client = await Client.connect( # The plugin registers one set of sandbox activities per # provider, prefixed with the provider name. Register several # providers to let one worker serve several backends. + # Unix-local and Docker sandboxes live on this machine, so they + # use OnHostSandboxClientProvider, which sends every operation + # on a sandbox to the worker that created it. Hosted backends + # such as Daytona use SandboxClientProvider. sandbox_clients=[ - SandboxClientProvider(SANDBOX_PROVIDER, UnixLocalSandboxClient()), + OnHostSandboxClientProvider( + SANDBOX_PROVIDER, + UnixLocalSandboxClient(), + worker_name=str(uuid.uuid4()), + ), ], ), ], @@ -573,7 +583,13 @@ class LocalSandboxWorkflow: run_config=RunConfig( sandbox=SandboxRunConfig( # Must match the name registered on the worker. - client=temporal_sandbox_client(SANDBOX_PROVIDER), + client=temporal_sandbox_client( + SANDBOX_PROVIDER, + config=ActivityConfig( + start_to_close_timeout=timedelta(minutes=5), + schedule_to_start_timeout=timedelta(seconds=30), + ), + ), options=UnixLocalSandboxClientOptions(), ), ), diff --git a/docs/develop/python/integrations/strands-agents.mdx b/docs/develop/python/integrations/strands-agents.mdx index 8529f32cc6..a9524856dd 100644 --- a/docs/develop/python/integrations/strands-agents.mdx +++ b/docs/develop/python/integrations/strands-agents.mdx @@ -373,7 +373,7 @@ dataclass or Pydantic model for multiple values. This is needed because hook eve If your agent needs access to tools provided by an [MCP](https://modelcontextprotocol.io/) server, configure the MCP clients on the Worker and reference them by name in the Workflow. -`StrandsPlugin(mcp_clients=...)` takes a mapping of `name` to `MCPClient` factory, mirroring the `models` pattern. The +`StrandsPlugin(mcp_clients=...)` takes a mapping of `name` to `mcp.Client` factory, mirroring the `models` pattern. The plugin registers a per-server Activity. In the Workflow, `TemporalMCPClient(server="name")` is a handle that references the server by name and carries per-call Activity options. @@ -409,23 +409,20 @@ class MCPWorkflow: Register the MCP client factory on the Worker: - + [strands_plugin/mcp/run_worker.py](https://github.com/temporalio/samples-python/blob/main/strands_plugin/mcp/run_worker.py) ```py # ... -from mcp import StdioServerParameters, stdio_client -from strands.tools.mcp.mcp_client import MCPClient +import mcp from temporalio.client import Client from temporalio.strands_agents import StrandsPlugin from temporalio.worker import Worker # ... -def _make_echo_client() -> MCPClient: - return MCPClient( - lambda: stdio_client( - StdioServerParameters( - command=sys.executable, - args=[str(ECHO_SERVER)], - ) +def _make_echo_client() -> mcp.Client: + return mcp.Client( + mcp.StdioServerParameters( + command=sys.executable, + args=[str(ECHO_SERVER)], ) ) # ... @@ -446,8 +443,7 @@ async def main() -> None: ``` -Each factory returns a fully configured `MCPClient`, so you can pass options like `tool_filters`, `prefix`, -`elicitation_callback`, or `tasks_config` to it. +Each factory returns a new `mcp.Client`. Set `prefix` and `tool_filters` on `TemporalMCPClient`. :::info