Building Bedrock Agents with Action Groups and Knowledge Bases
Amazon Bedrock Agents is a managed service for building agents: you write instructions, attach action groups (tools backed by Lambda) and knowledge bases, and Bedrock runs the reasoning loop, calls your tools, keeps session memory and records a trace of every step.
flowchart LR
U[User / app] -->|InvokeAgent| A["Bedrock Agent<br/>instructions + model"]
A -->|"orchestration (ReAct)"| AG["Action group order_tools<br/>get_order_status(order_id)"]
AG -->|event| L[Lambda function] -->|GetItem| D[(DynamoDB Orders)]
A -->|retrieve| KB[(Knowledge base: returns policy)]
A -->|final response + trace| U
Configuration
| Part | Notes |
|---|---|
| Instructions | Who the agent is, what it may do, tone – at least 40 characters, be specific |
| Model | One with strong tool use (Claude, Nova Pro) |
| Action group | A set of functions defined by function details (name, description, parameters) or an OpenAPI schema |
| Executor | A Lambda function (“quick create” generates a template) or return control to your app |
| Knowledge bases | Attached with a description of when to use them |
| Guardrail | Optional safety policy |
| Memory | Session summaries across conversations (optional) |
The Lambda contract (function details)
Event received by your function:
{
"messageVersion": "1.0",
"agent": { "name": "order-support-agent", "id": "AGENT123", "alias": "TSTALIASID", "version": "DRAFT" },
"inputText": "Where is my order ORD-1001?",
"sessionId": "abc-123",
"actionGroup": "order_tools",
"function": "get_order_status",
"parameters": [{ "name": "order_id", "type": "string", "value": "ORD-1001" }],
"sessionAttributes": {}, "promptSessionAttributes": {}
}
Response your function must return:
return {
messageVersion: '1.0',
response: {
actionGroup: event.actionGroup,
function: event.function,
functionResponse: { responseBody: { TEXT: { body: JSON.stringify(result) } } },
},
};
A wrong shape gives “The server encountered an error processing the Lambda response”.
Permissions – both directions
| Direction | Mechanism |
|---|---|
| Bedrock → Lambda | Resource-based policy on the function allowing bedrock.amazonaws.com (quick create adds it) |
| Lambda → DynamoDB etc. | The function’s execution role (least privilege) |
| Agent → model / KB | The agent service role |
Prepare, test and trace
- Save and prepare – builds the working DRAFT.
- Test in the console; open Show trace: pre-processing → orchestration rationale → invocation input (function + parameters) → observation (Lambda result) → knowledge-base lookups → final response.
- If a required parameter is missing, the agent asks the user instead of guessing.
Release and invoke
- Create an alias (e.g.
prod) – it creates an immutable version of the agent. - Applications call the alias with InvokeAgent and a
sessionId(streamed response chunks).
import { BedrockAgentRuntimeClient, InvokeAgentCommand } from '@aws-sdk/client-bedrock-agent-runtime';
const res = await new BedrockAgentRuntimeClient({}).send(new InvokeAgentCommand({
agentId: 'AGENT123', agentAliasId: 'ALIAS456', sessionId: 'user-42',
inputText: 'Where is my order ORD-1001?',
}));
Agent quality = clear instructions + precise function descriptions + correct Lambda contract + least-privilege permissions. Use the trace to debug every decision.
Practise it
Virtual lab · Amazon Web Services · 45 min
Build an AI agent with Bedrock Agents, a Lambda tool and a knowledge base
Create an order-support agent that decides when to call your Lambda function (looking up orders in DynamoDB), asks for missing details, answers policy questions from a knowledge base, and explains every step in its trace.
Quick revision
- Agent = instructions + model + action groups + knowledge bases (+ guardrail, memory).
- Action groups use function details or OpenAPI; Lambda executes them.
- Lambda gets
function+parameters, returnsfunctionResponse.responseBody. - Resource policy for Bedrock → Lambda; execution role for Lambda → data.
- Prepare, test with traces, then publish an alias and call InvokeAgent.
Practise this topic
Hands-on virtual lab
Apply what you just read in a realistic, guided simulation. Free with a verified account.
Create a free account to track your progress and unlock virtual labs.