Introduction
Usually software processes data in a predefined way and follows specific steps to complete a task. In contrast, AI agents can perceive, decide, and act, making them a powerful primitive that allows us to take user-defined input, break down a request into multiple tasks, and solve them dynamically. This enables a much more flexible interaction with the user.
Although AI agents offer many benefits and capabilities, and they can be easily prototyped locally using frameworks like LangChain/LangSmith, deploying them to production can be a significant challenge. This is because we need to address aspects such as scaling, session management, tool access, security, and memory management, among others.
AWS Bedrock AgentCore (preview) is a collection of composable services that you can use to build and deploy AI agents securely and at scale. Each AgentCore service addresses different aspects of agents in production, but you can choose not to use all of them. This is useful so that you are not vendor-locked if there is something you want to implement differently or if you already have an agentic solution implemented and have some of these angles already addressed with something different.
⚠️ DISCLAIMER: AgentCore is still in preview, which means that it is not recommended to use with production workloads yet, since things might change once we reach GA, but it is a good opportunity to experiment and learn.
AgentCore services
AgentCore Runtime is where you can deploy and run agents and MCP tools in AWS. Runtime uses Fargate as a backend, meaning that it will scale automatically, and Runtime will manage sessions automatically and, running each session in isolation in a different microVM.
AgentCore Gateway allows agents to discover tools and other agents to interact with. Gateway also allows exposing lambda functions, internal APIs, other AWS services, and external APIs, all as MCP tools, so that they can be accessed by agents in a standard way.
AgentCore Identity provides inbound security, ensuring that only authorized users can use a given agent, and outbound security, making sure that a given agent only uses the tools it is authorized to use.
AgentCore Memory abstracts away short-term and long-term memory management for agents, short-term memory for multi-turn conversations, and long-term memory to allow the agent to learn from conversations, which can be shared amongst multiple agents.
AgentCore Builtin Tools is a set of tools readily available for agents, like Browser Tool and Code Interpreter.
AgentCore Observability is allows for agent instrumentation compatible with OpenTelemetry to be able to trace, debug, and monitor agents in Cloudwatch.
Creating an agent
Here, we will take an incremental approach, allowing you to see how simple it is to start working with agents and how composable each AgentCore service is.
Now we will start by creating an agent
# Install dependencies
python -m venv .venv
source .venv/bin/activate
pip install bedrock-agentcore bedrock-agentcore-starter-toolkit strands-agents strands-agents-tools aws-opentelemetry-distro~=0.10.1
pip freeze > requirements.txt
Here is the agent code where we will be using the Strands Agents SDK, but you could also use other agent frameworks such as LangChain/LangGraph or CrewAI.
# agent.py
from bedrock_agentcore import BedrockAgentCoreApp
from strands import Agent
app = BedrockAgentCoreApp()
agent = Agent()
@app.entrypoint
def invoke(payload):
"""Agent function"""
user_message = payload.get("prompt")
result = agent(user_message)
return {"result": result.message}
if __name__ == "__main__":
app.run()
Then we can run it locally
# Start agent
python agent.py
# Run it locally
curl -X POST http://localhost:8080/invocations \
-H "Content-Type: application/json" \
-d '{"prompt": "Hello"}'
# {"result": {"role": "assistant", "content": [{"text": "Hello! It's nice to meet you. How are you doing today? Is there anything I can help you with?"}]}}
Now, to deploy our agent to AWS, we will leverage the AgentCore toolkit, which simplifies details regarding configuration and deployment.
AgentCore Runtime uses containers to provide compute capacity for your agents; therefore, the agentcore config
command will create a .bedrock-agentcore.yaml file containing all the needed configuration to be used when deploying the agent to AWS, along with a Dockerfile for the container in which the agent will be executed.
Then, the agentcore launch
command will use AWS Codebuild to create the agent container image, then push it to an AWS ECR repository, and finally have the agent runtime use this image. AgentCore Runtime will create a new agent version and will use a Runtime Endpoint to point to the right version, allowing for rollback if needed.
# Deploy
agentcore configure -e agent.py -r us-east-1
agentcore launch
Then, almost the same way we did it locally, we can run the agent, but this time using AgentCore Runtime in AWS.
# Run it remotely
agentcore invoke '{"prompt": "tell me a joke"}'
# {"result": {"role": "assistant", "content": [{"text": "Why don't scientists trust atoms?\n\nBecause they make up everything!"}]}}
Here we can see how simple it is to start using the AgentCore Runtime
Full code example here.
Tools
Agents in Runtime can gain additional capabilities quickly by leveraging AgentCore Built-in tools, a set of MCP tools made available by AWS for agents to utilize.
Browser tool
This is a headless browser that agents can use, which runs in an isolated ephemeral environment
# agent.py
from bedrock_agentcore import BedrockAgentCoreApp
from strands import Agent
from strands_tools.browser import AgentCoreBrowser
app = BedrockAgentCoreApp()
agent_core_browser = AgentCoreBrowser()
agent = Agent(tools=[agent_core_browser.browser])
@app.entrypoint
def invoke(payload):
"""Agent function"""
user_message = payload.get("prompt")
result = agent(user_message)
return {"result": result.message}
if __name__ == "__main__":
app.run()
Top comments (0)