motus serve. Each message spawns a fresh worker subprocess, so your agent runs in complete isolation. No shared state between requests, and a crash in one turn never affects another.
Quick start
Define your agent in a Python file, then start the server:myapp.py
Agent types
Every agent type follows the same turn contract: receive aChatMessage and the session’s prior state, return a response ChatMessage and updated state. All agent types run in worker subprocesses and must be importable from the module level.
Return value:
tuple[ChatMessage, list[ChatMessage]] the response message (surfaced to the HTTP client) and the updated state (stored in the session). The agent owns the state and can append, compact, or restructure it freely.
- ServableAgent
- Google ADK
- Anthropic SDK
- OpenAI Agents SDK
- Callable function
Any object with a conforming Built-in implementations include
run_turn method can be served directly. This is a runtime checkable. Protocolinheritance is not required.AgentBase and all of its subclasses (such as ReActAgent).Session lifecycle
Each conversation is a session. A session moves through the following states:A session in
error state can receive new messages and transitions back to running. Sessions are held in memory and do not persist across server restarts.--ttl is set, idle and errored sessions whose last activity exceeds the TTL are swept by a background task. When --timeout is set, agent turns that exceed the limit are killed and the session transitions to error with an "Agent timed out" message.
Architecture
Each message spawns a fresh subprocess viamultiprocessing.Process with pipe-based IPC. An asyncio.Semaphore limits concurrency to max_workers. Processes are not reused: each one starts, runs the agent function, sends the result over the pipe, and exits. On timeout or cancellation, the process is killed immediately.
This subprocess isolation model means:
- A crash in one agent turn never affects other sessions or the server itself.
- No shared state leaks between requests.
- Resource cleanup is automatic — when the process exits, all memory is reclaimed.
File structure
File structure
Server options
Start options formotus serve start:
CLI reference
motus serve chat
Send a message or enter an interactive REPL:
motus serve delete <url> <session-id> to delete manually.
Other commands
Python API
UseAgentServer to embed the server in your own Python application:
agent_fn are keyword-only):
run(host, port, log_level) -> None — starts the server (blocking).
The
server.app property exposes the underlying FastAPI application for testing or mounting in a larger application.
