Work with Claude Managed Agents sessions, events, and results
In Claude Managed Agents for Amazon Bedrock, a session is one conversation with one agent. It keeps the conversation across messages, so use one session for a related sequence of tasks, and delete it when you no longer need it. The examples here use the cma shell function from Run your first agent.
Session status
status | What it means |
|---|---|
| Waiting for input. That includes waiting for you to allow a tool call or to return a custom tool's result. |
| A turn is in progress. The session also stays |
| Ended, by an archive or by a failure. A terminated session takes no more events. |
The reason a turn stopped is on the session.status_idle event, in stop_reason, not on the session:
stop_reason.type | What it means |
|---|---|
| The agent finished and waits for the next message. |
| The agent called tools that need an answer from you. |
| A model request failed and will not be retried on its own, or the session's container could not put its S3 folders and files in place (see Errors in Use S3 folders and files). The session still works, and the next event you send tries again. |
When the model refuses to answer, the turn still ends with end_turn. The refusal is in the same event's stop_details, which is null on every other turn:
{ "type": "session.status_idle", "stop_reason": { "type": "end_turn" }, "stop_details": { "type": "refusal", "category": "cyber", "explanation": "..." } }
category names the policy area, such as cyber or bio, and can be null. No tool call in a refused reply runs. The session stays usable, but the refused turn stays in the conversation, so a message on the same subject can be refused again. A subagent's refusal is on that thread's session.thread_status_idle.
An idle session is not proof that the task worked. Check stop_details, then read the tool results and the agent's last message. A failure that ends a session arrives as a session.error event and then session.status_terminated.
Create a session
POST /sessions { "agent": "agent_...", "environment_id": "arn:aws:bedrock-agentcore:us-west-2:111122223333:runtime/cma_tool_runner-...", "title": "Investigate the failing build", "metadata": { "ticket": "1234" } }
Field | Required | Description |
|---|---|---|
| Yes | An agent ID, which uses the agent's latest version. To pin a version, send |
| Yes | Where the tools run: an AgentCore Runtime ARN, one of its endpoint ARNs, or your project's self-hosted ID. |
| No | Where the tools start. The default is |
| No | A title of up to 500 characters, and up to 16 string pairs. |
| No | Memory stores with read-only or read-write access, folders in your tool runner to tell the agent about, and S3 folders and files to mount or copy in. See Add tools and skills and Use S3 folders and files. |
| No | Up to 50 |
To create a session, an IAM caller needs bedrock:CreateAnthropicSession on the AgentCore Runtime ARN. That is also true when environment_id names one of the runtime's endpoints: the service checks the permission on the parent runtime, and still runs the session on the endpoint you named. A self-hosted session needs the permission on its project's self-hosted ARN.
The session starts with the agent's configuration. When you create a session, agent can be an agent_with_overrides object with the agent's id and, optionally, version, model, system, skills, tools, and mcp_servers. Overrides change only the session's copy, not the stored agent. Each AgentCore Gateway an mcp_servers override names, and each S3 folder of an s3_mount skill override, needs bedrock:CreateAnthropicSession on its ARN, as it does when an agent names it. Tool definitions need no permission. A model override also needs bedrock:CreateAnthropicSession on its inference profile, arn:aws:bedrock:<region>:<account>:inference-profile/<model id>, and that check sees the agent's tags. A model the session inherits from the agent needs no such permission.
By default, the session runs as the agent's role. To run it as another role in your account, name that role in execution_identity or in the x-amz-role-arn header when you create the session. Naming a role, even the agent's own, needs iam:PassRole on it, with the new session's ARN as the associated resource. A session that inherits the agent's role needs no PassRole. If the agent has no role, the create must name a role you may pass. An empty x-amz-role-arn header counts as no header. An empty or malformed role in the body is a 400, and so is a body that names the role twice. You cannot name a role when you update a session.
The service assumes the selected role once while it creates the session, so a role it cannot assume fails the create with 400 and nothing is made. The role cannot be changed afterward.
For example, this request changes one session's role, system prompt, and model, and attaches two memory stores. The stored agent must have the memory toolset turned on:
POST /sessions { "agent": { "type": "agent_with_overrides", "id": "agent_EXISTING", "model": "us.anthropic.claude-sonnet-5-5", "system": "Read the reference store and record your work in the journal store." }, "execution_identity": {"type": "aws_role", "role_arn": "arn:aws:iam::111122223333:role/CmaSessionOverrideRole"}, "environment_id": "arn:aws:bedrock-agentcore:us-west-2:111122223333:runtime/cma_tool_runner-EXAMPLE", "resources": [ {"type": "memory_store", "memory_store_id": "memstore_REFERENCE", "access": "read_only"}, {"type": "memory_store", "memory_store_id": "memstore_JOURNAL", "access": "read_write"} ] }
The selected role needs permission to invoke the overridden model and this environment's runtime. It also needs the ManagedAgentsExecutionRole tag and the trust policy in The session role, in Security and IAM roles. The caller needs bedrock:CreateAnthropicSession on the new session, the originating agent, the runtime, both memory stores, and the overridden model's inference profile, and iam:PassRole on the selected role. The stored agent's model, system prompt, and role do not change.
To update a session, send only the fields you change, for example POST /sessions/{id} with {"title": "New title"}. An IAM update needs bedrock:UpdateAnthropicSession on both the session and the agent it came from. The optional agent object replaces the session's copy of its tools or MCP servers, and null or empty lists clear them. It cannot select another agent, and agent_id is not accepted: the agent comes from the stored session. An update that sets mcp_servers needs bedrock:UpdateAnthropicSession on each gateway it names. An update cannot change skills. Admins can limit tool and MCP server changes with the same condition keys they use for session creates. See Limit session overrides in Security and IAM roles.
Creating a session is not idempotent. Each request makes a new session. If a create's answer is lost, list your sessions before you send it again. The same holds for creating an agent.
Send events
Send events with POST /sessions/{id}/events. The response lists the stored events with their IDs. It returns as soon as they are stored, not when the turn ends.
Event | When to send it |
|---|---|
| To start a turn. |
| To stop the current turn. |
| To allow or deny a tool call that waits for permission. |
| To return the result of a custom tool the agent called. |
A message:
{ "events": [{ "type": "user.message", "content": [{ "type": "text", "text": "Summarize the files in the workspace." }] }] }
A message sent while a turn is running is queued, and the agent reads it at its next step. While the session waits on a tool call, it accepts only the answer to that call, or user.interrupt.
Interrupt a turn
{ "events": [{ "type": "user.interrupt" }] }
An interrupt does not undo what tools already did. Wait for session.status_idle before you start more work. If a tool wrote to another system, check that system yourself.
Allow or deny a tool call
A tool whose permission policy is always_ask pauses the session before it runs. The session goes idle with requires_action, and stop_reason.event_ids names the agent.tool_use, agent.mcp_tool_use, or agent.custom_tool_use event. Answer it:
{ "events": [{ "type": "user.tool_confirmation", "tool_use_id": "sevt_...", "result": "allow" }] }
To refuse, send "result": "deny", and optionally a deny_message the agent sees. Send one confirmation per request. Permission policies shows how to set a tool's policy.
Return a custom tool's result
When the agent calls a custom tool, the session emits agent.custom_tool_use and goes idle with requires_action. Run the tool in your application and send its result:
{ "events": [{ "type": "user.custom_tool_result", "custom_tool_use_id": "sevt_...", "content": [{ "type": "text", "text": "Paris" }] }] }
Set "is_error": true when the tool failed, with content that says why.
Stream events
GET /sessions/{id}/events/stream keeps the connection open and sends each event as it happens, as server-sent events. Open it before you send a message, so you see the whole turn.
: connected event: message data: {"id":"sevt_...","processed_at":"2026-10-22T17:02:11.06Z","type":"session.status_running"} :keepalive
Each event: message block has one JSON event in its data line. Lines that begin with : are comments. Ignore them, as SSE clients do. A quiet stream gets a comment every 15 seconds, so idle timeouts on the way do not close it. The stream sends each event whole. To also see an agent's text as the model writes it, open the stream with event_deltas[]=agent.message. The stream then sends event_start and event_delta frames before the finished event, which still carries the whole text. These frames are best effort: some can be dropped, and they are never stored or listed. event_deltas[]=agent.thinking sends only the event_start frame, never the thinking text.
The service closes a stream that has carried no event for 10 minutes, even while a turn runs. Keepalive comments and partial text don't count as events. If the stream drops or is closed, the session goes on. List the events to see what happened while you were away, and reconnect.
List events
GET /sessions/{id}/events returns the session's events, oldest first.
Query parameter | Description |
|---|---|
| Events per page, 1 to 1,000. The default is 1,000. |
|
|
| The |
| Only events of this type. |
| Only events in a time range, as RFC 3339 times. |
Event types lists the events you will use most.
Expect event types you don't use, and skip them. A session's total token usage is also in the session's usage field.
Update, archive, and delete
Request | What it does |
|---|---|
| Changes |
| Ends the session and keeps its events, which you can still read. Only an idle session can be archived. |
| Deletes the session and its events, and stops its container on AgentCore. A running session cannot be deleted. Interrupt it first. |
| Lists your sessions. Filter with |
Deleting a session does not delete files the agent wrote outside the service, such as to an S3 bucket, a repository, or your own machine. It does not delete your AgentCore Runtime either.
Retries
An error with
x-should-retry: truechanged nothing. Retry it afterretry-after-ms, or with backoff if it has none.x-should-retry: falsemeans don't retry it as it is.A 503, a 529, and a 500 with the message
overloaded, shedding loadchanged nothing. Retry them with backoff.Do not retry a 500 from
POST /sessions/{id}/eventson its own. The events may already be stored, so list the session's events first.Do not retry a create whose answer you lost until you have listed what exists. A retry makes a second agent or session.
The Anthropic SDK retries 5xx, 408, 409, and 429 responses, and dropped connections, by itself. Turn its retries off for creates and sends, or check before you resend.