module documentation

The model seam: a chat model whose every call becomes a Temporal activity.

TemporalModel is a real BaseChatModel. Placed anywhere Deep Agents expects a model, it routes each generation through the deepagents.invoke_model activity instead of calling the provider inline. Because Deep Agents' sub-agents inherit the parent's model instance by default, substituting this one object makes every model call in the whole agent tree durable — no middleware injection that a sub-agent could silently miss.

Two ways to get one:

  • explicit — the user writes TemporalModel("anthropic:claude-...") and hands it to create_deep_agent(model=...); this is the public type users assert against;
  • implicit — while running inside a workflow, the plugin patches create_deep_agent so a bare model="anthropic:..." string is wrapped automatically (see install_model_patch).

Worker-wide dispatch defaults (activity options, streaming topic) live in temporalio.contrib.deepagents._serde.Settings, a module global set by the plugin. They live in _serde (not here) so the plugin can configure them without importing this module — which would drag LangChain into plugin construction. This module is under temporalio, which the workflow sandbox passes through, so the object the workflow reads is the same one the plugin set.

Function install_model_patch Route Deep Agents' model resolution through TemporalModel.
Function uninstall_model_patch Restore the original resolve_model / create_deep_agent.
Function _as_message_chunk Re-shape a finished AIMessage as the AIMessageChunk a stream yields.
Function _looks_like_activity_config A single ActivityConfig has known option keys; a per-model map does not.
Function _resolve_activity_options Merge worker defaults with a per-instance override into execute_activity kwargs.
Function _wrap_model_arg Resolve a create_deep_agent model argument to a durable model.
Constant _DEFAULT_MODEL_TIMEOUT Undocumented
Variable _original_create_deep_agent Undocumented
Variable _original_resolve_model Undocumented
def install_model_patch(): (source)

Route Deep Agents' model resolution through TemporalModel.

Patches deepagents.graph.resolve_model (the seam create_deep_agent uses for the main agent and every sub-agent) so a bare model="..." string becomes a durable TemporalModel, and additionally wraps deepagents.create_deep_agent to fire the advisory tool / checkpointer warnings. Both only act when called inside a workflow, so importing deepagents on a plain client / activity worker is unaffected. Idempotent.

def uninstall_model_patch(): (source)

Restore the original resolve_model / create_deep_agent.

def _as_message_chunk(message: Any) -> Any: (source)

Re-shape a finished AIMessage as the AIMessageChunk a stream yields.

def _looks_like_activity_config(m: Mapping[str, Any]) -> bool: (source)

A single ActivityConfig has known option keys; a per-model map does not.

def _resolve_activity_options(model_name: str, instance_options: Mapping[str, Any] | None) -> dict[str, Any]: (source)

Merge worker defaults with a per-instance override into execute_activity kwargs.

def _wrap_model_arg(model: Any) -> Any: (source)

Resolve a create_deep_agent model argument to a durable model.

A name string becomes a TemporalModel. A TemporalModel passes through. Any other live BaseChatModel instance is rejected at the workflow boundary: it has no name the activity could rebuild from, so it would run its provider call inside the workflow — nondeterministic and unsafe.

_DEFAULT_MODEL_TIMEOUT = (source)

Undocumented

Value
timedelta(minutes=5)
_original_create_deep_agent: Any = (source)

Undocumented

_original_resolve_model: Any = (source)

Undocumented