Amazon Bedrock Flows Agent
Overview
The Bedrock Flows Agent is a specialized agent class in the Multi-Agent Orchestrator that integrates directly with Amazon Bedrock Flows. This integration enables you to orchestrate your Bedrock Flows alongside other agent types (Bedrock Agent, Lex, Bedrock API…), providing a unified and flexible approach to agents orchestration.
Key Features
- Support for cross-region Bedrock Flows invocation
- Support for multiple flow input output type via flow input/output encoder/decoder callbacks
Creating a BedrockFlowsAgent
Python Package
If you haven’t already installed the AWS-related dependencies, make sure to install them:
pip install "multi-agent-orchestrator[aws]"
Basic Example
import { BedrockFlowsAgent } from 'multi-agent-orchestrator';
const techFlowAgent = new BedrockFlowsAgent({ name: 'tech-flow-agent', description: 'Specialized in AWS services', flowIdentifier: 'AEXAMPLID', flowAliasIdentifier: 'AEXAMPLEALIASID', enableTrace:true});
from multi_agent_orchestrator.agents import BedrockFlowsAgent, BedrockFlowsAgentOptions
tech_flow_agent = BedrockFlowsAgent(BedrockFlowsAgentOptions( name="tech-flow-agent", description="Specializes in handling tech questions about AWS services", flowIdentifier='AEXAMPLID', flowAliasIdentifier='AEXAMPLEALIASID', enableTrace=True))
Flow Input Encoder callback
Amazon Bedrock Flows Input supports multiple type of document output:
- String
- Number
- Boolean
- Object
- Array
In the default definition of the BedrockFlowsAgent, the output document type is a string. If you need to send an object, array, number or a boolean to your Flow input, you can use the flow input callback to transform the input payload based on your needs.
Here are an example for TS and python:
// implementation of the custom flowInputEncoder callbackconst flowInputEncoder = (agent: Agent,input: string,kwargs: {userId?: string,sessionId?: string,chatHistory?: any[],[key: string]: any // This allows any additional properties}) => {if (agent.name == 'tech-flow-agent'){return { "question":input,};} else {return input}}
// passing flowInputEncoder to our BedrockFlowsAgentconst techFlowAgent = new BedrockFlowsAgent({name: 'tech-flow-agent',description: 'Specialized in AWS services',flowIdentifier: 'AEXAMPLID',flowAliasIdentifier: 'AEXAMPLEALIASID',flowInputEncoder: flowInputEncoder,enableTrace: true});
# implementation of the custom flowInputEncoder callbackdef flow_input_encoder(agent:Agent, input: str, **kwargs) -> Any: if agent.name == 'tech-flow-agent': # return a dict return { "question": input } else: return input #input as string
# passing flowInputEncoder to our BedrockFlowsAgenttech_flow_agent = BedrockFlowsAgent(BedrockFlowsAgentOptions( name="tech-flow-agent", description="Specializes in handling tech questions about AWS services", flowIdentifier='AEXAMPLID', flowAliasIdentifier='AEXAMPLEALIASID', flow_input_encoder=flow_input_encoder, enableTrace=True))
Sample Code
You can find sample code for using the BedrockFlowsAgent in both TypeScript and Python: