The ChainAgent
is an agent class in the Multi-Agent Orchestrator System that allows for the sequential execution of multiple agents. It processes a request by passing the output of one agent as input to the next, creating a chain of agent interactions.
Creating a ChainAgent
Basic Example
Here’s how to create a ChainAgent with only the required parameters:
import { ChainAgent, ChainAgentOptions } from ' multi-agent-orchestrator ' ;
import { BedrockLLMAgent } from ' multi-agent-orchestrator ' ;
const agent1 = new BedrockLLMAgent ( {
description: ' ..AGENT DESCRIPTION.. '
const agent2 = new BedrockLLMAgent ( {
description: ' ..AGENT DESCRIPTION.. '
const chainAgent = new ChainAgent ( {
name: ' Chain Tech Agent ' ,
description: ' Specializes in technology areas including software development, hardware, AI, cybersecurity, blockchain, cloud computing, emerging tech innovations, and pricing/costs related to technology products and services. ' ,
from multi_agent_orchestrator.agents import ChainAgent, ChainAgentOptions
from multi_agent_orchestrator.agents import BedrockLLMAgent, BedrockLLMAgentOptions
agent1 = BedrockLLMAgent ( BedrockLLMAgentOptions (
description = ' ..AGENT DESCRIPTION.. '
agent2 = BedrockLLMAgent ( BedrockLLMAgentOptions (
description = ' ..AGENT DESCRIPTION.. '
chain_agent = ChainAgent ( ChainAgentOptions (
description = ' A simple chain of multiple agents ' ,
This example shows how to create a ChainAgent with a custom default output:
import { ChainAgent, ChainAgentOptions } from ' multi-agent-orchestrator ' ;
import { BedrockLLMAgent } from ' multi-agent-orchestrator ' ;
const agent1 = new BedrockLLMAgent ( {
description: ' ..AGENT DESCRIPTION.. '
const agent2 = new BedrockLLMAgent ( {
description: ' ..AGENT DESCRIPTION.. ' ,
const chainAgent = new ChainAgent ( {
name: ' IntermediateChainAgent ' ,
description: ' A chain of agents with custom default output ' ,
agents: [agent1, agent2] ,
defaultOutput: ' The chain encountered an issue during processing. '
from multi_agent_orchestrator.agents import ChainAgent, ChainAgentOptions
from multi_agent_orchestrator.agents import BedrockLLMAgent, BedrockLLMAgentOptions
agent1 = BedrockLLMAgent ( BedrockLLMAgentOptions (
description = ' ..AGENT DESCRIPTION.. '
agent2 = BedrockLLMAgent ( BedrockLLMAgentOptions (
description = ' ..AGENT DESCRIPTION.. '
chain_agent = ChainAgent ( ChainAgentOptions (
name = ' IntermediateChainAgent ' ,
description = ' A chain of agents with custom default output ' ,
default_output = ' The chain encountered an issue during processing. '
Advanced Example
For more complex use cases, you can create a ChainAgent with all available options:
import { ChainAgent, ChainAgentOptions } from ' multi-agent-orchestrator ' ;
import { BedrockLLMAgent } from ' multi-agent-orchestrator ' ;
const agent1 = new BedrockLLMAgent ( {
description: ' ..AGENT DESCRIPTION.. '
const agent2 = new BedrockLLMAgent ( {
description: ' ..AGENT DESCRIPTION.. ' ,
const options : ChainAgentOptions = {
name: ' AdvancedChainAgent ' ,
description: ' A sophisticated chain of agents with all options ' ,
agents: [agent1, agent2] ,
defaultOutput: ' The chain processing encountered an issue. ' ,
const chainAgent = new ChainAgent (options);
from multi_agent_orchestrator.agents import ChainAgent, ChainAgentOptions
from multi_agent_orchestrator.agents import BedrockLLMAgent, BedrockLLMAgentOptions
agent1 = BedrockLLMAgent ( BedrockLLMAgentOptions (
description = ' ..AGENT DESCRIPTION.. '
agent2 = BedrockLLMAgent ( BedrockLLMAgentOptions (
description = ' ..AGENT DESCRIPTION.. ' ,
options = ChainAgentOptions (
name = ' AdvancedChainAgent ' ,
description = ' A sophisticated chain of agents with all options ' ,
default_output = ' The chain processing encountered an issue. ' ,
chain_agent = ChainAgent ( options )
Integrating ChainAgent into the Multi-Agent Orchestrator
To integrate the ChainAgent into your Multi-Agent Orchestrator:
import { MultiAgentOrchestrator } from " multi-agent-orchestrator " ;
const orchestrator = new MultiAgentOrchestrator ();
orchestrator . addAgent (chainAgent);
from multi_agent_orchestrator.orchestrator import MultiAgentOrchestrator
orchestrator = MultiAgentOrchestrator ()
orchestrator. add_agent ( chain_agent )
Streaming Responses
The ChainAgent supports streaming responses only for the last agent in the chain.
This design ensures efficient processing through the chain while still enabling streaming capabilities for the end result.
By leveraging the ChainAgent, you can create sophisticated, multi-step processing pipelines within your Multi-Agent Orchestrator system, allowing for complex interactions and transformations of user inputs, with the added flexibility of streaming output from the final processing step.