AWS Bedrock
Use Claude on Bedrock
Section titled “Use Claude on Bedrock”Keep your AWS infrastructure. Get explainable agents.
npm install agentfootprint @aws-sdk/client-bedrock-runtimeimport { Agent, bedrock, defineTool } from 'agentfootprint';
const provider = bedrock('anthropic.claude-sonnet-4-20250514-v1:0');
const agent = Agent.create({ provider }) .system('You are a helpful assistant.') .tool(myTool) .build();
const result = await agent.run('Hello');console.log(result.content);console.log(agent.getNarrative()); // full execution traceConfiguration
Section titled “Configuration”import { BedrockAdapter } from 'agentfootprint';
// Explicit region and credentialsconst provider = new BedrockAdapter({ model: 'anthropic.claude-sonnet-4-20250514-v1:0', region: 'us-east-1',});
// Cross-region inferenceconst provider = new BedrockAdapter({ model: 'us.anthropic.claude-sonnet-4-20250514-v1:0', region: 'us-east-1',});Authentication uses the standard AWS credential chain (environment variables, IAM roles, SSO profiles).
Region defaults to the
AWS_REGIONenvironment variable. Override with:const provider = bedrock('anthropic.claude-sonnet-4-20250514-v1:0', { region: 'us-east-1' });
Available Bedrock models
Section titled “Available Bedrock models”| Model | Bedrock Model ID |
|---|---|
| Claude Sonnet 4 | anthropic.claude-sonnet-4-20250514-v1:0 |
| Claude Opus 4 | anthropic.claude-opus-4-20250514-v1:0 |
| Claude Haiku 3.5 | anthropic.claude-3-5-haiku-20241022-v1:0 |
Switching from raw AWS SDK
Section titled “Switching from raw AWS SDK”import { BedrockRuntimeClient, ConverseCommand } from '@aws-sdk/client-bedrock-runtime';
const client = new BedrockRuntimeClient({ region: 'us-east-1' });const response = await client.send(new ConverseCommand({ modelId: 'anthropic.claude-sonnet-4-20250514-v1:0', messages: [{ role: 'user', content: [{ text: 'Hello' }] }],}));console.log(response.output?.message?.content?.[0]?.text);import { Agent, bedrock } from 'agentfootprint';
const agent = Agent.create({ provider: bedrock('anthropic.claude-sonnet-4-20250514-v1:0', { region: 'us-east-1' }),}) .system('You are helpful.') .build();
const result = await agent.run('Hello');console.log(result.content);console.log(agent.getNarrative()); // bonus: full execution traceAgent with tools on Bedrock
Section titled “Agent with tools on Bedrock”import { Agent, bedrock, defineTool } from 'agentfootprint';
const provider = bedrock('anthropic.claude-sonnet-4-20250514-v1:0');
const lookupOrder = defineTool({ id: 'lookup_order', description: 'Look up an order by ID', inputSchema: { type: 'object', properties: { orderId: { type: 'string' } }, required: ['orderId'], }, handler: async ({ orderId }) => { const order = await db.orders.find(orderId); return { content: JSON.stringify(order) }; },});
const agent = Agent.create({ provider }) .system('You are a customer support agent.') .tool(lookupOrder) .build();
const result = await agent.run('Check order ORD-1003');
// Connected execution traceagent.getNarrative();// [// "[Seed] Initialized agent state",// "[CallLLM] Called LLM",// "[ParseResponse] Parsed: tool_calls → [lookup_order({orderId: "ORD-1003"})]",// "[ExecuteToolCalls] Tool results: {"orderId":"ORD-1003","status":"shipped"}",// "[CallLLM] Called LLM",// "[Finalize] Your order ORD-1003 has shipped."// ]Memory (conversation persistence)
Section titled “Memory (conversation persistence)”import { Agent, InMemoryStore, bedrock } from 'agentfootprint';
const provider = bedrock('anthropic.claude-sonnet-4-20250514-v1:0');
// Development: in-memoryconst agent = Agent.create({ provider }) .system('You are a support agent.') .memory({ store: new InMemoryStore(), conversationId: 'session-abc', }) .build();
await agent.run('My name is Alice');await agent.run('What is my name?'); // "Your name is Alice"For production, implement the MemoryStore interface backed by DynamoDB, Redis, or any datastore.
Observability
Section titled “Observability”Track tokens, cost, and tool usage — export to CloudWatch:
import { Agent, bedrock } from 'agentfootprint';import { agentObservability } from 'agentfootprint/observe';import { CloudWatch } from '@aws-sdk/client-cloudwatch';
const cw = new CloudWatch({ region: 'us-east-1' });const obs = agentObservability();const provider = bedrock('anthropic.claude-sonnet-4-20250514-v1:0');
const agent = Agent.create({ provider }) .system('You are a support agent.') .recorder(obs) .build();
await agent.run(userMessage);
// Structured data — tokens, tools, costconsole.log(obs.tokens()); // { totalCalls: 2, totalInputTokens: 243, calls: [...] }console.log(obs.tools()); // { totalCalls: 1, byTool: { lookup_order: { calls: 1 } } }console.log(obs.cost()); // 0.0042 (USD)
// Push to CloudWatchconst tokens = obs.tokens();await cw.putMetricData({ Namespace: 'AgentFootprint', MetricData: [ { MetricName: 'LLMCalls', Value: tokens.totalCalls, Unit: 'Count' }, { MetricName: 'InputTokens', Value: tokens.totalInputTokens, Unit: 'Count' }, { MetricName: 'OutputTokens', Value: tokens.totalOutputTokens, Unit: 'Count' }, { MetricName: 'EstimatedCost', Value: obs.cost(), Unit: 'None' }, ],});Streaming
Section titled “Streaming”const agent = Agent.create({ provider }) .system('You are a support agent.') .streaming(true) .build();
await agent.run('Check order ORD-1003', { onEvent: (event) => { switch (event.type) { case 'llm_start': console.log(`LLM call #${event.iteration}`); break; case 'llm_end': console.log(`${event.model} (${event.latencyMs}ms)`); break; case 'tool_start': console.log(`Running ${event.toolName}`); break; case 'tool_end': console.log(`Done (${event.latencyMs}ms)`); break; case 'token': process.stdout.write(event.content); break; } },});Grounding analysis
Section titled “Grounding analysis”Compare tool results vs LLM claims — hallucination detection without a separate eval pipeline:
import { ExplainRecorder } from 'agentfootprint/explain';
const explain = new ExplainRecorder();// attach via .recorder(explain) before .build()await agent.run('Check order ORD-1003');const report = explain.explain();report.sources; // what tools returned (ground truth)report.claims; // what the LLM said (to verify)Resilience
Section titled “Resilience”Provider failover across regions or families:
import { bedrock } from 'agentfootprint';import { fallbackProvider } from 'agentfootprint/resilience';
const provider = fallbackProvider([ bedrock('anthropic.claude-sonnet-4-20250514-v1:0'), // us-east-1 bedrock('us.anthropic.claude-sonnet-4-20250514-v1:0'), // cross-region]);Deploy on AgentCore
Section titled “Deploy on AgentCore”For serverless deployment with VM isolation, see the Bedrock AgentCore integration.