All Products
Search
Document Center

AgentCore:Session mechanisms and session isolation

Last Updated:Oct 21, 2026

AgentCore groups requests from the same conversation by session ID and manages these sessions according to instance capacity settings. A session ID only identifies which session a request belongs to; the application or managed Harness is responsible for conversation history and business state.

This topic primarily describes high-code agents and helps you design session IDs and history management for service calls. Differences for managed Harnesses and other agent types are explained in the relevant sections. Before you start, deploy a high-code agent by following Deploy and use a high-code agent. Configure the session ID method when you create the agent, because AgentCore identifies sessions by an HTTP header and the name of the header that carries the session ID is part of the agent configuration. For details, see Passing a session ID. Obtain the endpoint URL and the authentication method from the call instructions for the target endpoint; if API key authentication is used, configure the corresponding header and secret. Confirm that the instance capacity settings (Number of instances, Maximum Sessions per instance, and Session TTL) are in place for your agent. For details, see Sessions and instance capacity.

Sessions and session IDs

A session groups requests that belong to the same conversation or interaction. For example, an end user first submits "Analyze this report" and then asks "Summarize the conclusions in three points." The two requests can use the same session ID. When the end user starts a separate conversation, use a new session ID.

This topic distinguishes between two roles: the end user who interacts with the agent and the caller (business application) that integrates the agent. The caller generates and maintains session IDs. Throughout an integration, the caller completes five tasks. Configure the session ID method when you create the agent, as described in Passing a session ID. Generate a session ID for each conversation, reuse it within the conversation, and use a new value for a new conversation. Send the session header with every request and carry the session fields in the format of the selected protocol, as described in Request structure and session fields. Provide conversation history and business state in requests as required by your application, as described in Ownership of history and state. Validate routing, isolation, and recovery by using the methods in Integration validation. The session mechanism involves the following concepts:

ConceptQuestion answeredDescription and example
Session IDWhich session does this request belong to?For example, demo-session-01. Reuse it for the same conversation and replace it for a new conversation.
Runtime instanceWhich runtime environment processes the request?An instance can host multiple sessions based on its capacity settings.
Conversation history and business stateWhat context is required for this execution, and where are the results stored?Message lists, framework checkpoints, user files, and tool execution results.

Ownership of history and state

A session ID identifies a session; it is not the conversation history itself. Assigning two requests to the same session does not mean that the platform has stored the messages from the previous turn for the application. Whether history and business state are stored and can be restored depends on the application or managed Harness implementation:

  • Declaring a protocol in the AgentCore console does not implement the interface or store history automatically.

  • Using only AgentCoreServer does not automatically provide complete history persistence.

  • A session ID sent by the debugging panel does not prove that the server has stored or restored the history.

  • Using the same session ID in requests for two protocols does not mean that the application automatically converts or shares history across protocols. To continue a conversation across protocols, the application must manage history and state consistently.

Session isolation boundaries

Session isolation means that different sessions do not share history or state that should remain separate. This includes separate conversations of the same end user and conversations of different end users. The platform and caller jointly determine the isolation result, with different responsibilities on each side.

The platform provides session identification and scheduling boundaries. The session ID determines the session to which a request belongs. Routing association for the same session maintains execution continuity, but it does not guarantee permanent binding to the same process. An instance hosts multiple sessions according to Maximum Sessions per instance, and idle sessions are reclaimed based on Session TTL. For details, see Sessions and instance capacity.

The caller determines the actual isolation result. The business generates session IDs, reuses an ID for the same conversation, assigns a new ID to a new conversation, and does not share an ID across separate conversations. The application or framework implements storage and restoration of history and business state. After an instance restart, update, or session reclamation, the application must be able to restore state from persisted data.

For the division of responsibilities for history and state, see Ownership of history and state. For validation methods, see Integration validation.

Sessions and instance capacity

An agent can have multiple runtime instances, and an instance can host multiple sessions. A session ID is not an instance ID. Increasing the number of instances does not increase the number of session IDs carried in a request. The Session configuration item in the AgentCore console refers to the same concept as session in this topic. The following example uses fixed instances for a high-code agent:

ConfigurationMeaning
Number of instances: 2The target configuration contains two runtime instances.
Maximum Sessions per instance: 5Each instance is configured to host up to five active sessions.
Session TTL: 600 secondsA session is reclaimed after it remains inactive for the configured period. This value does not control the duration of a single model generation.

If both instances are ready and each hosts five sessions, the configured number of session slots is 2 × 5 = 10. This does not guarantee that 10 long-running requests can execute concurrently or that the actual throughput is 10 QPS. Model quotas, tool latency, memory usage, and instance health all affect the available capacity.

If some instances are not ready, the available capacity can be lower than the configured capacity. When the capacity limit is reached, use the actual error and runtime status, including instance readiness and the number of active sessions, to distinguish among session capacity, application concurrency, and downstream throttling. Increasing Session TTL alone cannot resolve all three issues. A longer TTL can cause idle sessions to occupy capacity for a longer period.

For other agent types that support auto scaling, distinguish between the current number of ready instances and the configured scaling limit. The fixed instance count for high-code agents does not apply to all agent types.

Passing a session ID

AgentCore currently identifies sessions by an HTTP header. When you create a high-code agent, you configure the session ID method, which includes the name of the header that carries the session ID. For example, if the application uses X-AgentCore-Session-ID as the session header:

X-AgentCore-Session-ID: demo-session-01

The request contains two different values:

  • X-AgentCore-Session-ID is the header name agreed upon by the agent configuration and the caller. After the agent is created, the caller sends requests with this header name. You can replace it with an existing business header. For an example, see Scenario 4 in Call examples.

  • demo-session-01 is the session ID. Reuse it for the same conversation and use a new value for a new conversation. It is not an agent name, instance ID, or API key.

    The caller generates the session ID. You can use an unpredictable ID generated by your business. Do not use personal information, such as an end user's mobile number, as the session ID.

Request structure and session fields

Components of a request

The session header, the AG-UI request body, and the Chat Completions request body occupy different parts of an HTTP request and are not mutually exclusive options. The session header is located in the request headers, and AG-UI and Chat Completions define the request body and response formats.

An HTTP request
├─ URL: Selects the protocol endpoint for this call
├─ Headers
│  ├─ Authentication header: Proves that the caller can access the endpoint
│  └─ Session header: Identifies the session to which the request belongs
└─ Body: Uses the format of the selected protocol
   ├─ AG-UI: threadId, runId, messages, and other fields
   └─ Chat Completions: model, messages, stream, and other fields

A request uses one protocol. Protocol capabilities must be implemented in code and declared in the AgentCore console. An agent can implement one or more protocols. If an agent implements and declares both protocols, you can call the agent through either endpoint, and the endpoints available for your agent depend on this implementation and declaration. Do not combine request bodies for the two protocols in one request. Before integration, review the call example for the target endpoint. In Call examples, Scenario 1 and Scenario 2 use the AG-UI endpoint, Scenario 3 uses the Chat Completions endpoint, and Scenario 4 shows how to use a custom session header name. The two protocols carry session data in different locations:

ProtocolWhere the session is carriedSession-related fields in the request body
AG-UISession headerthreadId (the same value as the session header) and runId (identifies the current run)
Chat CompletionsSession header; AgentCore console debugging requests also carry sessionId as a URL query parameterThe standard request body does not contain the threadId or runId session fields.

The sessionId query parameter in AgentCore console debugging requests for Chat Completions is an AgentCore integration convention, not a standard Chat Completions body field. If a business integration uses multiple locations to carry a session, use the same session value in each location.

Debugging panel behavior and recommendations for business calls

The following table describes how the debugging panel assembles each field and provides the corresponding recommendation for business calls. Required and optional fields and server-side processing rules are subject to the contract of the target endpoint and application.

Field and locationHow the debugging panel constructs the fieldRecommendation for business calls
Endpoint URL and authentication information (HTTP request / both protocols)Reads the endpoint URL. If API key authentication is used, obtains the API key and header name of the endpoint and adds them to the request.Obtain the URL and authentication method from the call instructions for the target endpoint. If API key authentication is used, configure the corresponding header and secret.
Session header name (HTTP header / both protocols)Resolves the request header name from the agent's session configuration.Use the header name in the agent configuration.
Session ID (HTTP header / both protocols)Generates and stores an ID when a session is created in the debugging panel. Subsequent requests use the current session ID.The caller generates and stores the ID. Use a new value for a new conversation and reuse the value for the same conversation.
threadId (body / AG-UI)Sets the field to the current session ID, which is the same value as the session header.As in the debugging panel, use the same value as the session header.
runId (body / AG-UI)Generates a new value each time a run request is constructed.Use a new value for each run.
Message id (body messages / AG-UI)Constructs the ID based on the current session ID and message sequence number.Specify an ID for each message in the request. Follow the contract of the integrated service for the ID format and reuse of historical message IDs.
Message list messages (body / both protocols)Includes the message history of the current debugging conversation and the end user's current input in the request.Provide the message list as required by the application interface. If the caller maintains history, include the relevant history in the request.
sessionId (URL query parameter / Chat Completions debugging request)Appends the current session ID, which is the same value as the session header.If the call example for the target endpoint contains this parameter, use the same session value as the session header.

Debugging requests for both AG-UI and Chat Completions contain messages. For information about whether the server stores or restores history, see Ownership of history and state.

Call examples

Scenario 1: Debug an AG-UI session in the console

After you create a session and enter a question in the debugging panel, the panel generates a session ID and constructs a request similar to the following one. The URL and IDs in this example are for illustration only.

POST /ag-ui/agent HTTP/1.1
Host: <agent-endpoint>
Content-Type: application/json
Accept: text/event-stream
X-AgentCore-Session-ID: demo-session-01
<authentication-header-name>: <actual-authentication-value>

{
  "threadId": "demo-session-01",
  "runId": "demo-run-01",
  "messages": [
    {"id": "demo-message-01", "role": "user", "content": "Introduce the topic of this report."}
  ],
  "state": {},
  "tools": [],
  "context": [],
  "forwardedProps": {}
}

The session ID appears in both the header and the body. Even when you select AG-UI, the session header is still required.

Scenario 2: Continue the same AG-UI session from a business application

The caller stores the session ID. The second call reuses demo-session-01 and uses a new demo-run-02 value for this run. If the service does not store history automatically, the caller must also include the messages from the previous turn. Replace the assistant content in the following example with the actual result from the previous turn.

POST /ag-ui/agent HTTP/1.1
Host: <agent-endpoint>
Content-Type: application/json
Accept: text/event-stream
X-AgentCore-Session-ID: demo-session-01
<authentication-header-name>: <actual-authentication-value>

{
  "threadId": "demo-session-01",
  "runId": "demo-run-02",
  "messages": [
    {"id": "demo-message-01", "role": "user", "content": "Introduce the topic of this report."},
    {"id": "demo-message-02", "role": "assistant", "content": "Replace this text with the actual result from the previous turn."},
    {"id": "demo-message-03", "role": "user", "content": "Summarize the conclusions in three points."}
  ],
  "state": {},
  "tools": [],
  "context": [],
  "forwardedProps": {}
}

When you start a new conversation, change both the session header value and threadId, and include only the messages needed for the new conversation. Changing only runId starts a new run; it does not start a new session.

Scenario 3: Call the Chat Completions endpoint from a business application

The following business call example uses the same session locations as AgentCore console debugging: the sessionId query parameter and the session header carry the same value. The body uses the Chat Completions format and does not contain the AG-UI threadId or runId fields. The sessionId query parameter is an AgentCore integration convention. Whether a business call must include it depends on the call example for the target endpoint. If the example contains this parameter, use the same value as the session header.

POST /openai/v1/chat/completions?sessionId=demo-session-02 HTTP/1.1
Host: <agent-endpoint>
Content-Type: application/json
X-AgentCore-Session-ID: demo-session-02
<authentication-header-name>: <actual-authentication-value>

{
  "model": "agentcore",
  "messages": [
    {"role": "user", "content": "Describe what you can do in one sentence."}
  ],
  "stream": false
}

Set the path and model based on the application implementation. The path in the example applies to the default AgentCoreServer endpoint. An existing HTTP service might use a different path. model is a request protocol field. Whether it affects downstream model selection depends on the application. To continue a conversation across protocols, the application must manage history and state consistently. For more information, see Ownership of history and state.

Scenario 4: Use a custom session header name in a business application

If you set the session header name to X-Business-Session when you create the agent, replace the session header in the preceding requests with:

X-Business-Session: demo-session-01

For AG-UI, threadId remains demo-session-01, and each run still uses a new runId. A custom header name does not change the field names in the protocol body or the relationship between sessions and instance capacity.

Differences between high-code agents and managed Harnesses

DimensionHigh-code agentManaged Harness
Who implements the agent execution logic?Application code, frameworks, and HTTP services.The selected Harness.
Protocol capabilitiesImplemented in code and declared in the console. One or more protocols can be implemented.Subject to the protocols actually provided by the selected Harness and endpoint. Do not assume that all protocol options for high-code agents are available.
Who populates session fields during console debugging?The debugging panel assembles the request based on the session configuration and selected protocol.The corresponding debugging entry point assembles the request according to the Harness integration contract.
Calls from a business applicationThe caller provides session fields according to the endpoint example.The caller also provides session fields according to the corresponding endpoint example. Using a Harness does not remove the caller's responsibility to distinguish conversations.
History storage, tool state, and restorationImplemented by the application or framework. For more information, see Ownership of history and state.Determined by the implementation, configuration, and storage capabilities of the Harness. Refer to the user guide for the selected Harness.

Both agent types must distinguish between which session a request belongs to and what state the session contains. History behavior is specific to each Harness implementation and is not a general capability of all high-code applications.

Integration validation

When you validate routing and isolation, use the instance and session information together with application logs.

Validation itemMethodPass criteria
Multiple requests in the same sessionReuse the session ID and use a new runId for each AG-UI run.History is included or restored according to the application contract.
Start a new session independentlyGenerate a new session ID and start a conversation.Neither the request nor the history read by the application contains messages from the previous conversation.
Concurrent access by multiple end usersStart multiple conversations for the same end user and conversations for different end users at the same time.The conversations do not share state that should remain isolated.
Custom headerChange the configured session header name and then make a call.The caller's actual field name and value match the configuration, and all call entry points have been updated.
Recovery after inactivity or restartObserve service behavior after session reclamation, an instance restart, or an application update.The business application can restore state from persistent storage.
Capacity validationCheck instance readiness, the number of active sessions, and the actual error.You can distinguish platform capacity limits from downstream service limits.
Note

The model might appear to remember the previous turn only because the request contains the history. Do not use the response content alone as proof that the platform has stored the history or that the session exclusively occupies an instance.