Skip to main content

Workflows

Workflow = “Agents in an organized way”. Multi-step pipelines with routing, parallel execution, and loops.

Quick Start

from praisonaiagents import AgentFlow, Agent

researcher = Agent(name="Researcher", instructions="Research topics")
writer = Agent(name="Writer", instructions="Write content")

workflow = AgentFlow(steps=[researcher, writer], output="verbose")
result = workflow.start("Research and write about AI")

Workflow Parameters

ParameterTypeDefaultDescription
namestr"Workflow"Workflow name
stepslist[]Steps (Agent, function, or Task)
variablesdict{}Initial variables
default_llmstrNoneDefault LLM for all steps

Consolidated Feature Params (Workflow)

ParameterTypeDefaultDescription
outputstr | WorkflowOutputConfigNoneOutput config
planningbool | WorkflowPlanningConfigFalsePlanning mode
memorybool | WorkflowMemoryConfigNoneMemory config
hooksWorkflowHooksConfigNoneLifecycle callbacks
contextbool | ContextConfigFalseContext management
autonomybool | AutonomyConfigNoneAutonomy settings
knowledgebool | List[str] | KnowledgeConfigNoneKnowledge/RAG
guardrailsbool | Callable | GuardrailConfigNoneValidation
webbool | WebConfigNoneWeb search/fetch
reflectionbool | ReflectionConfigNoneSelf-reflection

Task Parameters

ParameterTypeDefaultDescription
namestrrequiredStep name
actionstr""Action/prompt to execute
agentAgentNoneAgent for this step
toolslistNoneTools for this step
conditionstrNoneExecution condition
loop_overstrNoneVariable to iterate over

Consolidated Feature Params (Task)

ParameterTypeDefaultDescription
contextList[str] | TaskContextConfigNoneContext from steps
outputstr | TaskOutputConfigNoneOutput handling
executionstr | TaskExecutionConfigNoneExecution control
routingList[str] | TaskRoutingConfigNoneBranching
guardrailsCallable | str | GuardrailConfigNoneValidation
autonomybool | AutonomyConfigNoneAutonomy settings
knowledgebool | List[str] | KnowledgeConfigNoneKnowledge/RAG
webbool | WebConfigNoneWeb search/fetch
reflectionbool | ReflectionConfigNoneSelf-reflection

Precedence Ladder

Resolution Order: Instance > Config > Array > Dict > String > Bool > DefaultSame precedence as Agent. Workflow params propagate to steps, step params override workflow defaults.

Where to Set Params

ParamWorkflow-levelStep-levelAgent-levelNotes
memoryWorkflow or Agent
planningWorkflow or Agent
outputStep overrides Workflow
executionStep or Agent
guardrailsStep overrides Workflow
knowledgeStep overrides Workflow
webStep overrides Workflow
reflectionStep overrides Workflow
contextStep overrides Workflow

Presets & Options

Workflow Output Presets

PresetDescription
"silent"Zero output (default)
"status"Tool calls + response, no timestamps
"trace"Full trace with timestamps
"debug"trace + metrics (no boxes)
"verbose"Rich panels with Markdown

Step Execution Presets

Presetmax_retriesquality_check
"fast"1
"balanced"3
"thorough"5

Methods

MethodDescription
start(input)Execute workflow synchronously
run(input)Alias for start()
astart(input)Execute asynchronously
arun(input)Alias for astart()

Common Recipes

Basic Workflow

from praisonaiagents import AgentFlow, Agent

workflow = AgentFlow(
    steps=[
        Agent(instructions="Research the topic"),
        Agent(instructions="Write a summary"),
    ],
    output="verbose"
)
result = workflow.start("AI trends")

Task with Context

from praisonaiagents import AgentFlow, Task

workflow = AgentFlow(
    steps=[
        Task(name="research", action="Research {{input}}"),
        Task(name="write", action="Write based on research", context=["research"]),
    ]
)

Step with Guardrails

from praisonaiagents import Task

step = Task(
    name="validate",
    action="Generate content",
    guardrails="Ensure content is safe and accurate"
)

⚠️ Gotchas

  • Step names must be unique - Used for context references
  • guardrail (singular) is deprecated - Use guardrails (plural)
  • Workflow-level params are defaults - Step-level params override them
  • Pipeline is an alias - Workflow and Pipeline are the same class

See Also

WorkflowContext

Context passed between workflow steps.
from praisonaiagents import AgentFlowContext

context = WorkflowContext(
    initial_data={"topic": "AI"},
    metadata={"user_id": "123"}
)

# Access data
context.set("key", "value")
value = context.get("key")

StepResult

Result from a workflow step.
from praisonaiagents import StepResult

result = StepResult(
    success=True,
    output="Step completed",
    metadata={"duration": 1.5}
)

WorkflowManager

Manager for complex workflow orchestration.
from praisonaiagents import AgentFlowManager

manager = WorkflowManager()
manager.register_workflow("content", content_workflow)
manager.register_workflow("analysis", analysis_workflow)

result = manager.run("content", input_data)

Pattern Helpers

Route

Conditional routing between steps.
from praisonaiagents import Route, route

# Class-based
routing = Route(
    condition=lambda ctx: ctx.get("type"),
    routes={
        "technical": technical_agent,
        "creative": creative_agent
    },
    default=general_agent
)

# Function-based
@route(condition=lambda ctx: ctx.get("type"))
def my_router(ctx):
    if ctx.get("type") == "technical":
        return technical_agent
    return general_agent

Parallel

Execute steps in parallel.
from praisonaiagents import Parallel, parallel

# Class-based
parallel_steps = Parallel(
    steps=[agent1, agent2, agent3],
    merge_strategy="combine"  # or "first", "all"
)

# Function-based
@parallel(merge_strategy="combine")
def parallel_research():
    return [web_search, database_search, api_search]

Loop

Loop until condition is met.
from praisonaiagents import Loop, loop

# Class-based
refinement_loop = Loop(
    step=refine_agent,
    condition=lambda ctx: ctx.get("quality_score", 0) < 0.9,
    max_iterations=5
)

# Function-based
@loop(max_iterations=5)
def refine_until_good(ctx):
    return ctx.get("quality_score", 0) < 0.9

Repeat

Repeat a step N times.
from praisonaiagents import Repeat, repeat

# Class-based
repeated = Repeat(
    step=generate_agent,
    times=3
)

# Function-based
@repeat(times=3)
def generate_variations():
    return generate_agent

YAML Workflows

Parse workflows from YAML files.
from praisonaiagents import YAMLWorkflowParser

parser = YAMLWorkflowParser()
workflow = parser.parse("workflow.yaml")
result = workflow.run()

YAML Format

name: Content Pipeline
steps:
  - name: research
    agent: researcher
    task: Research the topic
    
  - name: write
    agent: writer
    task: Write article
    depends_on: research
    
  - name: review
    agent: reviewer
    task: Review and edit
    depends_on: write

Usage Examples

Sequential Workflow

from praisonaiagents import AgentFlow, Agent

researcher = Agent(name="Researcher")
writer = Agent(name="Writer")
editor = Agent(name="Editor")

workflow = AgentFlow(steps=[
    {"agent": researcher, "task": "Research {topic}"},
    {"agent": writer, "task": "Write article based on research"},
    {"agent": editor, "task": "Edit and polish the article"}
])

result = workflow.run(topic="Machine Learning")

Conditional Workflow

from praisonaiagents import AgentFlow, Route

workflow = AgentFlow(steps=[
    {"agent": classifier, "task": "Classify the request"},
    Route(
        condition=lambda ctx: ctx.get("category"),
        routes={
            "technical": technical_agent,
            "billing": billing_agent,
            "general": general_agent
        }
    )
])

Parallel Processing

from praisonaiagents import AgentFlow, Parallel

workflow = AgentFlow(steps=[
    {"agent": planner, "task": "Create research plan"},
    Parallel(steps=[
        {"agent": web_researcher, "task": "Search web"},
        {"agent": db_researcher, "task": "Search database"},
        {"agent": api_researcher, "task": "Query APIs"}
    ]),
    {"agent": synthesizer, "task": "Combine all research"}
])

Loop with Refinement

from praisonaiagents import AgentFlow, Loop

workflow = AgentFlow(steps=[
    {"agent": generator, "task": "Generate initial draft"},
    Loop(
        step={"agent": refiner, "task": "Improve the draft"},
        condition=lambda ctx: ctx.get("score", 0) < 0.9,
        max_iterations=3
    ),
    {"agent": finalizer, "task": "Finalize output"}
])