Hosting and Invoking AI Agents with Amazon Bedrock AgentCore
This lesson explains the services of Amazon Bedrock AgentCore and how an application invokes an agent hosted on AgentCore Runtime, with isolated sessions, memory, tools and identities.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the purpose of each main AgentCore service.
- Explain how runtime sessions are created, reused and isolated.
- Explain the developer's responsibilities for session IDs.
- Choose between Agents for Amazon Bedrock, AgentCore Runtime and Lambda for an agent workload.
What AgentCore provides
An AI agent is a program that uses a model to decide which steps to take and which tools to call to reach a goal. Building the agent logic is only part of the work: it must also run securely and at scale, remember context, reach tools with the right credentials and be monitored. AgentCore supplies these capabilities as modular services that work with any agent framework and any model, inside or outside Bedrock. The following table summarises the services a developer is most likely to meet.
| Service | What it does |
|---|---|
| Runtime | Hosts agents and tools serverlessly, running each session in its own microVM |
| Memory | Stores short-term conversation history and long-term facts and preferences across sessions |
| Gateway | Turns APIs and Lambda functions into Model Context Protocol (MCP) tools behind one secure endpoint |
| Identity | Authenticates callers and gives agents workload identities and stored OAuth tokens or API keys for tools |
| Policy | Enforces deterministic rules, compatible with Cedar, on every tool call through Gateway |
| Observability | Traces each step of an agent run with OpenTelemetry data in Amazon CloudWatch |
| Code Interpreter and Browser | Sandboxed tools for running code and using websites |
| Evaluations | Scores agent quality, such as task completion and tool use, before and after release |
AgentCore services
AgentCore Runtime and sessions
AgentCore Runtime runs an agent packaged as a container image or as code. Creating an agent runtime gives it an ARN, an execution role that sets what the agent can call, and versions with endpoints for controlled releases. The agent listens for requests over HTTP, or over the MCP or Agent2Agent (A2A) protocols when it serves as a tool or as another agent's peer.
Applications call InvokeAgentRuntime with the runtime ARN, a payload and a runtimeSessionId. The first request with a new session ID creates a session in a dedicated microVM with its own CPU, memory and file system; later requests with the same ID reach the same microVM and its context. A session is stopped after 15 minutes of inactivity by default or after a maximum lifetime of up to 8 hours, and the microVM is then terminated and its memory sanitised. Data that must outlive the session belongs in AgentCore Memory or another data store.
The session ID is the developer's responsibility. It must be unique for each user or conversation and at least 33 characters long, for example a UUID, and the application keeps the mapping between users and sessions, because AgentCore does not enforce it. Reusing one session ID for different users would mix their context.
The following diagram shows how session IDs map requests to isolated microVMs.

Runtime sessions
Memory, Gateway and Identity
AgentCore Memory separates short-term memory, the events of the current conversation, from long-term memory, which extracts facts, summaries and user preferences and makes them available in later sessions. Memory is organised by actor and session identifiers, so the application controls whose memory each agent run can read.
AgentCore Gateway exposes existing Lambda functions, OpenAPI-described APIs and other MCP servers as tools that any MCP-capable agent can discover and call. AgentCore Identity handles authentication in both directions: inbound, it checks that the caller of an agent or gateway presents valid IAM credentials or a JSON Web Token from an identity provider such as Amazon Cognito; outbound, it stores OAuth tokens and API keys in a token vault and supplies them when the agent calls a tool for a user who has given consent. How these services secure tool calls is covered in the lesson on securing AI agent interactions in the next module.
Choosing where to run an agent
Agents can run in several places on AWS. The deciding factors are how much the team wants to configure rather than code, which framework it uses and how long each session lasts. The following comparison summarises the main options.
Where should the agent run?
A support agent
A company builds a customer support agent with an open-source framework. Conversations can last an hour, customers must never see each other's data, and the agent must call the order API as the signed-in customer.
The developer deploys the agent to AgentCore Runtime with inbound JWT authentication from the company's Cognito user pool. The web backend creates a UUID-based runtimeSessionId for each conversation, stores it against the customer's ID and passes it on every InvokeAgentRuntime call.
The order API is registered as a tool in AgentCore Gateway, and AgentCore Identity supplies the customer's OAuth token for each call, so the API's own authorisation limits each customer to their orders. AgentCore Memory stores preferences such as the customer's language for later conversations, and AgentCore Observability traces each tool call for debugging.
Why must an application never reuse one runtimeSessionId for different users?
Show answer
Requests with the same session ID reach the same microVM and its context, so a second user would see the first user's conversation state. AgentCore does not map sessions to users; the application must.
Exam Tips
Remember for the exam
- Host a custom agent with per-session isolation and sessions of up to 8 hours: AgentCore Runtime.
- Generate a unique runtimeSessionId (at least 33 characters) per user conversation.
- Expose existing Lambda functions and APIs to agents as MCP tools: AgentCore Gateway.
- Agent calls an API as the signed-in user: AgentCore Identity outbound OAuth.
- Context that must outlive a session: AgentCore Memory.