Skip to content

Serve over HTTP and stream

maiden serve exposes the agent over HTTP. Each request is a conversation turn on a named thread; the thread is checkpointed after every turn, so restarts resume cleanly (see Execution model).

Terminal window
maiden serve my-agent --port 8080

POST a JSON body:

{
"thread": "t1",
"message": "echo hello",
"stream": false
}
FieldTypeDefaultDescription
threadstringThe conversation to run on. Reusing it resumes history.
messagestringThe user message.
streambooleanfalseWhen true, respond with Server-Sent Events instead of one JSON body.

With stream off (or omitted), you get a single JSON object once the run finishes:

Terminal window
curl -s localhost:8080 -d '{"thread":"t1","message":"echo hello"}'
{
"answer": "Tool returned: {\"echoed\":\"from-mock\", ...}",
"turns": 2,
"resumed_from_checkpoint": false,
"thread_messages": 4
}
FieldDescription
answerThe final answer text.
turnsModel turns taken this run.
resumed_from_checkpointWhether the thread had prior history on disk.
thread_messagesTotal entries in the thread after this exchange.

A malformed request returns { "error": "..." }.

Set stream: true to receive events as the run progresses. Use curl -N to disable buffering:

Terminal window
curl -sN localhost:8080 -d '{"thread":"t1","message":"echo hello","stream":true}'
event: tool
data: {"tool":"structured-echo"}
event: token
data: {"token":"The tool returned "}
event: done
data: {"answer":"The tool returned ...","turns":2,"resumed_from_checkpoint":false,"thread_messages":4}

The event types are:

EventDataWhen
token{ "token": "..." }A chunk of the answer text as the model produces it.
tool{ "tool": "name" }A tool is being invoked this round.
donethe full JSON response (as above)The run finished.
error{ "error": "..." }The run failed.

Streaming works with every provider. A backend without native token streaming still drives the same event path — it emits the final answer as a single token event before done — so your client code is identical regardless of provider.

The server, schedules, and channels share one runtime lock, so a streaming request holds the runtime for its duration. maiden is designed for durable, sequential agent work rather than many simultaneous requests — see Execution model.