> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Workflow History & Continuous Execution

> Build workflows that reference previous runs across multiple executions using workflow history.

v2.1.4 (Introduced in v2.1.4)

Workflow History enables your Agno workflows to remember and reference previous conversations, transforming isolated executions into continuous, context-aware interactions.

Instead of starting fresh each time, with Workflow History you can:

* **Build on previous interactions** - Reference the context of past interactions
* **Avoid repetitive questions** - Avoid requesting previously provided information
* **Maintain context continuity** - Create a conversational experience
* **Learn from patterns** - Analyze historical data to make better decisions

> [!TIP]
>
> This feature is different from `add_history_to_context`.
> It adds the full workflow history to either all or some steps, rather than the history of a particular agent or team.

## How It Works

When workflow history is enabled, previous messages are automatically injected into agent/team inputs as structured context:

```xml theme={null}
<workflow_history_context>
[Workflow Run-1]
User input: Create content about AI in healthcare
Workflow output: # AI in Healthcare: Transforming Patient Care...

[Workflow Run-2]
User input: Make it more family-focused
Workflow output: # AI in Family Healthcare: A Parent's Guide...

</workflow_history_context>

Your current input goes here...
```

Along with this, in using Steps with custom functions, you can access this history in the following ways:

1. As a formatted context string as shown above
2. In a structured format as well for more control

```python theme={null}
[
    ("<workflow input from run 1>", "<workflow output from run 1>"),
    ("<workflow input from run 2>", "<workflow output from run 2>"),
]
```

> [!NOTE]
>
> A database is required to use Workflow history. Runs across different executions will be persisted there.

Example:

```python theme={null}
def custom_function(step_input: StepInput) -> StepOutput:
    # Option 1: Structured data for analysis
    history_tuples = step_input.get_workflow_history(num_runs=3)
    for user_input, workflow_output in history_tuples:
        ...  # Process each conversation turn

    # Option 2: Formatted context for agents
    context_string = step_input.get_workflow_history_context(num_runs=3)

    return StepOutput(content="Analysis complete")
```

> [!NOTE]
>
> You can use these helper functions to access the history:
>
> * `step_input.get_workflow_history(num_runs=3)`
> * `step_input.get_workflow_history_context(num_runs=3)`

Refer to [StepInput](https://agno-v2.mintlify.site/reference/workflows/step_input.md) reference for more details.

## Control Levels

You can be specific about which Steps to add the history to:

### Workflow-Level History

Add workflow history to **all steps** in the workflow:

```python theme={null}
workflow = Workflow(
    steps=[research_step, analysis_step, writing_step],
    add_workflow_history_to_steps=True  # All steps get history
)
```

### Step-Level History

Add workflow history to **specific steps** only:

```python theme={null}
Step(
    name="Content Creator",
    agent=content_agent,
    add_workflow_history=True  # Only this step gets history
)
```

> [!NOTE]
>
> You can also put `add_workflow_history=False` to disable history for a specific step.

## Precedence Logic

**Step-level settings always take precedence over workflow-level settings**:

```python theme={null}
workflow = Workflow(
    steps=[
        Step("Research", agent=research_agent),                              # None → inherits workflow setting
        Step("Analysis", agent=analysis_agent, add_workflow_history=False),  # False → overrides workflow
        Step("Writing", agent=writing_agent, add_workflow_history=True),     # True → overrides workflow
    ],
    add_workflow_history_to_steps=True  # Default for all steps
)
```

### History Length Control

**By default, each step receives the last 3 runs** (`num_history_runs=3`). Keep this limit small to avoid bloating the LLM context window.

You can control this at both levels:

```python theme={null}
# Workflow-level: limit history for all steps
workflow = Workflow(
    add_workflow_history_to_steps=True,
    num_history_runs=5  # Only last 5 runs
)

# Step-level: override for specific steps
Step("Analysis", agent=analysis_agent,
     add_workflow_history=True,
     num_history_runs=3  # Only last 3 runs for this step
)
```

## Developer Resources

> **[Single Step Continuous Execution](https://agno-v2.mintlify.site/history/workflow/single-step-continuous-execution-workflow.md)**
>
> Single step workflow with continuous execution and history awareness.

> **[Workflow History for Steps](https://agno-v2.mintlify.site/history/workflow/workflow-with-history-enabled-for-steps.md)**
>
> Add workflow history to all steps in the workflow.

> **[Enable History for Specific Step](https://agno-v2.mintlify.site/history/workflow/enable-history-for-step.md)**
>
> Enable workflow history for a specific step only.

> **[Get History in Function](https://agno-v2.mintlify.site/history/workflow/get-history-in-function.md)**
>
> Access workflow history in custom functions for analysis.

> **[Multi-Purpose CLI](https://agno-v2.mintlify.site/history/workflow/multi-purpose-cli.md)**
>
> Add workflow history to the steps of a multi-purpose CLI workflow.

> **[Intent Routing](https://agno-v2.mintlify.site/history/workflow/intent-routing-with-history.md)**
>
> Route requests to specialist agents that share the same conversation history.


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