Skip to content

Chain Agent

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({
name: 'Agent 1',
description: '..AGENT DESCRIPTION..'
});
const agent2 = new BedrockLLMAgent({
name: 'Agent 2',
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.',
agents: [agent1, agent2]
});

Intermediate Example

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({
name: 'Agent 1',
description: '..AGENT DESCRIPTION..'
});
const agent2 = new BedrockLLMAgent({
name: 'Agent 2',
description: '..AGENT DESCRIPTION..',
streaming: true
});
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.'
});

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({
name: 'Agent 1',
description: '..AGENT DESCRIPTION..'
});
const agent2 = new BedrockLLMAgent({
name: 'Agent 2',
description: '..AGENT DESCRIPTION..',
streaming: true
});
const options: ChainAgentOptions = {
name: 'AdvancedChainAgent',
description: 'A sophisticated chain of agents with all options',
agents: [agent1, agent2],
defaultOutput: 'The chain processing encountered an issue.',
saveChat: true
};
const chainAgent = new 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);

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.