bedrock_agents_sdk package

Subpackages

Module contents

Amazon Bedrock Agents with Return Control SDK

This SDK provides a simple yet powerful way to create and interact with Amazon Bedrock Agents using the Return Control pattern. It allows you to easily define function tools, organize them into action groups, and handle the entire conversation flow with minimal boilerplate code.

class bedrock_agents_sdk.ActionGroup(*, name: str, description: str, functions: List[Function | Callable] = [])[source]

Bases: BaseModel

Represents an action group in the agent

description: str
functions: List[Function | Callable]
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
class bedrock_agents_sdk.Agent(**data)[source]

Bases: object

Agent configuration for Amazon Bedrock Agents

action_groups: List[ActionGroup]
add_action_group(action_group: ActionGroup)[source]

Add an action group to the agent

Parameters:

action_group – The action group to add

Returns:

For method chaining

Return type:

self

add_dependency(dependency: str, version: str | None = None, action_group: str | None = None)[source]

Add a custom dependency for deployment

This method allows you to specify dependencies that should be included in the requirements.txt file when deploying the agent to AWS Lambda.

Parameters:
  • dependency – The name of the dependency (e.g., “pandas”)

  • version – Optional version constraint (e.g., “>=1.0.0”)

  • action_group – Optional action group to add the dependency to. If not provided, the dependency will be added to all action groups.

Returns:

For method chaining

Return type:

self

add_file(name: str, content: bytes, media_type: str, use_case: str = 'CODE_INTERPRETER') InputFile[source]

Add a file to be sent to the agent

add_file_from_path(file_path: str, use_case: str = 'CODE_INTERPRETER') InputFile[source]

Add a file from a local path

add_function(function: Callable, description: str | None = None, action_group: str | None = None)[source]

Add a function to the agent

add_plugin(plugin: AgentPlugin)[source]

Add a plugin to the agent

Parameters:

plugin – The plugin to add

advanced_config: Dict[str, Any] | None = None
deploy(output_dir: str | None = None, foundation_model: str | None = None, parameters: Dict[str, Dict[str, str]] | None = None, description: str | None = None, auto_build: bool = False, auto_deploy: bool = False) str[source]

Deploy the agent to AWS using SAM

Parameters:
  • output_dir – The directory to output the SAM template and code to. If None, defaults to “./[agent_name]_deployment”

  • foundation_model – The foundation model to use (defaults to the agent’s model)

  • parameters – Additional parameters to add to the template

  • description – Description for the SAM template

  • auto_build – Whether to automatically run ‘sam build’

  • auto_deploy – Whether to automatically run ‘sam deploy –guided’

Returns:

Path to the generated template file

Return type:

str

enable_code_interpreter: bool = False
files: List[InputFile]
functions: List[Callable] | Dict[str, List[Callable]]
instructions: str
model: str
model_config = {'arbitrary_types_allowed': True}
name: str
plugins: List[AgentPlugin]
class bedrock_agents_sdk.AgentPlugin[source]

Bases: object

Base class for all plugins for the Bedrock Agents SDK

post_invoke(response)[source]

Called after invoke_inline_agent, can modify response

post_process(result)[source]

Called after processing the response, can modify the final result

pre_deploy(template)[source]

Called before generating the SAM template, can modify the template

Parameters:

template – The SAM template dictionary

Returns:

The modified SAM template dictionary

pre_invoke(params)[source]

Called before invoke_inline_agent, can modify params

bedrock_agents_sdk.BedrockAgents

alias of Client

bedrock_agents_sdk.BedrockAgentsPlugin

alias of AgentPlugin

class bedrock_agents_sdk.Client(region_name: str | None = None, profile_name: str | None = None, verbosity: str = 'normal', trace_level: str = 'none', max_tool_calls: int = 10)[source]

Bases: object

Client for interacting with Amazon Bedrock Agents

chat(agent: Agent, session_id: str | None = None)[source]

Start an interactive chat session with the agent

Parameters:
  • agent – The agent configuration

  • session_id – Optional session ID to continue a conversation. If not provided, a new session will be created.

run(agent: Agent, message: str | None = None, messages: List[Message | Dict[str, str]] | None = None, session_id: str | None = None) Dict[str, Any][source]

Run the agent with either a simple message string or a list of structured messages

Parameters:
  • agent – The agent configuration

  • message – A simple string message (mutually exclusive with messages)

  • messages – A list of messages in the conversation (mutually exclusive with message)

  • session_id – Optional session ID to continue a conversation. If not provided, a new session will be created.

Returns:

Dictionary containing the response text and any files

Return type:

Dict[str, Any]

bedrock_agents_sdk.ClientPlugin

alias of AgentPlugin

class bedrock_agents_sdk.Function(*, name: str, description: str, function: Callable, action_group: str | None = None)[source]

Bases: BaseModel

Represents a function that can be called by the agent

action_group: str | None
description: str
function: Callable
model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
class bedrock_agents_sdk.GuardrailPlugin(guardrail_id: str, guardrail_version: str = None)[source]

Bases: AgentPlugin

Plugin for adding guardrails to Bedrock Agents

pre_deploy(template)[source]

Add guardrail configuration to the agent in the SAM template

pre_invoke(params)[source]

Add guardrail configuration to the request parameters

class bedrock_agents_sdk.InputFile(*, name: str, content: bytes, media_type: str, use_case: str = 'CODE_INTERPRETER')[source]

Bases: BaseModel

Represents a file to be sent to the agent

content: bytes
media_type: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
to_dict() Dict[str, Any][source]

Convert to API parameters format

use_case: str
class bedrock_agents_sdk.KnowledgeBasePlugin(knowledge_base_id: str, description: str = None, retrieval_config: dict = None)[source]

Bases: AgentPlugin

Plugin for adding knowledge base integration to Bedrock Agents

pre_deploy(template)[source]

Add knowledge base configuration to the agent in the SAM template

pre_invoke(params)[source]

Add knowledge base configuration to the request parameters

class bedrock_agents_sdk.Message(*, role: str, content: str)[source]

Bases: BaseModel

Represents a message in the conversation

content: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

role: str
class bedrock_agents_sdk.OutputFile(name: str, content: bytes, file_type: str)[source]

Bases: object

Represents a file received from the agent

classmethod from_response(file_data: Dict[str, Any]) OutputFile[source]

Create an OutputFile from API response data

save(directory: str = '.') str[source]

Save the file to disk

class bedrock_agents_sdk.SAMTemplateGenerator(agent: Agent, output_dir: str = None)[source]

Bases: object

Generates a SAM template for deploying a Bedrock Agent

add_custom_dependency(action_group: str, dependency: str, version: str | None = None)[source]

Add a custom dependency for a specific action group

Parameters:
  • action_group – The action group to add the dependency to

  • dependency – The name of the dependency

  • version – Optional version constraint (e.g., “>=1.0.0”)

generate(foundation_model: str | None = None, parameters: Dict[str, Dict[str, str]] | None = None, description: str | None = None) str[source]

Generate the SAM template and supporting files

Parameters:
  • foundation_model – The foundation model to use (defaults to the agent’s model)

  • parameters – Additional parameters to add to the template

  • description – Description for the SAM template

Returns:

Path to the generated template file

Return type:

str

class bedrock_agents_sdk.SecurityPlugin(customer_encryption_key_arn=None)[source]

Bases: AgentPlugin

Plugin for adding security features to Bedrock Agents

pre_deploy(template)[source]

Add KMS key ARN to the agent configuration in the SAM template

pre_invoke(params)[source]

Add KMS key ARN to the request parameters