Building a Multi-Agent System

Creating a system with multiple cooperative agents

Build a team of agents that work together – each specializing in one task for better results.

Diagram

Content Creation Team

📋 Task

🔍 Researcher

✍️ Writer

📝 Editor

✅ Polished Content


What We’ll Build

A content creation team with 3 agents:


Step-by-Step Guide

  1. Create the Agents
    python
    from praisonaiagents import Agent, AgentTeam
    
    # Agent 1: Researcher
    researcher = Agent(
        name="Researcher",
        instructions="Research topics thoroughly and provide key facts",
        web=True  # Can search the web
    )
    
    # Agent 2: Writer
    writer = Agent(
        name="Writer",
        instructions="Write engaging content based on research"
    )
    
    # Agent 3: Editor
    editor = Agent(
        name="Editor",
        instructions="Polish content for clarity and grammar"
    )
  2. Create the Team
    python
    # Combine agents into a team
    team = AgentTeam(
        agents=[researcher, writer, editor],
        process="sequential"  # One after another
    )
  3. Run the Team
    python
    result = team.start("Create a blog post about the benefits of exercise")
    print(result)

Complete Example

python
from praisonaiagents import Agent, AgentTeam

# Create specialized agents
researcher = Agent(
    name="Researcher",
    instructions="""You research topics thoroughly.
    - Find key facts and statistics
    - Identify main points
    - Organize information clearly""",
    web=True
)

writer = Agent(
    name="Writer",
    instructions="""You write engaging content.
    - Use research provided
    - Write clear, readable text
    - Include introduction and conclusion"""
)

editor = Agent(
    name="Editor",
    instructions="""You polish and improve content.
    - Fix grammar and spelling
    - Improve clarity and flow
    - Ensure consistent tone"""
)

# Create the team
team = AgentTeam(
    agents=[researcher, writer, editor],
    process="sequential"
)

# Run the team
result = team.start("Create a blog post about renewable energy")
print(result)

How It Works

Diagram

Sequential Flow

Research

Draft

📋 Topic

🔍 Researcher

✍️ Writer

📝 Editor

✅ Final Content

StepAgentWhat Happens
1ResearcherGathers information on the topic
2WriterCreates content from research
3EditorPolishes the final result

Different Team Patterns

Parallel Team

All agents work at the same time when each Task sets async_execution=True inside a workflow process and the team is started with await team.astart() — the sync team.start() runs them sequentially and warns:

python
import asyncio
from praisonaiagents import Agent, Task, AgentTeam

team = AgentTeam(
    agents=[analyst1, analyst2, analyst3],
    tasks=[
        Task(description="Analysis A", agent=analyst1, async_execution=True),
        Task(description="Analysis B", agent=analyst2, async_execution=True),
        Task(description="Analysis C", agent=analyst3, async_execution=True),
    ],
    process="workflow"  # parallel fan-out via async_execution on tasks
)

async def main():
    await team.astart()   # parallel fan-out — sync .start() would run sequentially and warn

asyncio.run(main())

Hierarchical Team

Manager coordinates workers:

python
manager = Agent(instructions="Coordinate the team")
worker1 = Agent(instructions="Handle research")
worker2 = Agent(instructions="Handle writing")

team = AgentTeam(
    agents=[manager, worker1, worker2],
    process="hierarchical"
)

Best Practices

Clear Roles

Each agent should have one specific job

Simple Instructions

Keep agent instructions focused and clear

Start with 2-3 Agents

Don’t overcomplicate – add more only when needed

Test Each Agent First

Make sure each agent works alone before combining


Next: Building Conversational Agents

Learn how to create agents that remember conversations.