Serialization helpers, a result cache, and worker-runtime configuration.
The Deep Agents control loop runs inside the Temporal workflow, so the values that actually cross the workflow⇄activity boundary are a small set of LangChain types: chat messages, tool-call descriptors, and the RunnableConfig metadata attached to each model / tool call. LangChain messages are polymorphic Serializable models (an AIMessage must not be rehydrated as a ToolMessage) and RunnableConfig carries live callback / checkpointer references, so neither survives a naive round-trip. This module owns:
- message (de)serialization via langchain_core.load.dumpd / load — the round-trip that preserves message subtype and tool-call structure;
- the strip → ship → rebuild dance for RunnableConfig;
- tool → JSON-schema advertisement (full name + description + argument schema, never {name, description} alone — without the argument schema the model picks the right tool but hallucinates its arguments);
- the Pydantic data converter (exclude_unset=True) the plugin installs on the client and replayer, so message payloads stay small and round-trip cleanly;
- a workflow-scoped result cache so model / tool results computed before a continue_as_new are reused rather than recomputed after it;
- the sandbox passthrough module list covering LangChain's transitive eager-import tree.
LangChain imports are deferred into the functions that need them, so importing this module — and constructing the plugin — does not require LangChain to be installed on the machine assembling the worker.
| Class | |
Pydantic payload converter pinned to exclude_unset=True. |
| Class | |
Dispatch defaults shared by every TemporalModel on the worker. |
| Function | build |
Compose the plugin's converter with whatever the caller already set. |
| Function | cache |
Stable key over (kind, call_id, args) for cache lookups. |
| Function | cache |
Return (hit, value) for key in the active cache. |
| Function | cache |
Record value under key when a cache is active for this run. |
| Function | default |
The LangChain / deepagents transitive import tree passed through the sandbox. |
| Function | dump |
Encode a backend op's return value for the activity boundary. |
| Function | dump |
Serialize a sequence of LangChain messages to their dumpd form. |
| Function | dump |
Serialize a single LangChain Serializable (message, tool call, …). |
| Function | get |
Return the active dispatch settings. |
| Function | load |
Rebuild a value produced by dump_backend_result. |
| Function | load |
Rehydrate messages serialized by dump_messages. |
| Function | load |
Rehydrate a value produced by dump_object, preserving subtype. |
| Function | rebuild |
Reconstruct a minimal RunnableConfig from strip_runnable_config. |
| Function | resolve |
Merge caller-supplied passthrough modules with the plugin defaults. |
| Function | result |
Return a serializable copy of the cache, or None when empty. |
| Function | set |
Seed the workflow-scoped result cache (e.g. carried across CAN). |
| Function | set |
Install the worker-wide model dispatch defaults (called by the plugin). |
| Function | strip |
Reduce a live RunnableConfig to its JSON-safe subset for shipping. |
| Function | tool |
Advertise a tool to the model as a full OpenAI tool schema. |
| Variable | data |
The plugin's default data converter (LangChain messages are shipped as their dumpd JSON form, so the Pydantic converter only ever sees plain containers). |
| Function | _is |
Undocumented |
| Constant | _BACKEND |
Undocumented |
| Constant | _DEFAULT |
Undocumented |
| Variable | _result |
Undocumented |
| Variable | _settings |
Undocumented |
Compose the plugin's converter with whatever the caller already set.
- None — install the plugin default.
- the SDK default converter — swap in the LangChain-aware Pydantic
converter via
dataclasses.replace. - a custom converter — refuse rather than silently clobber it; the caller
must fold
DeepAgentsPayloadConverterinto their own converter.
Encode a backend op's return value for the activity boundary.
Backend protocol results (WriteResult / ReadResult / GrepResult
and their nested FileInfo / GrepMatch items, …) are plain
dataclasses — not LangChain Serializable objects — and the filesystem
middleware reads their ATTRIBUTES in-workflow, so a plain JSON round-trip
(which decays them to dicts) breaks the seam at the first real backend op.
Tag deepagents dataclasses with their import path so
load_backend_result rebuilds the real type; anything else (str,
dict, a custom backend's own types) passes through with today's
plain-JSON behavior.
Rebuild a value produced by dump_backend_result.
Only deepagents.* dataclasses are reconstructed (the tag is written exclusively for them); anything else would mean a forged payload, so refuse rather than import arbitrary types. Reconstruction suppresses DeprecationWarning: this is transport, not user code — the backend already constructed the object once on the activity side, and required deprecated fields (e.g. WriteResult.files_update) would otherwise warn on every op. Field values equal to a declared default are omitted from the constructor call.
Any = None, streaming_topic: str | None = None):
(source)
¶
Install the worker-wide model dispatch defaults (called by the plugin).
Reduce a live RunnableConfig to its JSON-safe subset for shipping.
Keeps tags, run_name, run_id, recursion_limit, JSON-safe metadata and the JSON-safe (non-dunder) configurable keys. Drops callbacks, checkpointer / store / cache handles and every other live reference — those are reconstructed activity-side.
Advertise a tool to the model as a full OpenAI tool schema.
Carries name + description + argument JSON schema so the model can build valid arguments, not just select the tool by name.
The plugin's default data converter (LangChain messages are shipped as their dumpd JSON form, so the Pydantic converter only ever sees plain containers).