module documentation

The activities that carry every nondeterministic Deep Agents operation.

The Deep Agents control loop runs inside the workflow; the operations that must not run there — talking to an LLM, executing a tool that does real I/O, or touching a real filesystem / shell backend — are moved out to these activities.

Each activity is a method on DeepAgentActivities so the worker-only dependencies (the model_provider that builds real chat models from a name, the streaming batch interval) can be captured on the instance rather than smuggled through activity inputs. API keys therefore live on the worker, never in a workflow input or in history.

Every method:

  • takes a single serializable dataclass in and returns a single dataclass out (LangChain objects travel as their dumpd JSON form via temporalio.contrib.deepagents._serde);
  • translates the LLM SDK's HTTP error into Temporal's retry contract so a 429 honors the upstream retry-after instead of hammering it;
  • heartbeats on a background task so a slow (thinking-mode / long-context) call is not mistaken for a stuck worker.
Class BackendOpInput A single filesystem / shell / store operation for a wrapped backend.
Class BackendOpOutput The backend operation's return value.
Class DeepAgentActivities Holds the worker-side dependencies and exposes the four activities.
Class ModelActivityInput A single LLM request.
Class ModelActivityOutput The model's reply.
Class ToolActivityInput One tool execution routed to an activity.
Class ToolActivityOutput A tool result as a ToolMessage in dumpd form.
Constant BACKEND_OP Undocumented
Constant INVOKE_MODEL Undocumented
Constant INVOKE_MODEL_STREAMING Undocumented
Constant INVOKE_TOOL Undocumented
Function _auto_heartbeater Heartbeat at half the configured heartbeat_timeout while fn runs.
Function _default_model_provider Build a chat model from a name string with LLM-SDK retries disabled.
Function _translate_api_error Map an LLM SDK HTTP error onto Temporal's retry contract.
BACKEND_OP: str = (source)

Undocumented

Value
'deepagents.backend_op'
INVOKE_MODEL: str = (source)

Undocumented

Value
'deepagents.invoke_model'
INVOKE_MODEL_STREAMING: str = (source)

Undocumented

Value
'deepagents.invoke_model_streaming'
INVOKE_TOOL: str = (source)

Undocumented

Value
'deepagents.invoke_tool'
def _auto_heartbeater(fn: Callable) -> Callable: (source)

Heartbeat at half the configured heartbeat_timeout while fn runs.

Long LLM calls (thinking mode, long context, streaming accumulation) can run well past a scheduler's patience; without a heartbeat Temporal would cancel them and surface a HeartbeatTimeoutError instead of the real problem.

def _default_model_provider(model_name: str) -> Any: (source)

Build a chat model from a name string with LLM-SDK retries disabled.

Temporal owns retries; the model client must not also retry, or a single logical attempt fans out into nested retry storms that Temporal can neither see nor bound.

def _translate_api_error(exc: Exception) -> ApplicationError | None: (source)

Map an LLM SDK HTTP error onto Temporal's retry contract.

Works by duck typing so neither openai nor anthropic needs to be imported here: both expose status_code and response.headers. Returns None when exc is not a recognizable HTTP status error, so the caller can fall through to its generic handling.