ToolRunner,
and serve it.
Installation
- uv
- pip
The Anthropic SDK is a core dependency of Motus. You need
anthropic>=0.49.0
for tool runner support.Basic usage
ImportToolRunner and beta_async_tool from motus.anthropic. Use @beta_async_tool to decorate your tool functions, then pass them to ToolRunner:
ToolRunner holds your model configuration and tool list. It creates a fresh
BetaAsyncToolRunner on each turn. Tool runners are single-use generators that
cannot be re-iterated, so ToolRunner handles that lifecycle for you.
Tool types
You can pass several tool types toToolRunner.tools:
- Functions decorated with
@beta_async_toolor@beta_tool - Plain async or sync Python functions (auto-wrapped on each turn)
- Motus
@tool-decorated functions (unwrapped and re-wrapped automatically)
Limiting the tool-use loop
Passmax_iterations to stop after a fixed number of tool-use rounds:
Deployment
Local serving
Pass therunner object directly to motus serve start:
runner is a ToolRunner instance defined at module level in myapp.py.
Cloud deployment
requirements.txt with anthropic>=0.49.0 (the SDK is not in the base image). No API key secrets are needed - the platform routes Anthropic API calls through the model proxy.
Session state (conversation history) is persisted in DynamoDB and survives backend restarts, failovers, and scaling events.
State management
Motus manages conversation state across turns. Each turn receives the full prior conversation as a list ofChatMessage objects. ToolRunner converts that state into Anthropic message format and prepends it to every request, so the model always sees the full conversation context.
You do not need to manage history yourself. Motus passes prior state in and
stores the updated state after each turn automatically.
Tracing
Tracing is automatic when the Motus runtime is active (as it is insidemotus serve). Each turn produces three span types in TraceManager:
All
model_call and tool_call spans are parented to the root agent_call span for the turn. Traces are auto-exported on process exit.
On the Motus cloud platform, the
AsyncAnthropic() client picks up platform-injected environment variables that route requests through the model proxy. You do not need to set ANTHROPIC_API_KEY at deploy time.Exports
motus.anthropic re-exports the following from the Anthropic SDK, plus Motus-specific additions:

