Sequential Workflow
Execute agents one after another in a defined sequence.Overview
Copy
┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────┐
│ Research │ ─► │ Analyze │ ─► │ Write │ ─► │ Edit │
└───────────┘ └───────────┘ └───────────┘ └───────────┘
Implementation
Copy
from praisonaiagents import Agent, Task, PraisonAIAgents
# Create agents for each step
researcher = Agent(
name="Researcher",
instructions="Research the given topic thoroughly."
)
analyst = Agent(
name="Analyst",
instructions="Analyze the research and extract key insights."
)
writer = Agent(
name="Writer",
instructions="Write content based on the analysis."
)
editor = Agent(
name="Editor",
instructions="Edit and polish the written content."
)
# Create sequential tasks
tasks = [
Task(description="Research AI trends", agent=researcher),
Task(description="Analyze the research", agent=analyst),
Task(description="Write a report", agent=writer),
Task(description="Edit the report", agent=editor)
]
# Run sequentially (default)
agents = PraisonAIAgents(
agents=[researcher, analyst, writer, editor],
tasks=tasks,
process="sequential"
)
result = agents.start()
Using Workflows Module
Copy
from praisonaiagents.workflows import SequentialWorkflow
workflow = SequentialWorkflow(
agents=[researcher, analyst, writer, editor]
)
result = workflow.run("Create a report on AI trends")
With Context Passing
Each agent receives the output of the previous agent:Copy
from praisonaiagents import Task
research_task = Task(
description="Research the topic",
agent=researcher,
expected_output="Research findings"
)
analysis_task = Task(
description="Analyze the research findings",
agent=analyst,
context=[research_task], # Receives research output
expected_output="Analysis report"
)
writing_task = Task(
description="Write based on analysis",
agent=writer,
context=[analysis_task], # Receives analysis output
expected_output="Draft content"
)
editing_task = Task(
description="Edit the draft",
agent=editor,
context=[writing_task], # Receives draft
expected_output="Final content"
)
Pipeline Pattern
Copy
from praisonaiagents import Agent
def pipeline(input_text: str) -> str:
"""Run agents in a pipeline."""
# Step 1: Research
researcher = Agent(name="Researcher")
research = researcher.start(f"Research: {input_text}")
# Step 2: Analyze
analyst = Agent(name="Analyst")
analysis = analyst.start(f"Analyze this research: {research}")
# Step 3: Write
writer = Agent(name="Writer")
content = writer.start(f"Write based on: {analysis}")
# Step 4: Edit
editor = Agent(name="Editor")
final = editor.start(f"Edit this: {content}")
return final
result = pipeline("AI trends in 2024")
Related
- Workflows Module - Workflows reference
- Parallel Workflow - Parallel pattern

