Background: Challenges of AgentCore Runtime and Session Start
Amazon Bedrock AgentCore Runtime provides a fully managed serverless environment for agent workloads. Each session runs in an isolated microVM, scaling down to zero when idle and charging only for the actual resources consumed. In the existing V1 architecture, every time a session started, it had to pull the container image from Amazon ECR, start the container, and only then could it process the first request. In this process, image pulling time acted as the dominant factor of cold start, leading to structural limitations where start delays increased in proportion to image size.
"AgentCore Runtime runs each session in a new microVM. In V1, AgentCore pulls the user's container image from Amazon ECR, starts the container, and only then can it process the first request. Since image pulling is dominant, cold starts increase in proportion to image size."
V2 Architecture: Snapshot-Based Session Restoration Mechanism
V2 (platformVersion "V2") fundamentally changes this paradigm. At the time of runtime creation or update, the container is started once, and after receiving the first healthy ping (GET /ping, must arrive within 120 seconds), the operating system file cache is cleared, and the microVM is frozen to save the memory and disk state as a snapshot. When a new session request comes in, this snapshot is restored to a new microVM, resuming the process exactly from the frozen point. Imported libraries, created objects, client connections, etc., are all preserved in memory.
In this process, it takes several minutes to complete runtime creation or update, but this is transitioned to a one-time build cost rather than a recurring cost per session. V2 also recovers unused memory from sessions to ensure that billing aligns with actual usage.
| Step | V1 (Existing) | V2 (Snapshot-Based) |
|---|---|---|
| Image Pulling | Performed every session | Performed once at build |
| Container Start | Performed every session | Performed once at build |
| Initialization Code Execution | Performed every session | Performed once at build (before app.run()) |
| Session Start Delay | Proportional to image size | Fixed to snapshot restoration time |
| Memory Billing | Based on total allocated memory | Billed after recovery based on actual usage |
Memory and File System: What Snapshots Preserve and What They Don’t
During snapshot restoration, the memory state is fully restored. Everything the process held at the snapshot point, as well as the contents of RAM-backed file systems like `/dev/shm`, is available at memory speed from the first access. In contrast, file read states are not transferred. Since the file cache is cleared before freezing, even if files are read during initialization, they cannot be accessed quickly in the restored session. Container image files are fetched in blocks from snapshot storage and cached near the host at the first read point.
This characteristic affects different agent types differently. Agents that can maintain everything they need within their own process will see maximum benefits, but CLI tools or browser binaries that run as separate processes and terminate will need to read from the image again upon restoration after reading during initialization.
Measurement Strategy: CloudWatch Metrics and Latency Breakdown
AgentCore Runtime provides two CloudWatch metrics under the `AWS/Bedrock-AgentCore` namespace.
- Latency: Time to first byte (total)
- OverheadLatency: Platform attributable portion (microVM startup, snapshot restoration, etc.)
Initialization time does not appear in these metrics. This is because, in V2, it is only reflected in the time taken to reach the READY state during build when executed once. The initialization duration should be logged once just before `app.run()` to be checked in the build logs.
| OverheadLatency | 45 |
| Handler_Execution | 35 |
| Model_Call | 15 |
| Streaming_Buffer | 5 |
*The above chart is an illustrative ratio; actual distribution may vary based on the new session ratio.*
Points to note during measurement include:
- Use percentiles instead of averages: P90, P99, or TM90 (top 90% average, removing slow tails) recommended
- Fix new session ratio: OverheadLatency includes session requests during execution, so test under conditions similar to expected new session ratios in production
- Parallel client-side measurement: Measure invoke call time on the client to include network time, subtracting handler execution time returned
- Consider streaming buffer: The first event may be delayed until several hundred bytes are buffered
Optimization Pattern: Moving Initialization Tasks to Snapshot Time
Common cold start advice is "deferred imports and minimal initialization," but in V2, the opposite strategy is effective. Initialization is executed once at build time, and tasks deferred to the handler incur repeated costs for every new session. This applies to static tasks (imports, client creation, loading data into images). Dynamic data cannot be snapshotted.
The agents that see the greatest benefit are those that read large files from images at request time.
- Small local model weights
- Embedding vectors
- Datasets
- Large libraries
- Browser binaries for automation
- CLI toolchains executed as subprocesses by coding agents
- Tasks that read numerous small files like TypeScript compilation
Utilizing AgentCore Observability (custom span support), measure tool setup, file loading, and deferred import intervals to identify residual initialization tasks within the handler and move them before `app.run()`.
Build Hooks and Exception Handling: Responding to Separate Process Tools
For cases where it is not possible to maintain all state within a single process (separate process CLI, browser binaries, etc.), the AgentCore Runtime supports build hooks. Hooks run during the build phase to prepare artifacts that will be included in the snapshot. As shown in Figure 3, hooks are executed after container startup and before the healthy ping during the build process, allowing the binary or cache of separate process tools to be preloaded into snapshot memory/disk.
---