Decoding Amazon Bedrock Agents
You have probably heard this multiple times — “2025 is the year of Agents”. This blogs dives deep in to building AI agents using Amazon Bedrock.
An agent is anything that can perceive its environment and act upon that environment using data and tools. Applications using agents do not create pre-defined workflows. Agents dynamically architect the workflow based on user query, orchestrate the end to end workflow (tool calling) and return the results.
For a deeper dive on AI Agents refer to one of the best blog on Agents from Chip Huyen- https://huyenchip.com/2025/01/07/agents.html.
A quick look at the inner working of an agent.
For a given task, Agent architects the end to end workflow by decomposing the tasks in to steps, executing each of the steps, observing the results against the goals of the task. Agents returns the control and the results once the goal is achieved.
Anatomy of an Agent
Let us look at the components of an Agent. Agents needs an environment to work that defines the scope of the agent.
- Environment: Agents operate in an environment defined by its use case. Environment defines the functional boundary for the agent. This functional boundary is important for ensuring the agent scope is clear. You do not want a agent that is too broad (like having 10s of knowledge bases / tools) or too narrow having a single tool functionality.
- Model: is the brain of the Agent. Models reasons on the user requests to come up with a plan to accomplish the task(s), evaluate the generated plan, execute the plan.
- Tools: help extend the capability of the Model. Agents use the tools to perform a set of actions (defined by their tools) within the environment.
- Knowledge bases: represent the enterprise data pertaining to the environment
In addition to the above, Agent runtime requires
- Prompt Management: For agents to decompose the task, identify the right tools for the task and evaluating the results requires distinct prompts to the LLM.
- Guardrail: for making agents responsible by safeguarding prompts, intermediate response from each of the steps and the final response
- Memory management: Memory provides your agent the ability to retain conversational context across multiple sessions and to recall past actions and behaviors
- Observability: Tracing and tracking agents behavior from start to finish
How Bedrock Agents work
Amazon Bedrock implements the agent capability using battle tested services from Bedrock Models, OpenSearch, Lambda, Dynamo DB to Cloud watch
- Bedrock Agents use Bedrock Models as the brain for reasoning and execution. Use of larger / powerful models is recommended. think Nova Pro, Claude Sonnet 3.5. You can also chose to use other models including your own custom fine tuned / distilled model. Default implementation of Bedrock agents uses ReACT framework.
- Bedrock knowledge bases address the Data needs. Knowledge bases are powered by one of OpenSearch, Aurora pgvector, Mongo DB, Pinecone or Amazon Neptune database (for Graph ontologies)
- Tools for agents are implemented using AWS Lambda functions. Use of Lambda function extends the capability to use API’s, any of AWS services or third party libraries.
- Amazon Bedrock agents provides built-in support for Prompt Management and Memory management.
- Amazon Guardrails help in defining safe guards and responsible AI
- All operations of the agents are traced with detailed logging using Amazon CloudWatch
Advantages on using Bedrock Agents:
- All the above services used by Bedrock Agents are Serverless in nature. You do not have to provision or scale them and you pay for what you use
- Bedrock provides the runtime environment for the agents with memory management (prompt and session)
- Built in prompts are provided for pre-processing, post processing. You have the option to override if you chose to do so
- Use of battle tested AWS servies makes Bedrock agents reliable and secure
- Authorization is enabled using IAM and RBAC policies applied on tools (lambda functions) and knowledge bases
- Bedrock Agents can be integrated as a node on to Langgraph if you chose to use a langgraph based agent orchestration
- For optimal performance (at the time of this writing) restrict the components of the Agent to a single account / region.
Bedrock Agents in Action
You can work with Bedrock agents in 3 easy steps
Build Agent
In the build phase of the agent, you define all the necessary components of the agents from Models, instruction (environment), data (knowledge bases), tools (Action groups)…
Step 1 — Create the Agent: you will have to use the pointer to ‘bedrock-agent’ sdk. This is the build SDK for agents.
bedrock_agent_client = boto3.client('bedrock-agent')
response = bedrock_agent_client.create_agent(
agentName=agent_name,
agentResourceRoleArn=agent_role['Role']['Arn'],
description=agent_description,
idleSessionTTLInSeconds=1800,
foundationModel=agent_foundation_model,
instruction=agent_instruction,
guardrailConfiguration,
memoryConfiguration,
promptOverrideConfiguration
)
agent_id = response['agent']['agentId']
agent_id
- Model ID — have to be a model available through Amazon Bedrock Model hub
- Instructions — describes the agent’s environment, its role and task. This has to be verbose and detailed
- Memory configuration: defines what to store and how long to store.
memoryConfiguration={
"enabledMemoryTypes": ["SESSION_SUMMARY"],
"storageDays": 30
}
- Guardrail configuration — Guardrail id and version. To understand how to create a guardrail, please refer to this blog — https://medium.com/@meenakshisundaram-t/responsible-ai-lens-gen-ai-poc-to-prod-part-1-0e7efde9da83
- Bedrock Agents provide default prompts for pre-processing and post processing. However if you chose to override them, you can provide them in the prompts override parameter.
Step 2 — Associate Knowledge Base to Bedrock Agent:
Let us first associate a knowledge Base to Bedrock Agent. You need to first create a knowledge base. To create a knowledge base, please follow this user guide — https://docs.aws.amazon.com/bedrock/latest/userguide/knowledge-base-create.html.
Once the knowledge base is created, use the knowledge base id and associate it to the agent. You can associate multiple knowledge bases to a single agent.
agent_kb_description = bedrock_agent_client.associate_agent_knowledge_base(
agentId=agent_id,
agentVersion='DRAFT',
description=f'Use the information in the {kb_name} knowledge base to provide accurate responses to the questions about Amazon Bedrock.',
knowledgeBaseId=knowledge_base_id
)
Step 3 — Associate Tools to Bedrock Agents:
Amazon Bedrock provides built-in tool (code interpreter) and you can bring your own tool.
Code interpreter is a special pre-defined tool (action group) that provides the agent with a sandbox environment in which it can execute code (currently Python), using a set of available pre-defined libraries. You can associate this tool by adding this tool as a action group to the agent.
agent_action_group_response = bedrock_agent_client.create_agent_action_group(
agentId=agent_id,
agentVersion='DRAFT',
actionGroupName='code-interpreter',
parentActionGroupSignature='AMAZON.CodeInterpreter',
actionGroupState='ENABLED'
)
On the other hand, Custom Tools needs to be created in a lambda function. You can follow this user guide to create tools for agents — https://docs.aws.amazon.com/bedrock/latest/userguide/agents-lambda.html.
You can now associate the lambda function to the Bedrock Agent as an “Action Group”. An Action group can have multiple actions and each action is defined as a function within the Lambda.
agent_action_group_response = bedrock_agent_client.create_agent_action_group(
agentId=agent_id,
agentVersion='DRAFT',
actionGroupExecutor={
'lambda': lambda_function['FunctionArn']
},
actionGroupName=agent_action_group_name,
functionSchema={
'functions': agent_functions
},
description=agent_action_group_description
)
Prepare Agent:
Think of preparing the agent as gluing / compiling all the components of the agents defined in the build phase. You will need to prepare the agent before invoking the agent.
agent_prepare = bedrock_agent_client.prepare_agent(agentId=agent_id)
agent_prepare
Run Agent:
Now the agent is ready. You can now invoke the agent with a task. You will have to use the pointer to the ‘bedrock-agent-runtime’ SDK for invoking the agent.
bedrock_agent_client = boto3.client('bedrock-agent-runtime')
agentResponse = bedrock_agent_runtime_client.invoke_agent(
inputText="Your task",
agentId=agent_id,
agentAliasId=agent_alias_id,
sessionId=session_id,
enableTrace=enable_trace,
endSession= end_session
)
Your agentic application is ready.
Patterns — Bedrock Agent
Agents can be time consuming both at build / design time and run time. To address this Bedrock has built-in patterns like Inline Agents and Custom Orchestration.
Bedrock Inline agents:
Problem statement: Agent development and testing often requires you to changing your configurations to find the optimal design. The changes apply to agent instructions, tools and knowledge base configurations, prompt templates etc. In the traditional way of building Bedrock agents, after every configuration change in the agent, you will have to go through the three stages: Build -> Prepare -> Invoke. This process consumes time and effort. This consumes time and effort.
Solution: Bedrock Inline agents helps in eliminating the need for you build and prepare agent. You can provide all the configurations as runtime parameters to the invoke agent call.
Here is a simple example usage for Bedrock inline agents
import boto3
import json
model_id = ''
agent_instruction = ''
# Runtime Endpoints
bedrock_rt_client = boto3.client(
"bedrock-agent-runtime",
region_name=region
)
# prepare request parameters before invoking inline agent
request_params = {
"instruction": agent_instruction,
"foundationModel": model_id,
"sessionId": sessionId,
"endSession": endSession,
"enableTrace": enableTrace,
}
# define code interpreter tool
code_interpreter_tool = {
"actionGroupName": "UserInputAction",
"parentActionGroupSignature": "AMAZON.CodeInterpreter"
}
# add the tool to request parameter of inline agent
request_params["actionGroups"] = [code_interpreter_tool]
# enable traces
request_params["enableTrace"] = True
# enter the question you want the inline agent to answer
request_params['inputText'] = 'Your query'
response = client.invoke_inline_agent(
**request_params
)
Custom Orchestrator in Bedrock agents:
Problem Statement: By design, Agent execution uses ReAct framework (a cyclical Thought -> Action -> Observe) demanding multiple calls to the model, there by increased cost and latency.
Solution: Amazon Bedrock agents provides a capability called ‘Custom Orchestrator’. This enables you to fine-tune agent behavior and manage tool interactions at each workflow step. This customization allows you to tailor agent functionality to their specific operational needs, improving precision, adaptability, and efficiency. This is achieved by using Reasoning Without Observation (ReWOO) framework over ReAct framework
Closing thoughts
We have just scratched the surface on Bedrock Agents. Bedrock Agents support multiple configuration on memoy management, prompting and tracing. In addition you can do multi agent orchestration using Amazon Bedrock agents. At the time of this writing, Bedrock agents supports Supervisor pattern and hierarchical patter on multi agent orchestration. More on this in the next blog.