MAAManaged Agents Anywhere
Docs›Build

Sessions and events

Built. A session is one run. You talk to it with events and it answers with events.

Createagent + environmentRunningthe agent worksIdlefinished, or waitingfor your approvalDeletedata removed,key destroyedCertificatesigned and loggedyou send a message, an approval or a tool resultevents stream to you liveyou choose when
A session moves between running and idle as often as you like. Deleting it is final and always ends in a certificate.

Start a session

const session = await client.beta.sessions.create({
  agent: agent.id,                      // or { type: "agent", id, version } to pin a version
  environment_id: environment.id,
  title: "Company analysis",
  vault_ids: [vault.id],                // credentials, attached at creation only
  resources: [{ type: "memory_store", memory_store_id: store.id }],
});
Field Meaning
agent An agent id, a pinned {type: "agent", id, version}, or agent_with_overrides to change model, prompt or tools for this session only
environment_id The sandbox template
initial_events Events to queue at creation, such as the first user.message or a user.define_outcome
vault_ids Vaults whose credentials this session may use
resources Files, GitHub repositories and memory stores to mount
budget A hard spend cap: {type: "limit", max_list_cost: {amount, currency}}. Amount is in minor units as a string ("2500" is £25.00). GBP, EUR or USD.
max_runtime_seconds MAA addition: the paid runtime. At 85% the agent is told to finish; at 100% the session stops with stop_reason.type = "runtime_limit_reached".
region MAA addition. Must match the agent and environment.

The response includes a residency record: where inference, the sandbox, storage and keys run for this session. See Residency and deletion.

Status

Status Meaning
running The agent is working
idle The agent has stopped and is waiting. stop_reason.type says why: end_turn (finished), requires_action (waiting for a tool approval or a custom tool result), or a budget or runtime limit
terminated The session has ended and cannot continue

Events you send

Event Use
user.message A new instruction or a reply
user.interrupt Stop the agent now
user.tool_confirmation Allow or deny a tool call that is waiting for approval
user.custom_tool_result The result of a custom tool you ran yourself
user.define_outcome Start rubric-graded work. See Outcomes
system.message An operator instruction mid-session
await client.beta.sessions.events.send(session.id, {
  events: [{ type: "user.message", content: [{ type: "text", text: "Focus on the UK market." }] }],
});

You can send while the session is running or idle; events are handled in order.

Events you receive

Event Meaning
agent.message, agent.thinking What the agent says and its reasoning summary
agent.tool_use, agent.tool_result A built-in tool call and its result
agent.mcp_tool_use, agent.mcp_tool_result An MCP tool call and its result
agent.custom_tool_use A call to one of your custom tools; answer with user.custom_tool_result
session.status_running, session.status_idle, session.status_terminated Status changes
session.usage Running totals: tokens, runtime, cost
session.error, session.updated Errors and configuration changes
session.thread_created, session.thread_idle A coordinator's threads
span.model_request_start / _end Each model call, with the provider and region used
span.outcome_evaluation_start / _end Grader runs for outcomes

Read events

Stream (live, server-sent events):

const stream = await client.beta.sessions.events.stream(session.id);
for await (const event of stream) {
  if (event.type === "session.status_idle") break;
}

Add event_deltas[]=agent.message to receive the agent's text as it is written.

List (the stored history, paged):

for await (const event of client.beta.sessions.events.list(session.id)) { /* … */ }

If a stream drops, reconnect, list the history and remove duplicates by event id. The log is the record; the stream is a view of it.

Interrupt

await client.beta.sessions.events.send(session.id, { events: [{ type: "user.interrupt" }] });

The agent stops and the session goes idle. Send a user.message to say what to do instead.

Delete

const deleted = await client.delete(`/v1/sessions/${session.id}`);
// deleted.certificate.id -> "cert_…"

Deleting removes the session's events, files, sandbox and threads, destroys its key and returns a signed certificate. Memory stores are kept; they are persistent by design. Archiving (POST …/archive) makes a session read-only without deleting it.

Endpoints

POST /v1/sessions · GET /v1/sessions · GET /v1/sessions/{id} · POST /v1/sessions/{id} · DELETE /v1/sessions/{id} · POST /v1/sessions/{id}/archive · GET /v1/sessions/{id}/events · POST /v1/sessions/{id}/events · GET /v1/sessions/{id}/events/stream · GET /v1/sessions/{id}/threads · /v1/sessions/{id}/resources