Skip to main content
The self-managed motus exposes any agent as an HTTP server with session-based conversations using 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 a ChatMessage 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.
Any object with a conforming run_turn method can be served directly. This is a runtime checkable. Protocolinheritance is not required.
Built-in implementations include 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.
When --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 via multiprocessing.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.
For detailed CLI usage and all available flags, see the CLI reference for motus serve.

Server options

Start options for motus serve start:

CLI reference

motus serve chat

Send a message or enter an interactive REPL:
Sessions are always kept on exit so traces remain viewable. The session ID is printed when a new session is created — copy it to resume later or to inspect traces in the cloud console. Use motus serve delete <url> <session-id> to delete manually.

Other commands

Python API

Use AgentServer to embed the server in your own Python application:
Constructor parameters (all except 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.