This template demonstrates how to handle Amazon Bedrock Agent events using function-based actions.
The template sets up:
- Amazon Bedrock Agent: Orchestrates user requests and identifies tool usage.
- AWS Lambda function: Resolves function calls using
BedrockAgentFunctionResolver. - Amazon DynamoDB table: Stores and retrieves items used by the agent.
- Function code:
templates/agent - Unit tests:
tests/agent - Infra stack:
infra/stacks/agent.py
Deploy the stack using:
make deploy STACK=agent- Function-based Actions: Uses the
@app.tool()decorator to expose functions to Bedrock Agents. - Automatic Parameter Mapping: Maps Bedrock Agent parameters directly to Python function arguments.
- Type Safety: Uses Pydantic models for data validation and camelCase alias conversion.
- Observability: Integrated with AWS Lambda Powertools for logging, tracing, and metrics.
Use the @app.tool() decorator to define tools that the agent can call:
@app.tool(name="getItem", description="Gets item details by ID")
def get_item(item_id: str) -> dict:
return handler.get_item(item_id)| Field | Type | Description |
|---|---|---|
id |
UUID string | Unique item identifier (auto-generated) |
name |
string | Human-readable item name |
description |
string | Human-readable item description |
| Variable | Description |
|---|---|
TABLE_NAME |
DynamoDB table name |
SERVICE_NAME |
Powertools service name |
METRICS_NAMESPACE |
Powertools metrics namespace |
