> ## Documentation Index
> Fetch the complete documentation index at: https://docs.relayhub.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent Chains

> Connect multiple agents into multi-step workflows

## What Are Agent Chains?

Agent Chains let you connect multiple agents into a sequential workflow where the output of one agent feeds into the next. Instead of manually copying results between conversations, you define a chain once and run it as a single operation.

A typical chain might look like:

1. **Research Agent** gathers information from attached documents
2. **Analysis Agent** evaluates the findings and identifies key insights
3. **Report Agent** produces a formatted summary for stakeholders

Each agent in the chain operates with its own system prompt, model, and tools, but receives context from the previous step automatically.

## Creating a Chain

<Steps>
  <Step title="Open Agent Chains">
    In the Agent Hub, switch to the **Chains** tab and click **New Chain**.
  </Step>

  <Step title="Add agents to the chain">
    Select agents in the order they should execute. Drag to reorder if needed. Each agent becomes a step in the pipeline.
  </Step>

  <Step title="Configure step handoffs">
    For each step, define what context passes forward. By default, the full output of the previous agent is included. You can add a handoff instruction to tell the next agent how to interpret the incoming context -- for example, *"The following is a list of extracted data points. Analyze them for trends."*
  </Step>

  <Step title="Set the initial input">
    Define what the chain expects as its starting input. This could be a user prompt, an attached file, or both.
  </Step>

  <Step title="Save the chain">
    Give the chain a name and description. It appears in the Chains tab of Agent Hub, ready to execute.
  </Step>
</Steps>

## Execution Flow

When you run a chain, RelayHub executes each step sequentially. The conversation view shows each agent's contribution as a distinct section, so you can see exactly what each step produced.

```
[User Input] --> Agent 1 --> Agent 2 --> Agent 3 --> [Final Output]
```

Each agent runs to completion before the next one starts. If an agent uses tools (file analysis, data queries, web search), those tool calls execute within that step. The full output -- including any tool results -- is passed forward as context to the next agent.

<Note>
  Chains run within a single conversation. You can scroll through the full execution history and see each agent's reasoning, tool usage, and output in order.
</Note>

## Human-in-the-Loop Intervention

For chains that involve critical decisions, you can enable **human-in-the-loop** checkpoints at any step. When execution reaches a checkpoint, the chain pauses and waits for your review before continuing.

<Tabs>
  <Tab title="Pause">
    When a checkpoint step completes, the chain pauses. You see the agent's output and can review it before the next step begins. A notification bar appears with options to continue, edit, or cancel.
  </Tab>

  <Tab title="Resume">
    After reviewing the paused output, click **Continue** to proceed to the next step. If you want to adjust the output before it passes forward, edit the text inline -- the modified version is what the next agent receives.
  </Tab>

  <Tab title="Cancel">
    Click **Cancel** to stop the chain entirely. All completed steps remain visible in the conversation, but no further agents execute. Use this if an early step produced results that make the rest of the chain unnecessary or incorrect.
  </Tab>
</Tabs>

<Tip>
  Enable checkpoints after steps where accuracy matters most -- data extraction, financial calculations, or any step where an error would compound through later agents. You do not need a checkpoint at every step.
</Tip>

## Monitoring Execution Status

While a chain is running, the conversation interface shows a progress indicator with:

* **Current step** -- which agent is actively processing
* **Completed steps** -- green checkmarks for finished steps
* **Pending steps** -- grayed-out steps that have not started yet
* **Elapsed time** -- how long the chain has been running

If a step fails (for example, a tool call encounters an error), the chain pauses at that step and surfaces the error. You can retry the failed step or cancel the chain.

## Best Practices

* **Keep chains focused.** Three to five steps is the sweet spot. Chains with many steps accumulate context and can hit model token limits.
* **Use specific handoff instructions.** Telling the next agent what to expect produces better results than passing raw output without guidance.
* **Test each agent independently first.** Make sure every agent in the chain works well on its own before connecting them. A weak link in the chain degrades the entire output.
* **Use checkpoints for irreversible actions.** If a step triggers an automation or creates a file, add a checkpoint before it so you can verify the data first.
