Agentic Prompt Chaining

Chain agents so each step's output feeds the next

Run agents in sequence — each step receives the previous step’s output.

python
from praisonaiagents import Agent, AgentFlow

researcher = Agent(name="Researcher", instructions="Research the topic. Return facts only.")
writer = Agent(name="Writer", instructions="Turn the research into a clear summary.")

flow = AgentFlow(steps=[researcher, writer])
result = flow.start("Benefits of renewable energy")
print(result["output"])

The user submits one goal; each agent step passes its output to the next.

Diagram

Input

Step 1

Step 2

Step 3

Output

Quick Start

  1. Simple Usage

    Chain two agents with AgentFlow:

    python
    from praisonaiagents import Agent, AgentFlow
    
    researcher = Agent(name="Researcher", instructions="Research the topic.")
    writer = Agent(name="Writer", instructions="Write a summary from the research.")
    
    flow = AgentFlow(steps=[researcher, writer])
    result = flow.start("Benefits of renewable energy")
  2. With Configuration

    Add branching with route and step hooks:

    python
    from praisonaiagents import Agent, AgentFlow, route, Task
    
    classifier = Agent(name="Classifier", instructions="Classify the request as success or failure.")
    
    flow = AgentFlow(
        steps=[
            classifier,
            route({
                "success": [Agent(name="Process", instructions="Process the request.")],
                "failure": [Agent(name="Fallback", instructions="Handle the error.")],
            }),
        ],
    )

How It Works

Diagram
WriterResearcherAgentFlowUserWriterResearcherAgentFlowUserflow.start(“goal”)goalresearch outputresearch output as inputsummaryresult[“output”]

AgentFlow runs steps in order. Each agent’s reply becomes the next step’s input. Use route() for conditional paths, Task(should_run=...) to skip steps, or StepResult(stop_workflow=True) to exit early.

PatternUse when
Sequential agentsFixed pipeline (research → write → edit)
route()Branch on classifier output
should_runSkip steps based on context

Configuration Options

OptionTypeDefaultDescription
stepslist[]Agents, Task, or handler functions
processstr"sequential""sequential" or "hierarchical"
outputOutputConfigNoneVerbose, stream, and trace settings
hooksWorkflowHooksConfigNoneon_step_complete and lifecycle callbacks
memoryMemoryConfigNoneShared memory across steps

Best Practices

Keep each step focused

One role per agent — research, analyse, write, edit. Narrow instructions produce cleaner hand-offs.

Use route for decisions

Put a classifier step before route() rather than asking one agent to do everything.

Enable hooks for visibility

WorkflowHooksConfig(on_step_complete=...) logs progress without changing agent logic.

Start with two steps

Prove the pipeline with two agents, then add steps once data flow is clear.


Related