The tool + backend seams: the explicit per-unit Workflow-vs-Activity choice.
Deep Agents holds its tools and filesystem/shell backends in-workflow. A tool or backend op that only reads and writes DeepAgentState is pure and belongs in the workflow (deterministic, replay-safe). One that does real I/O — a web search, a shell command, a disk write — must not run there. This module gives the user three explicit ways to move that work to an activity:
activity_as_tool— expose an existing @activity.defn as a Deep Agents tool (Temporal adopters already have activities; don't make them re-declare);tool_as_activity— wrap a LangChain BaseTool / callable so its execution runs as an activity;TemporalBackend— wrap a real-I/O backend so each file/exec op runs as an activity.
The choice is always explicit: an unwrapped non-builtin tool runs in-workflow, and the plugin warns at construction so that is a conscious decision, never a silent one.
Registries here live in a temporalio-namespaced (sandbox-passthrough) module, so the object the worker's activity sees is the same one the module-level tool_as_activity(...) / TemporalBackend(...) call populated. They hold worker-wide wiring, not per-workflow state.
| Function | get |
Look up a tool registered by register_tool. |
| Function | install |
Make BackendProtocol's async defaults workflow-safe. |
| Function | register |
Record a backend so DeepAgentActivities.backend_op can reach it. |
| Function | register |
Record tool so DeepAgentActivities.invoke_tool can run it. |
| Function | registered |
Return the live backend registry (read by the plugin at worker build). |
| Function | set |
Install the plugin's default tool_activity_options (called by the plugin). |
| Function | uninstall |
Restore BackendProtocol's upstream async defaults. |
| Function | warn |
Warn once per unwrapped, non-builtin tool passed to create_deep_agent. |
| Function | _is |
Undocumented |
| Function | _resolve |
Merge plugin tool defaults (possibly per-tool) with a per-call override. |
| Function | _unregister |
Drop ref from the registry if it still maps to inner. |
| Constant | _ASYNC |
Undocumented |
| Constant | _BACKEND |
Undocumented |
| Constant | _BACKEND |
Undocumented |
| Constant | _BACKEND |
Undocumented |
| Constant | _BUILTIN |
Undocumented |
| Constant | _ROUTED |
Undocumented |
| Constant | _TOOL |
Undocumented |
| Variable | _original |
Undocumented |
| Variable | _tool |
Undocumented |
Make BackendProtocol's async defaults workflow-safe.
Inside a workflow, run the sync twin inline: for state-only backends that is deterministic and semantically identical to the upstream default, which merely moves the same sync call onto a worker thread. Outside a workflow (activities, clients) the upstream default — thread hop plus timeout guard — is used unchanged. Subclasses that override an async method natively are unaffected; only the protocol defaults are replaced. Idempotent.
Install the plugin's default tool_activity_options (called by the plugin).
Accepts a single ActivityConfig or a Mapping[tool_name, ActivityConfig].
Warn once per unwrapped, non-builtin tool passed to create_deep_agent.
Running a tool in-workflow is only safe if it is pure/deterministic. The
Workflow-vs-Activity choice must be conscious, so any user tool that was not
routed through tool_as_activity / activity_as_tool gets a
construction-time warning rather than silently executing in the workflow.
str, instance_options: Mapping[ str, Any] | None) -> dict[ str, Any]:
(source)
¶
Merge plugin tool defaults (possibly per-tool) with a per-call override.
Drop ref from the registry if it still maps to inner.
GC hook for TemporalBackend (via weakref.finalize): a wrapper
is typically constructed per workflow run, so without cleanup a long-lived
worker accumulates one registry entry per run. The identity guard is
load-bearing: refs are deterministic per run, so after a cache eviction a
replay re-registers the same ref with a fresh inner backend — the evicted
wrapper's finalizer must not remove that live registration.
Undocumented
| Value |
|
Undocumented
| Value |
|