Orchestration

Choose the right orchestration pattern for your AI agents

Agent Orchestration

PraisonAI provides two orchestration patterns for multi-agent systems. Choose based on your mental model.

Diagram

AgentFlow

AgentFlow

Step 1

Step 2

Step 3

AgentTeam

AgentTeam

Task 1

Task 2

Agent A

Agent B

Quick Decision Guide

Comparison

FeatureAgentTeamAgentFlow
Mental Model“Who does what”“What happens next”
Unit of WorkTask + AgentStep (Agent/function)
Sequentialprocess="sequential"Default behavior
Parallelprocess="parallel"parallel([...])
Conditionaltask.condition={...}route({...}), when()
Looptask.loop_over="items"loop(step, over="items")
Hierarchical✅ manager_llm❌ Not available
Repeat Until❌ Not available✅ repeat(step, until=...)
Composition❌ Not available✅ include(workflow=...)

AgentTeam

Best for task-centric workflows where you think in terms of “who does what task”.

python
from praisonaiagents import Agent, AgentTeam, Task

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

task1 = Task(description="Research AI trends", agent=researcher)
task2 = Task(description="Write article", agent=writer)

team = AgentTeam(
    agents=[researcher, writer],
    tasks=[task1, task2],
    process="sequential"  # or "parallel", "hierarchical"
)
result = team.start()

Hierarchical Mode

Use a manager agent to validate and coordinate:

python
team = AgentTeam(
    agents=[researcher, writer, editor],
    tasks=[task1, task2, task3],
    process="hierarchical",
    manager_llm="gpt-4o-mini"
)
Diagram

validate

validate

validate

Manager Agent

Task 1

Task 2

Task 3

AgentFlow

Best for flow-centric pipelines where you think in terms of “what happens in sequence”.

python
from praisonaiagents import Agent, AgentFlow

researcher = Agent(instructions="Research topics")
writer = Agent(instructions="Write content")
editor = Agent(instructions="Edit content")

flow = AgentFlow(steps=[researcher, writer, editor])
result = flow.start("Write about AI")

Patterns

Route

Branch based on output:

python
from praisonaiagents import AgentFlow, route

flow = AgentFlow(steps=[
    classifier,
    route({
        "positive": [celebrate],
        "negative": [escalate],
        "default": [log]
    })
])

Parallel

Execute concurrently:

python
from praisonaiagents import AgentFlow, parallel

flow = AgentFlow(steps=[
    parallel([researcher1, researcher2, researcher3]),
    aggregator
])

Loop

Iterate over items:

python
from praisonaiagents import AgentFlow, loop

flow = AgentFlow(
    steps=[loop(processor, over="items")],
    variables={"items": ["a", "b", "c"]}
)

Repeat

Repeat until condition:

python
from praisonaiagents import AgentFlow, repeat

flow = AgentFlow(steps=[
    repeat(
        improver,
        until=lambda ctx: "done" in ctx.previous_result,
        max_iterations=5
    )
])

Same Use Case, Different APIs

Sequential: Research → Write → Edit
AgentTeam
team = AgentTeam(
    agents=[researcher, writer, editor],
    tasks=[
        Task(description="Research AI", agent=researcher),
        Task(description="Write article", agent=writer),
        Task(description="Edit article", agent=editor),
    ],
    process="sequential"
)
result = team.start()
AgentFlow
flow = AgentFlow(steps=[researcher, writer, editor])
result = flow.start("Research AI")
Parallel Execution
AgentTeam
team = AgentTeam(
    agents=[a, b, c],
    tasks=[Task(..., agent=a), Task(..., agent=b), Task(..., agent=c)],
    process="parallel"
)
AgentFlow
flow = AgentFlow(steps=[
    parallel([a, b, c]),
    aggregator
])

Shared Features

Both support the same consolidated parameters:

ParameterDescription
memoryMemory configuration
planningPlanning mode
contextContext management
outputOutput configuration
hooksLifecycle callbacks
autonomyAgent autonomy
knowledgeRAG configuration
guardrailsValidation
webWeb search/fetch
reflectionSelf-reflection
cachingCaching

Best Practices

  1. Start Simple

    Use AgentFlow for simple sequential pipelines. It’s cleaner.

  2. Add Patterns

    Use route(), parallel(), loop() for complex flows.

  3. Use AgentTeam for DAGs

    When you need explicit task dependencies or hierarchical validation.

  4. Don't Mix

    Pick one pattern per workflow. Don’t nest AgentTeam in AgentFlow.

Related