# How to Optimize and Monitor AWS Costs with the Agent Toolkit for AWS

> Optimize and monitor AWS costs using the Agent Toolkit for AWS. Learn to select cheaper models, manage memory, sample evaluations, stop idle sessions, and set up CloudWatch dashboards for effective cost control.

- Repository: [Amazon Web Services/agent-toolkit-for-aws](https://github.com/aws/agent-toolkit-for-aws)
- Tags: how-to-guide
- Published: 2026-06-26

---

**You can optimize and monitor AWS costs with the Agent Toolkit for AWS by selecting cheaper Bedrock models, configuring memory strategies, sampling evaluations at low rates, stopping idle runtime sessions explicitly, and setting up CloudWatch dashboards to track invocation counts and latency metrics.**

The **Agent Toolkit for AWS (ATFA)** enables you to build **AgentCore** agents that run on AWS Bedrock, where costs accumulate across compute, memory, API calls, and observability. Understanding the specific cost components and applying the optimization levers documented in the source code allows you to keep agent operations predictable and cost-efficient. This guide covers the practical strategies defined in the `agents-optimize` skill references.

## Understand AgentCore Cost Components

AgentCore cost is distributed across multiple operational layers. According to [`plugins/aws-agents/skills/agents-optimize/references/cost.md`](https://github.com/aws/agent-toolkit-for-aws/blob/main/plugins/aws-agents/skills/agents-optimize/references/cost.md), you incur charges for the following components:

- **Runtime compute** : You pay for vCPU-hours and GB-hours based on active session time, including idle periods. The default `idleRuntimeSessionTimeout` is 15 minutes.
- **Memory events** : Charges apply per new memory record written. `SEMANTIC` memory is significantly more expensive than `SUMMARIZATION`.
- **Memory storage** : Long-term retention of memory records (default expiry is 30 days) incurs monthly storage fees.
- **Memory retrieval** : Each read operation querying stored memories generates costs based on the number of records retrieved.
- **Gateway tool calls** : Every tool invocation routed through the Bedrock gateway is metered individually.
- **Evaluator model calls** : LLM-as-judge evaluations run during online testing consume tokens on each execution.
- **Bedrock model usage** : Input and output tokens for the underlying foundation models (e.g., Claude, Nova) represent the largest variable cost.
- **Policy authorization** : Each authorization request processes input tokens through the policy engine.
- **Identity token requests** : API-key fetches for external services generate per-request charges.
- **CloudWatch logs and traces** : Log ingestion and storage costs scale with verbosity and retention settings.
- **ECR image storage** : Container builds store images in Amazon ECR, while CodeZip builds incur no storage charge.

Because pricing changes frequently, validate current rates against the AgentCore pricing page and the reference documentation before implementing optimizations.

## Reduce Costs with Model Selection

Selecting the cheapest model that meets your quality requirements delivers the highest immediate savings. The cost difference between model tiers can be 10-30x according to the cost reference.

| Tier | Example Models | Use Case |
|------|---------------|----------|
| **Cheapest** | `amazon.nova-micro-v1:0`, `claude-3-5-haiku-*`, Gemini Flash | Simple classification, extraction, short replies |
| **Mid-tier** | `amazon.nova-lite-v1:0`, Gemini 2.5 Flash | General-purpose agents with light reasoning |
| **Premium** | `anthropic.claude-sonnet-4-5-*`, GPT-5, Gemini 2.5 Pro | Complex multi-step planning or code generation |

Configure your agent to use a cost-efficient model at creation:

```bash
agentcore create my-agent --model "anthropic.claude-3-haiku-20240307"

```

## Optimize Memory and Session Configuration

Memory strategies and session lifecycle management directly impact compute and storage charges.

### Tune Memory Strategies

`SEMANTIC` memory enables vector similarity search but is the most expensive option. For cost-sensitive workloads, enable only the strategies you need:

```text
agentcore create --memory-strategies SUMMARIZATION

```

You can further reduce costs by increasing the `relevance_score` threshold to return fewer records per query, limiting `top_k` in retrieval calls, and setting appropriate expiry periods (e.g., `--expiry 7d` instead of the default 30 days) to purge old records automatically.

### Manage Runtime Sessions

Idle sessions continue consuming vCPU-hours. Stop sessions explicitly when workflows complete:

```text
agentcore stop-runtime-session --runtime <AGENT_NAME>

```

Lowering the `idleRuntimeSessionTimeout` below the default 15 minutes or selecting smaller instance types also reduces baseline compute costs.

### Sample Evaluations

Running evaluations at 100% sampling quickly dominates your bill. Run online evals at low sampling rates:

```text
agentcore eval start --sampling 2

```

This executes evaluations on only 2% of invocations while maintaining statistical significance. Use cheaper evaluator models (e.g., Haiku) even when your main agent requires a larger model.

## Monitor Spend with CloudWatch

The Agent Toolkit ships with built-in observability feeding metrics into **CloudWatch** and traces into **X-Ray**, documented in [`plugins/aws-agents/skills/agents-optimize/references/observability.md`](https://github.com/aws/agent-toolkit-for-aws/blob/main/plugins/aws-agents/skills/agents-optimize/references/observability.md).

### Build a Cost-Focused Dashboard

After deployment, the `AWS/BedrockAgentCore` namespace exposes metrics critical for cost monitoring:

- **Invocation count** : Tracks request volume affecting total compute
- **Error rate** : High errors indicate wasted spend on failed operations
- **P50/P90/P99 latency** : Longer durations correlate with higher runtime costs
- **CPU and memory utilization** : Identifies over-provisioned instances

Create a CloudWatch dashboard with these widgets to visualize cost drivers in real time.

### Inspect Logs and Traces

Stream recent logs filtered to errors to identify expensive failures:

```bash
agentcore logs --runtime MyAgent --level error --since 1h

```

List recent traces approximately 10 seconds after invocation:

```bash
agentcore traces list --runtime MyAgent --since 1h --limit 10

```

Ensure **CloudWatch Transaction Search** is enabled for trace visibility. Set log retention policies to prevent indefinite storage growth:

```bash
aws logs put-retention-policy \
  --log-group-name /aws/bedrock-agentcore/runtimes/<AGENT_ID>-DEFAULT \
  --retention-in-days 30

```

### Aggregate Across Accounts

For multi-account setups (dev, staging, prod), enable CloudWatch cross-account observability:

1. Designate a monitoring account in the CloudWatch console
2. Link source accounts via AWS Organizations
3. Deploy agents normally; telemetry flows automatically without additional IAM configuration

## Optimize Build and Artifact Storage

Avoid container storage charges when possible. If you do not need custom containers, use CodeZip builds:

```text
agentcore deploy my-agent --codezip

```

When containers are required, keep images lean and prune old ECR tags regularly to minimize storage costs.

## Complete Optimization Workflow

The following script demonstrates applying multiple cost-reduction levers simultaneously:

```bash

# 1. Select a cheap model for simple classification

AGENT_MODEL="anthropic.claude-3-haiku-20240307"

# 2. Create agent with summarization-only memory

agentcore create my-classifier \
  --model $AGENT_MODEL \
  --memory-strategies SUMMARIZATION

# 3. Deploy using CodeZip to avoid ECR charges

agentcore deploy my-classifier --codezip

# 4. Set 30-day log retention

aws logs put-retention-policy \
  --log-group-name /aws/bedrock-agentcore/runtimes/my-classifier-DEFAULT \
  --retention-in-days 30

# 5. Run test invocations

agentcore run my-classifier "Classify the sentiment of: 'Great product!'"

# 6. Stop runtime session to prevent idle charges

agentcore stop-runtime-session --runtime my-classifier

# 7. Monitor via CloudWatch dashboard (add InvocationCount, ErrorRate, AvgDuration widgets)

```

This workflow implements model selection, memory strategy reduction, avoidance of container storage, log retention control, and explicit session termination.

## Summary

- **Choose the cheapest viable model** : Haiku or Nova Micro can reduce token costs by 10-30x compared to Sonnet or Opus models
- **Stop idle sessions explicitly** : Use `agentcore stop-runtime-session` to eliminate vCPU-hour charges when work completes
- **Optimize memory strategies** : Prefer `SUMMARIZATION` over `SEMANTIC` memory and adjust `top_k` and relevance thresholds to reduce retrieval costs
- **Sample evaluations** : Run online evals at 1-5% sampling rates to minimize evaluator model charges
- **Configure observability limits** : Set CloudWatch log retention to 30 days and use CodeZip builds to avoid ECR storage fees
- **Monitor continuously** : Build dashboards using the `AWS/BedrockAgentCore` namespace to track invocation volume, latency percentiles, and error rates that correlate with cost

## Frequently Asked Questions

### What is the most expensive component of an AgentCore agent?

Bedrock model usage (input and output tokens) typically represents the largest cost driver, followed by runtime compute for idle sessions. According to the cost reference in [`plugins/aws-agents/skills/agents-optimize/references/cost.md`](https://github.com/aws/agent-toolkit-for-aws/blob/main/plugins/aws-agents/skills/agents-optimize/references/cost.md), semantic memory operations and evaluations at full sampling rates can also dominate bills if left unoptimized.

### How do I stop idle session charges immediately?

Execute `agentcore stop-runtime-session --runtime <AGENT_NAME>` when your workflow completes. Idle sessions continue accruing vCPU-hours and GB-hours until they time out (default 15 minutes) or are stopped explicitly.

### Which memory strategy costs the least?

`SUMMARIZATION` is significantly cheaper than `SEMANTIC` memory. Create agents with `--memory-strategies SUMMARIZATION` to avoid vector similarity search costs unless your use case specifically requires semantic retrieval.

### How do I view AgentCore traces for cost debugging?

Use `agentcore traces list --runtime <AGENT_NAME> --since 1h --limit 10` to inspect recent execution traces. Ensure CloudWatch Transaction Search is enabled in your account, as traces appear approximately 10 seconds after invocation and help identify latency spikes that increase compute costs.