

# 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](claude-managed-agents-bedrock-first-agent.md).

## Session status
<a name="claude-managed-agents-bedrock-sessions-session-status"></a>


| status | What it means | 
| --- | --- | 
| `idle` | Waiting for input. That includes waiting for you to allow a tool call or to return a custom tool's result. | 
| `running` | A turn is in progress. The session also stays `running` while your tool runner runs a built-in tool call. | 
| `terminated` | 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 | 
| --- | --- | 
| `end_turn` | The agent finished and waits for the next message. | 
| `requires_action` | The agent called tools that need an answer from you. `stop_reason.event_ids` lists the tool call events. | 
| `retries_exhausted` | 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](claude-managed-agents-bedrock-s3-folders-and-files.md#claude-managed-agents-bedrock-s3-folders-and-files-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:

```json
{
  "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
<a name="claude-managed-agents-bedrock-sessions-create-a-session"></a>

```http
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 | 
| --- | --- | --- | 
| `agent` | Yes | An agent ID, which uses the agent's latest version. To pin a version, send `{"type": "agent", "id": "agent_...", "version": 2}`. | 
| `environment_id` | Yes | Where the tools run: an AgentCore Runtime ARN, one of its endpoint ARNs, or your project's self-hosted ID. | 
| `working_directory` | No | Where the tools start. The default is `/mnt/workspace`. | 
| `title`, `metadata` | No | A title of up to 500 characters, and up to 16 string pairs. | 
| `resources` | 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](claude-managed-agents-bedrock-tools.md) and [Use S3 folders and files](claude-managed-agents-bedrock-s3-folders-and-files.md). | 
| `initial_events` | No | Up to 50 `user.message` events to send as the session's first input, so you need no separate send. | 

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:

```http
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](claude-managed-agents-bedrock-security.md#claude-managed-agents-bedrock-security-the-session-role), in [Security and IAM roles](claude-managed-agents-bedrock-security.md). 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](claude-managed-agents-bedrock-security.md#claude-managed-agents-bedrock-security-limit-session-overrides) in [Security and IAM roles](claude-managed-agents-bedrock-security.md).

**Important**  
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
<a name="claude-managed-agents-bedrock-sessions-send-events"></a>

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 | 
| --- | --- | 
| `user.message` | To start a turn. `content` is a list of blocks: `text`, `image` (base64), and `document` (base64 PDF or plain text). A request body can be at most 2 MiB, which limits the size of images and documents. | 
| `user.interrupt` | To stop the current turn. | 
| `user.tool_confirmation` | To allow or deny a tool call that waits for permission. | 
| `user.custom_tool_result` | To return the result of a custom tool the agent called. | 

A message:

```json
{ "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
<a name="claude-managed-agents-bedrock-sessions-interrupt-a-turn"></a>

```json
{ "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 name="claude-managed-agents-bedrock-sessions-allow-or-deny-a-tool-call"></a>

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:

```json
{ "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](claude-managed-agents-bedrock-tools.md#claude-managed-agents-bedrock-tools-permission-policies) shows how to set a tool's policy.

### Return a custom tool's result
<a name="claude-managed-agents-bedrock-sessions-return-a-custom-tool-s-result"></a>

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:

```json
{
  "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
<a name="claude-managed-agents-bedrock-sessions-stream-events"></a>

`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
<a name="claude-managed-agents-bedrock-sessions-list-events"></a>

`GET /sessions/{id}/events` returns the session's events, oldest first.


| Query parameter | Description | 
| --- | --- | 
| `limit` | Events per page, 1 to 1,000. The default is 1,000. | 
| `order` | `asc`, the default, or `desc`. | 
| `page` | The `next_page` value from the previous page. The last page has no `next_page`. A page token expires after 24 hours; after that, start again from the first page. | 
| `types[]` | Only events of this type. | 
| `created_at[gt]`, `[gte]`, `[lt]`, `[lte]` | Only events in a time range, as RFC 3339 times. | 

[Event types](claude-managed-agents-bedrock-reference.md#claude-managed-agents-bedrock-reference-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
<a name="claude-managed-agents-bedrock-sessions-update-archive-and-delete"></a>


| Request | What it does | 
| --- | --- | 
| `POST /sessions/{id}` | Changes `title`, `metadata`, or this session's copy of its tools or MCP servers through `agent`, for example `{"agent": {"tools": [...]}}`. An IAM update needs permission on the session and on the agent it came from, and `agent_id` is not accepted. The stored agent does not change. Tools and MCP servers cannot change while the session is running. An `agent` that is left out, null, or empty changes nothing. | 
| `POST /sessions/{id}/archive` | Ends the session and keeps its events, which you can still read. Only an idle session can be archived. | 
| `DELETE /sessions/{id}` | Deletes the session and its events, and stops its container on AgentCore. A running session cannot be deleted. Interrupt it first. | 
| `GET /sessions` | Lists your sessions. Filter with `agent_id`, or `created_by_me=true` for the ones your role created. Page with `page`, set to the previous page's `next_page`. | 

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
<a name="claude-managed-agents-bedrock-sessions-retries"></a>
+ An error with `x-should-retry: true` changed nothing. Retry it after `retry-after-ms`, or with backoff if it has none. `x-should-retry: false` means don't retry it as it is.
+ A 503, a 529, and a 500 with the message `overloaded, shedding load` changed nothing. Retry them with backoff.
+ Do not retry a 500 from `POST /sessions/{id}/events` on 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.