View a markdown version of this page

Claude Managed Agents examples - Amazon Bedrock

Claude Managed Agents examples

The examples are in claude-managed-agents-examples.zip. Each one has its own README and clean-up steps, and most have a CloudFormation template. memory and evaluation have none. Run them in a development account: they create IAM roles, AgentCore Runtimes, and data stores, and some create billable networking.

Example

What it shows

Guide topic

scheduled-agent

Running an agent on a schedule with Amazon EventBridge Scheduler and AWS Lambda.

Work with sessions

github-repo-agent

An agent that changes private GitHub repositories and opens pull requests, with one-hour tokens from your own GitHub App.

Protect the tool runner

invoice-reconciliation

An accounts payable agent that matches a month of invoices in Amazon S3 to purchase orders in Amazon DynamoDB, and approves or flags each one through custom tools.

Custom tools

incident-investigation

An on-call agent that finds the cause of an outage in two hours of service logs, writes the postmortem, and answers follow-up questions in the same session.

Stream events

support-desk

Six support tickets handled in parallel sessions with MCP tools from an AgentCore Gateway, where each refund waits for a supervisor's approval.

MCP tools, Allow or deny a tool call

contract-review

A coordinator agent that hands eight vendor contracts to two other agents, one to read the terms and one to check them against a playbook.

More than one agent

web-search

An agent that searches the web with the managed Web Search Tool behind an AgentCore Gateway.

MCP tools

privatelink

A tool runner in a VPC with no internet access, connected to the service through an interface endpoint for Amazon Bedrock.

Protect the tool runner

session-storage

What a session keeps when AgentCore replaces its container, with AgentCore session storage and without it.

Memory across sessions

s3-files

Notes and skills kept in Amazon S3 and mounted with Amazon S3 Files, so they outlast every session and change without a new image.

Skills

memory

Memory stores read and written by agents with the memory tools and by your code through the API, and checked against each other.

Memory across sessions

account-guardrail

An Amazon Bedrock guardrail enforced on every model call in the account, and what a session shows when it blocks a message or a reply.

Security and IAM roles

evaluation

A session you have already run, scored with the evaluators of Amazon Bedrock AgentCore Evaluations.

Work with sessions

Get the examples

Download claude-managed-agents-examples.zip and claude-managed-agents-tool-runner.zip, and unzip the examples in the same folder as the tool runner bundle:

unzip claude-managed-agents-examples.zip cd examples

The examples need the tool runner binary, which is in the tool runner bundle, not in the examples zip. Most examples take the path to cma-tool-runner-linux-arm64 from the bundle's bin/. memory and account-guardrail don't need it.

Before you start

Every example needs the following. The table after it lists what each example needs on top of that.

  • Your account is set up as in Set up permissions and prerequisites, so the session role ClaudeManagedAgentsSessionRole exists. Most examples' stacks add an inline policy to that role so it can invoke the example's runtime. To use a different session role, pass the stack's SessionRoleName parameter. The scheduled-agent stack doesn't take one. Only github-repo-agent/run.py also takes --session-role-arn; the other examples always use ClaudeManagedAgentsSessionRole.

  • A profile for a role with the ClaudeManagedAgentsCaller policy, such as cma-caller from Create a role to call as, for the run.py scripts. The API refuses IAM users, so use a role profile, such as an SSO profile or one with role_arn.

  • If you run run.py as a different role than setup.sh, such as one with only ClaudeManagedAgentsCaller, that role also needs to read what the scenario's stack made: cloudformation:DescribeStacks on the stack, and s3:GetObject, dynamodb:Scan, and dynamodb:Query on the scenario's bucket and tables. run.py reads the stack's outputs and then checks the agent's work in them. account-guardrail also needs bedrock:ListGuardrails and bedrock:ListEnforcedGuardrailsConfiguration.

  • A deployment identity for setup.sh and the CloudFormation commands. The example stacks create IAM roles and inline policies, ECR repositories and images, AgentCore Runtimes and Gateways, Lambda functions, and data stores, so this identity needs broad permissions such as iam:CreateRole, iam:PutRolePolicy, and iam:PassRole. Those are for setting up the examples only. The role your agents call the API with needs none of them.

  • Access to the Claude models the examples use in Amazon Bedrock: us.anthropic.claude-sonnet-5-5 by default for every example. To use another model ID, such as eu.anthropic.claude-sonnet-5-5 in the EU Regions, pass --model to the example's script. evaluation/run.py doesn't take it, and scheduled-agent has no script to run. Claude model names, such as claude-sonnet-5-5, are refused.

  • Docker with buildx, running. The images are built for ARM64 without emulation, so an x86-64 machine works.

  • AWS CLI version 2, and Python 3.10 or newer with boto3 and pip. The image build downloads Python packages from PyPI, so the machine needs access to it.

  • sha256sum on your PATH. Recent macOS versions include it. On an older Mac, install GNU coreutils.

  • All stacks in the same Region as your API endpoint. The commands below use US West (Oregon).

export AWS_PROFILE=my-deployment-profile # for setup.sh and stacks; use cma-caller for run.py export AWS_REGION=us-west-2 export CMA_ENDPOINT_URL=https://bedrock.us-west-2.amazonaws.com/anthropic/v1 RUNNER=<bundle>/bin/cma-tool-runner-linux-arm64

Replace bundle with the path to the folder where you unzipped the tool runner bundle.

Example

Also needs

Time and cost notes

scheduled-agent

An agent and an AgentCore Runtime you already have, such as the ones from Run your first agent.

Each scheduled run leaves an idle session. Delete them, or the stack, when you finish.

github-repo-agent

A GitHub App you can register in the organization that owns the repositories, and install on them. That usually takes an organization owner.

The App's private key is in AWS Secrets Manager, and the agent gets one-hour tokens through a Lambda function. The model can read a token while it is valid.

Four scenarios

Nothing more. They share one image, built the first time you run a scenario's setup.sh.

About 5 to 10 minutes each, 25 minutes for all four, with setup.

web-search

The AgentCore Gateway Web Search Tool in your Region.

Under a minute per run.

privatelink

Permission to create a VPC, interface endpoints, and an AgentCore Runtime in VPC network mode. setup.sh picks two Availability Zones that AgentCore Runtime supports in US East (N. Virginia), US East (Ohio), or US West (Oregon). To choose others, set FIRST_ZONE_ID and SECOND_ZONE_ID before you run it.

Each interface endpoint is billed for every hour it exists, in each of the two subnets. Delete the stack when you finish.

session-storage

AgentCore Runtime session storage in your Region.

About 10 minutes, most of it waiting for AgentCore to replace the container.

s3-files

Amazon S3 Files in your Region, and permission to create a VPC, a NAT gateway, and the iam:CreateServiceLinkedRole AgentCore needs for VPC mode.

About 10 minutes to create. The NAT gateway is billed by the hour, so run cleanup.py when you finish.

memory

Nothing more. Its sessions use the project's self-hosted environment, so no runtime is started.

About three minutes.

account-guardrail

Permission to create an Amazon Bedrock guardrail and an enforced guardrail configuration.

The guardrail applies to every model call in the account and Region, from every role, while the stack exists. Use a test account, and delete the stack when you finish.

evaluation

A session you have already run, permission to call AgentCore's Evaluate API, and a boto3 version with the bedrock-agentcore client's evaluate method.

Nothing to deploy. Each run sends one session's spans to the Evaluate API.

Run a scenario

The four scenarios are tasks a team might hand an agent, with mock data that has known right answers. Each one's run.py runs the task and then checks what the agent did, so a run ends with a list of passed and failed checks.

Feature

invoice-reconciliation

incident-investigation

support-desk

contract-review

AWS resources

S3, DynamoDB

S3, DynamoDB

DynamoDB, Lambda, AgentCore Gateway

S3, DynamoDB

Sessions

1

1, with 3 turns

6, at the same time

1, with 3 agents

Custom tools

Yes

No

No

No

MCP tools

No

No

Yes

No

Tool confirmations

No

No

Allow and deny

No

Skills

Yes

Yes

Yes

Yes

Coordinator and called agents

No

No

No

Yes

What the tools can reach

Read the data, write one report

Read the logs, write under incidents/

Nothing. The data is reachable only through the gateway's tools.

Read the contracts, write the reviews and the memo

cd invoice-reconciliation ./setup.sh "$RUNNER" python3 run.py

setup.sh builds and pushes the shared image if it needs to, deploys the scenario's stack, and loads its mock data. Run it again to reset the data. For support-desk, run python3 data.py before a later run to clear the last run's refunds and notes. The image holds every scenario's skills, so after you change a skill, run that scenario's setup.sh again.

A check can fail because the model made a wrong call, not because anything is broken. The checks say what was expected and what the agent did, and run.py keeps the session of a failed run so you can read its events. To run all four:

for s in invoice-reconciliation incident-investigation support-desk contract-review; do (cd "$s" && ./setup.sh "$RUNNER" && python3 run.py) || echo "$s failed" done

What the scenarios share

File

What it is

common/Dockerfile, common/aws, common/build-image.sh

One tool runner image for all the scenarios, with Python 3.12, boto3, and the AWS CLI, and each scenario's skills/ folder under /opt/skills/<scenario>/. Its tag is a hash of its contents, so it is rebuilt only when something in it changes.

common/image.yaml

The cma-scenarios image repository. build-image.sh deploys it as the cma-scenarios-image stack.

common/cma.py

A small Python client for the API. It signs requests, reuses agents, streams a turn's events, answers custom tool calls and tool confirmations, and records the checks. You can reuse it in your own code.

Run the other examples

Example

Steps (see its README for details)

scheduled-agent

Find your agent ID and runtime ARN, deploy template.yaml with EndpointUrl, AgentId, EnvironmentId, Prompt, and ScheduleExpression, then invoke the function once to test. Read the run's events with python3 call.py GET sessions/<id>/events.

github-repo-agent

Register a GitHub App and install it on the repositories, deploy the stack, put the App's private key in its secret, build the image with build-image.sh, deploy again with ImageUri, then run python3 run.py. Review the pull request the agent opened.

web-search

./setup.sh "$RUNNER", then python3 run.py. --question asks something else.

privatelink

./setup.sh "$RUNNER", then python3 run.py. Delete the privatelink stack when you finish.

session-storage

./setup.sh "$RUNNER", then python3 run.py.

s3-files

./setup.sh "$RUNNER", then python3 skills.py and python3 memory.py. Clean up with python3 cleanup.py.

memory

python3 run.py.

account-guardrail

Deploy template.yaml with --capabilities CAPABILITY_IAM, then python3 run.py. Delete the stack when you finish.

evaluation

python3 run.py <session id> --evaluators Builtin.Helpfulness,Builtin.GoalSuccessRate.

Clean up the examples

Each example's README has its own steps. To remove the four scenarios and their shared image repository:

for s in invoice-reconciliation incident-investigation contract-review; do bucket=$(aws cloudformation describe-stacks --stack-name "$s" \ --query "Stacks[0].Outputs[?OutputKey=='Bucket'].OutputValue" --output text) aws s3 rm "s3://$bucket" --recursive done for s in invoice-reconciliation incident-investigation support-desk contract-review cma-scenarios-image; do aws cloudformation delete-stack --stack-name "$s" done

The privatelink and s3-files examples create resources that are charged while they exist: interface endpoints, and a NAT gateway. Remove them when you finish:

aws cloudformation delete-stack --stack-name privatelink (cd s3-files && python3 cleanup.py)

Deleting a stack removes the inline policy it added to the session role. The agents the examples create stay in your project. Archive them with POST /agents/{id}/archive if you no longer want them listed.