
- The client is created for the Bedrock Agent Runtime service (not the standard Bedrock Runtime).
- You must provide
agentIdandagentAliasIdthat reference an existing Bedrock agent (the agent configuration contains the foundation model, action groups, instructions, and optional knowledge bases). - Provide a
sessionIdto scope a conversation. The format is defined by your application (numeric, alphanumeric, or any convention you choose) and controls conversation separation and continuity. - Responses from
InvokeAgentare streamed in chunks; the code below shows assembling a completion from those chunks.
Session ID guidance: choose a
sessionId strategy that fits your application. You might use one session per end user, or separate sessions for different tasks or contexts (for example, a support conversation vs. an order request). The sessionId format is up to you.- Your application calls the Bedrock Agent Runtime and specifies an agent (
agentId). - The agent configuration maps to a chosen foundation model and one or more action groups.
- Action groups contain discrete actions (for example:
getOrder,updateOrder,updateInventory). - Each action can be implemented as an AWS Lambda function; Lambda acts as the “glue” to external APIs, databases, and services.
- Centralizes retry logic, pagination, backoff strategies, and error handling.
- Encapsulates API clients and secrets management.
- Enables complex business logic, filtering, and orchestration before returning results to the agent.

Agent abstraction: instead of your application orchestrating every model call and external API call, you send a goal-oriented request and the agent selects tools, action groups, and knowledge sources. Lambda functions make those external integrations reliable, testable, and secure.
- Amazon Bedrock documentation: https://docs.aws.amazon.com/bedrock/
- AWS Lambda: https://docs.aws.amazon.com/lambda/
- SWAPI (example external data source): https://swapi.dev/