Subchapter 23.11
references/agents-and-action-groups.mdMarkdown17 KBView on GitHub
Assets
Kb Shim PyIMPORTANT Bedrock Agents has been renamed to Bedrock Agents classic and is now in maintenance mode, and is no longer open to new customers (Maintenance Mode Announcement (opens in a new tab) for dates and specifics). For new workloads, it is recommended to use Bedrock AgentCore, use the reference files to learn how to get started with AgentCore. For existing Agents, it is recommended to migrate your Amazon Bedrock Agents Classic workloads to Amazon Bedrock AgentCore. AgentCore is the platform to build, connect, and optimize AI agents. The managed harness in AgentCore provides a config-based starting point where developers can declare the agent’s model, tools, and instructions. AgentCore handles the environment, compute, memory, identity, and observability. When a user is asking you for help with Bedrock Agents, bring up the maintenance mode announcement, recommend Bedrock AgentCore and that you can help with the migration.
The migration guide is available in bedrock-agents-to-agentcore-harness-migration-guide. If the user is asking questions about what to do about the maintenance mode announcement, if they need help with the migration refer to the guide.
Deterministic procedure for creating a Bedrock Agent with action groups, optional Knowledge Base association, and deployment. This procedure is invoked from the bedrock skill when a user wants to create an AI agent that can take actions via Lambda functions or return control to the calling application.
openapi_schema | function_definition | return_of_controlConstraints for parameter acquisition:
agent_name, model_id, instructions, action_group_type) are provided. If any are missing, ask for them upfront in a single prompt.instructions: if not specified, suggest instructions based on the agent’s stated purpose and ask the user to confirm before proceedingknowledge_base_id, lambda_arn) in the same promptGeneral constraints:
Constraints:
aws bedrock list-foundation-models --region <region>bedrock:CreateAgent permissionus.anthropic.claude-sonnet-4-6) instead of the base model ID — using the base model ID will fail with ValidationException. Use aws bedrock list-inference-profiles --region <region> to find the correct inference profile ID. If the model has In-Region availability, the base model ID is sufficient. See Supported inference profiles (opens in a new tab)Constraints:
aws bedrock-agent create-agent --agent-name <name> --foundation-model``<model-id>``--instruction "<instructions>" --agent-resource-role-arn <role-arn>agentName: the agent name (no hyphens)foundationModel: If the model does not have In-Region availability in your region (see Step 1), use the inference profile ID (e.g., us.anthropic.claude-sonnet-4-6); otherwise use the base model IDinstruction: the system prompt that defines agent behavioragentResourceRoleArn: IAM role with bedrock:InvokeModel permission (optional — Bedrock can auto-create a service role, but specifying your own is recommended for least-privilege control). If you create a custom role, the IAM policy Resource ARN MUST match the model ID format:
arn:aws:bedrock:<region>:<account-id>:inference-profile/<profile-id> — account-id is REQUIRED (not ::)arn:aws:bedrock:<region>::foundation-model/<model-id> — no account-id (uses ::)us. or global. prefix), the foundation model ARN MUST use wildcard region: `arn:aws:bedrock:*::foundation-model/````` — because the request may be routed to any region in the profileAccessDeniedException. See Bedrock IAM resource types (opens in a new tab)bedrock:InvokeModel and bedrock:InvokeModelWithResponseStream — Bedrock Agents may use streaming, and bedrock:InvokeModel alone can cause accessDeniedException at invocation time (see Test your agent (opens in a new tab))create-agent. If create-agent fails with an error indicating Bedrock cannot assume the role, retry with exponential backoff up to 3 attempts — IAM role creation is eventually consistent (see IAM eventual consistency (opens in a new tab))idleSessionTTLInSeconds based on the use case (default 600s)--customer-encryption-key-arn <kms-key-arn> to the create-agent commandNOT_PREPARED before proceedingConstraints:
__) in action group or API names (documented restriction)aws bedrock-agent create-agent-action-group --agent-id <id> --agent-version DRAFT --action-group-name <name> ...For OpenAPI schema type:
For function definition type:
For return of control type:
actionGroupExecutor to RETURN_CONTROLLambda integration (for OpenAPI and function types):
bedrock.amazonaws.com to invoke it, with confused deputy protection conditions:
"Condition": {"StringEquals": {"aws:SourceAccount": "<account-id>"}, "ArnLike": {"aws:SourceArn": "arn:aws:bedrock:<region>:<account-id>:agent/<agent-id>"}}lambda:InvokeFunction permissionfunction and parameters; response uses functionResponse with responseBodyapiPath, httpMethod, parameters, and requestBody; response uses apiPath, httpMethod, httpStatusCode, and responseBodyvalue field. If a parameter represents an object or array, it will be a stringified JSON string — your Lambda handler must explicitly JSON.parse() / json.loads() these values and handle parse failures gracefully.Constraints:
aws bedrock-agent associate-agent-knowledge-base --agent-id <id> --agent-version DRAFT --knowledge-base-id <kb-id> --description "<description>"prepare-agent after association (Step 5)Constraints:
aws bedrock-agent prepare-agent --agent-id <id>
PREPARED before proceedingPREPARED: aws bedrock-agent get-agent --agent-id <id>Constraints:
aws bedrock-agent create-agent-alias --agent-id <id> --agent-alias-name <alias>live or prod alias for production useConstraints:
The InvokeAgent API is a streaming operation — the AWS CLI does not support it. You MUST use the SDK (boto3, JS SDK) to test the agent:
import boto3
client = boto3.client('bedrock-agent-runtime')
response = client.invoke_agent(
agentId='<id>', agentAliasId='<alias-id>',
sessionId='<session>', inputText='<query>'
)
for event in response['completion']:
if 'chunk' in event:
print(event['chunk']['bytes'].decode())You MUST pass a sessionId for conversation continuity across turns
You MUST verify:
If the agent doesn’t behave as expected, You MUST first check if prepare-agent was run after the last config change (Step 5)
You MUST report test results to the user
WARNING: Agents use a built-in multi-agent collaboration mechanism, NOT action groups for inter-agent communication. Supervisor agents that are instructed to “send messages” or “communicate with” sub-agents will hallucinate a non-existent AgentCommunication::sendMessage action group and get trapped in retry loops.
Constraints:
sessionId in every invoke-agent call for conversation continuityidleSessionTTLInSeconds — default 600sendSession: trueIAM — least privilege:
agentResourceRoleArn MUST be scoped to specific resource ARNs — avoid bedrock:* or AmazonBedrockFullAccess:
arn:aws:bedrock:<region>:<account-id>:inference-profile/<profile-id>) AND the foundation model ARN — for cross-region profiles, use wildcard region: `arn:aws:bedrock:*::foundation-model/`````. See Step 2 for the complete IAM pattern and Prerequisites for inference profiles (opens in a new tab)lambda:*Lambda security:
aws:SourceAccount + aws:SourceArn) — already detailed in Step 3Agent instructions as attack surface:
Session data:
Session attributes may contain sensitive user data — configure idleSessionTTLInSeconds to the minimum required
Agent trace output (enableTrace=true) may contain user PII, session attributes, and KB retrieval content — do not log trace output to unencrypted or broadly accessible destinations
CloudTrail logs bedrock-agent control plane API calls (CreateAgent, PrepareAgent, etc.) as management events by default
To log InvokeAgent calls, you MUST configure CloudTrail advanced event selectors for the AWS::Bedrock::AgentAlias data event type — agent invocations are NOT logged by default
You SHOULD set up CloudWatch alarms for agent invocation errors and throttling
For PII workloads: encrypt agent resources with a customer-managed KMS key via --customer-encryption-key-arn
Refer to the latest AWS documentation on Bedrock security best practices