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

# Sequential Patterns

> Build multi-agent pipelines where agents execute in sequence and pass structured data between them

Sequential patterns in workflow architecture allow you to build multi-agent pipelines where agents execute in a predefined order. Each agent processes data and passes its output to the next agent in the chain.

## Sequential Execution

In sequential patterns, agents execute one after another in a fixed order. You define explicit edges to control the flow:

```yaml theme={null}
architecture: "workflow"

edges:
  - from: "__start__"
    to: "agent_a"
  - from: "agent_a"
    to: "agent_b"
  - from: "agent_b"
    to: "__end__"
```

> [!NOTE]
>
> Sequential patterns are ideal when you have a clear, linear workflow and want each agent to build on the previous agent's output.

## Core Concepts

### Special Nodes

* **`__start__`** (or `START`): Entry point — first agent receives user input
* **`__end__`** (or `END`): Exit point — final agent's output is returned to user

Both forms are accepted and normalized internally. You can use either `__start__`/`__end__` or `START`/`END` in your YAML.

Every workflow must have a path from `__start__` to `__end__`.

### Entry Point

The `entry_point` field specifies which agent runs first:

* **Agent name** (e.g., `"assistant"`): An edge from `__start__` to this agent is added automatically. You can still define an explicit `__start__ → agent` edge, but it's not required.
* **`"START"`**: No automatic edge is created. You must define your own edge from `__start__` (useful for [conditional routing from start](https://docs.artaios.ai/amas/advanced/conditional-edges.md#conditional-routing-from-start)).

### Passing Data Between Agents

Each agent in the sequence receives the previous agent's output. You can access it in two ways:

**1. Direct access (free-form text):**
The previous agent's output is automatically available in the agent's context.

**2. Structured output (typed data):**
Define schemas for agent outputs and reference specific fields in subsequent agents.

> [!NOTE]
>
> **Learn more about structured output:** [Structured Output →](https://docs.artaios.ai/amas/advanced/structured-output.md)

## Basic Sequential Chain

### Single Agent Flow

```yaml theme={null}
name: "Basic Assistant"
description: "Simple conversational assistant"
architecture: "workflow"
save_messages: true
persistent_state: true

agents:
  - name: "assistant"
    agent_type: "llm_agent"
    description: "A helpful AI assistant"
    system_prompt: "You are a helpful AI assistant."
    
    llm_config:
      temperature: 0.7
      max_tokens: 500
    
    streaming_config:
      show_output_to_user: true

edges:
  - from: "__start__"
    to: "assistant"
  - from: "assistant"
    to: "__end__"

entry_point: "assistant"
```

**Flow:**

```
START → Assistant → END
```

### Sequential Chain with Structured Output

Using structured output for reliable data passing:

```yaml theme={null}
name: "Sentiment Analysis Pipeline"
description: "Analyze → Classify → Respond based on sentiment"
architecture: "workflow"
save_messages: true
persistent_state: true

agents:
  - name: "analyzer"
    agent_type: "llm_agent"
    description: "Analyzes sentiment of user input"
    
    structured_output:
      enabled: true
      schema:
        sentiment:
          type: "str"
          description: "Sentiment category: positive, negative, or neutral"
        confidence:
          type: "float"
          description: "Confidence score between 0.0 and 1.0"
        key_topics:
          type: "list[str]"
          description: "Main topics mentioned in the input"
    
    prompt_config:
      system_prompt: |
        Analyze the sentiment and extract key topics from user input.
    
    streaming_config:
      show_output_to_user: true

  - name: "responder"
    agent_type: "llm_agent"
    description: "Generates response based on sentiment analysis"
    
    prompt_config:
      system_prompt: |
        Sentiment: {{ analyzer.output.sentiment }}
        Confidence: {{ analyzer.output.confidence }}
        Topics: {{ analyzer.output.key_topics }}
        
        Generate an appropriate response based on the sentiment analysis.
        For positive sentiment, be enthusiastic. For negative, be empathetic.
    
    streaming_config:
      show_output_to_user: true

edges:
  - from: "__start__"
    to: "analyzer"
  - from: "analyzer"
    to: "responder"
  - from: "responder"
    to: "__end__"

entry_point: "analyzer"
```

**Flow:**

```
START → Analyzer (structured output) → Responder (uses analyzer.output.*) → END
```

> [!TIP]
>
> The `responder` agent accesses the analyzer's structured output using template variables: `{{ analyzer.output.sentiment }}`, `{{ analyzer.output.confidence }}`, etc.

## Research → Analysis Pipeline

Multi-agent workflow where a ReAct agent uses tools to gather data with structured output, then an LLM agent analyzes the findings:

```yaml theme={null}
name: "Research and Analysis Pipeline"
description: "Research with tools → Structured analysis → Insights"
architecture: "workflow"
save_messages: true
persistent_state: true

agents:
  - name: "researcher"
    agent_type: "react_agent"
    description: "Gathers information using web search"
    
    tools:
      - "tavily_search"
    
    tool_calling:
      enabled: true
      max_iterations: 5
    
    structured_output:
      enabled: true
      schema:
        key_findings:
          type: "list[str]"
          description: "Main findings from research"
        sources:
          type: "list[str]"
          description: "URLs of sources used"
        confidence:
          type: "float"
          description: "Confidence in findings (0.0-1.0)"
    
    prompt_config:
      system_prompt: |
        Research the topic using web search. Extract key findings and sources.
    
    streaming_config:
      show_output_to_user: true
      show_reasoning: true

  - name: "analyst"
    agent_type: "llm_agent"
    description: "Analyzes research findings and generates insights"
    
    prompt_config:
      system_prompt: |
        ## Research Findings
        {{ researcher.output.key_findings }}
        
        ## Sources
        {{ researcher.output.sources }}
        
        ## Confidence Level
        {{ researcher.output.confidence }}
        
        Based on the research above, provide:
        1. Key insights and patterns
        2. Recommendations
        3. Potential concerns or limitations
    
    streaming_config:
      show_output_to_user: true

edges:
  - from: "__start__"
    to: "researcher"
  - from: "researcher"
    to: "analyst"
  - from: "analyst"
    to: "__end__"

entry_point: "researcher"
```

**Flow:**

```
START → Researcher (tools + structured output) → Analyst (uses researcher.output.*) → END
```

> [!TIP]
>
> The `researcher` agent uses `tavily_search` to gather data and outputs structured findings. The `analyst` agent then references `{{ researcher.output.key_findings }}` and other fields to generate insights.

## When to Use Sequential Patterns

> [!TIP]
>
> **Use sequential patterns when:**
>
> * You have a clear, linear workflow
> * Each step depends on the previous step's output
> * You want type-safe data passing between agents
> * The execution order is predictable

> [!NOTE]
>
> **For dynamic routing**, see [Supervisor Pattern →](https://docs.artaios.ai/amas/advanced/supervisor-pattern.md) or [Conditional Edges →](https://docs.artaios.ai/amas/advanced/conditional-edges.md)

## Best Practices

> [!TIP]
>
> **Use structured output for data dependencies**: When an agent needs specific fields from a previous agent, define a schema to ensure type safety and validation.

> [!TIP]
>
> **Reference outputs explicitly**: Use `{{ agent_name.output.field }}` in prompts to access structured data from previous agents.

> [!TIP]
>
> **Stream intermediate results**: Set `show_output_to_user: true` on agents you want users to see during execution.

> [!WARNING]
>
> Every workflow must have a path from `__start__` to `__end__`. Ensure all agents are reachable.

> [!TIP]
>
> **Set `recursion_limit`**: For workflows with conditional edges that loop back, increase `recursion_limit` (default: 5) to allow enough iterations. Example: `recursion_limit: 20`.

> [!TIP]
>
> **Keep schemas simple**: Start with basic types (`str`, `int`, `float`, `bool`) before using complex nested structures.

## Advanced Patterns

For more complex routing logic:

> **[Conditional Edges](https://docs.artaios.ai/amas/advanced/conditional-edges.md)**
>
> Add dynamic routing based on agent output

> **[Supervisor Pattern](https://docs.artaios.ai/amas/advanced/supervisor-pattern.md)**
>
> Use intelligent task delegation instead of fixed edges

## Common Use Cases

> **Content Pipeline**
>
> **Pattern**: Sequential chain
>
> Research → Draft → Edit → Publish
>
> Each agent specializes in one stage of content creation.

> **Data Processing Pipeline**
>
> **Pattern**: Sequential chain with tools
>
> Collector (web search) → Analyzer (calculator) → Reporter (synthesis)
>
> Each agent uses specific tools for its task.

> **Sentiment Analysis Pipeline**
>
> **Pattern**: Sequential with structured output
>
> Analyzer (structured output) → Responder (uses analyzer data)
>
> First agent produces typed data, second agent consumes it via template variables.

> **Quality Assurance Flow**
>
> **Pattern**: Sequential with conditional edges
>
> Writer → Reviewer → \[Approve → Publish | Reject → Writer]
>
> Add conditional edges for dynamic routing based on quality checks.

## Next Steps

> **[Conditional Edges](https://docs.artaios.ai/amas/advanced/conditional-edges.md)**
>
> Add dynamic routing to workflows

> **[Supervisor Pattern](https://docs.artaios.ai/amas/advanced/supervisor-pattern.md)**
>
> Learn about supervisor-based coordination

> **[Agent Types](https://docs.artaios.ai/amas/agent_config/types_config/agent-types.md)**
>
> Understand different agent types for workflows

> **[YAML Configuration](https://docs.artaios.ai/amas/yaml-configuration.md)**
>
> Complete reference for workflow configuration


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.