|
| 1 | +# Amazon Bedrock AgentCore Example |
| 2 | + |
| 3 | +This example demonstrates how to integrate an AgentCore-hosted agent into a Pipecat pipeline. |
| 4 | + |
| 5 | +The pipeline looks like a standard Pipecat bot pipeline, but with an AgentCore agent taking the place of an LLM. User audio gets converted to text and sent to the AgentCore agent, which will try to do work on the user's behalf. Responses from the agent are streamed back and spoken. User and agent messages are recorded in a context object. |
| 6 | + |
| 7 | +Note that unlike an LLM service found in a traditional Pipecat bot pipeline, the AgentCore agent by default does not receive the full conversation context after each user turn, only the last user message. It is up to the AgentCore agent to decide whether and how to manage its own memory (AgentCore includes memory capabilities). |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +- Accounts with: |
| 12 | + - AWS |
| 13 | + - OpenAI |
| 14 | + - Deepgram |
| 15 | + - Cartesia |
| 16 | + - Daily (optional) |
| 17 | +- Python 3.10 or higher |
| 18 | +- `uv` package manager |
| 19 | + |
| 20 | +## Setup |
| 21 | + |
| 22 | +### Install Dependencies |
| 23 | + |
| 24 | +Install dependencies needed to run the Pipecat bot as well as the AgentCore CLI. |
| 25 | + |
| 26 | +```bash |
| 27 | +uv sync |
| 28 | +``` |
| 29 | + |
| 30 | +### Set Environment Variables |
| 31 | + |
| 32 | +Copy `env.example` to `.env` and fill in the values in `.env`. |
| 33 | + |
| 34 | +```bash |
| 35 | +cp env.example .env |
| 36 | +``` |
| 37 | + |
| 38 | +**Do not worry** about `AWS_AGENT_ARN` yet. You'll obtain an agent ARN as part of the following steps, when you deploy your agent to AgentCore Runtime. |
| 39 | + |
| 40 | +## Deploying Your Agent to AgentCore Runtime |
| 41 | + |
| 42 | +Before you can run the Pipecat bot file, you need to deploy an agent to AgentCore Runtime. This example includes two agents: |
| 43 | + |
| 44 | +- A dummy agent that reports progress while pretending to carry out a relatively long-running task |
| 45 | +- An algorithmic-problem-solving agent that can write code to answer questions |
| 46 | + |
| 47 | +Below we'll do a barebones walkthrough of deploying an agent to AgentCore Runtime. For a comprehensive guide to getting started with Amazon Bedrock AgentCore, including detailed setup instructions, see the [Amazon Bedrock AgentCore Developer Guide](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/what-is-bedrock-agentcore.html). |
| 48 | + |
| 49 | +### IAM Setup |
| 50 | + |
| 51 | +Configure your IAM user with the necessary policies for AgentCore usage. Start with these: |
| 52 | + |
| 53 | +- `BedrockAgentCoreFullAccess` |
| 54 | +- A new policy (maybe named `BedrockAgentCoreCLI`) configured [like this](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-permissions.html#runtime-permissions-starter-toolkit) |
| 55 | + |
| 56 | +You can also choose to specify more granular permissions; see [Amazon Bedrock AgentCore docs](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-permissions.html) for more information. |
| 57 | + |
| 58 | +### Environment Setup |
| 59 | + |
| 60 | +To simplify the remaining AgentCore deployment steps in this README, it's a good idea to export some AWS-specific environment variables: |
| 61 | + |
| 62 | +```bash |
| 63 | +export AWS_SECRET_ACCESS_KEY=... |
| 64 | +export AWS_ACCESS_KEY_ID=... |
| 65 | +export AWS_REGION=... |
| 66 | +``` |
| 67 | + |
| 68 | +### Agent Configuration |
| 69 | + |
| 70 | +Create a new AgentCore configuration. |
| 71 | + |
| 72 | +```bash |
| 73 | +cd agents |
| 74 | +uv run agentcore configure -e code_agent.py |
| 75 | +``` |
| 76 | + |
| 77 | +Follow the interactive prompts to complete the configuration. It's OK to just accept all defaults. |
| 78 | + |
| 79 | +### Agent Deployment |
| 80 | + |
| 81 | +Deploy your agent to AgentCore Runtime. |
| 82 | + |
| 83 | +```bash |
| 84 | +uv run agentcore launch |
| 85 | +``` |
| 86 | + |
| 87 | +This step will spit out the agent ARN. Copy it and paste it in your `.env` file as your `AWS_AGENT_ARN` value. |
| 88 | + |
| 89 | +The above is also the command you need to run after you've updated your agent code and need to redeploy. |
| 90 | + |
| 91 | +### Validation |
| 92 | + |
| 93 | +Try running your agent on AgentCore Runtime. |
| 94 | + |
| 95 | +```bash |
| 96 | +uv run agentcore invoke '{"prompt": "What is the meaning of life?"}' |
| 97 | +``` |
| 98 | + |
| 99 | +### Obtaining Your Agent ARN at Any Point |
| 100 | + |
| 101 | +Your agent status will include its ARN. |
| 102 | + |
| 103 | +```bash |
| 104 | +uv run agentcore status |
| 105 | +``` |
| 106 | + |
| 107 | +## Running The Example |
| 108 | + |
| 109 | +With your agent deployed to AgentCore, you can now run the example. |
| 110 | + |
| 111 | +```bash |
| 112 | +# Using SmallWebRTC transport |
| 113 | +uv run python bot.py |
| 114 | + |
| 115 | +# Using Daily transport |
| 116 | +uv run python bot.py -t daily -d |
| 117 | +``` |
0 commit comments