Agent Tasks

Understanding how agents handle and manage tasks

Tasks define what agents should do. In PraisonAI, you can give tasks directly to agents or use the Task class for complex workflows.

Diagram

Task Flow

๐Ÿ“‹ Define Task

๐Ÿค– Assign Agent

โšก Execute

โœ… Result


Quick Start

Simple Way – Direct Task

python
from praisonaiagents import Agent

agent = Agent(instructions="You are a research assistant")
agent.start("Research the latest AI trends")  # This is the task

Advanced Way – Task Class

python
from praisonaiagents import Agent, Task, AgentTeam

researcher = Agent(instructions="Research topics")
writer = Agent(instructions="Write summaries")

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

team = AgentTeam(agents=[researcher, writer], tasks=[task1, task2])
team.start()

Task Options

OptionDescriptionExample
descriptionWhat to do"Research AI trends"
agentWho does itresearcher
expected_outputWhat to produce"Summary report"
contextPrevious tasks to use[task1]
output_fileSave result to file"report.md"

Task Types

Diagram

Task Types

๐Ÿ” Research
Find information

โœ๏ธ Create
Generate content

๐Ÿ“Š Analyze
Process data

๐Ÿ’ฌ Interact
Chat with users


Task Dependencies

Tasks can use results from previous tasks:

Diagram

Task Chain

๐Ÿ“‹ Task 1
Research

๐Ÿ“‹ Task 2
Analyze

๐Ÿ“‹ Task 3
Write

python
from praisonaiagents import Agent, Task, AgentTeam

researcher = Agent(instructions="Research topics")
analyst = Agent(instructions="Analyze data")
writer = Agent(instructions="Write reports")

# Task 1: Research
task1 = Task(
    description="Research renewable energy trends",
    agent=researcher
)

# Task 2: Uses Task 1's output
task2 = Task(
    description="Analyze the research findings",
    agent=analyst,
    context=[task1]  # Gets task1's result
)

# Task 3: Uses Task 2's output
task3 = Task(
    description="Write a summary report",
    agent=writer,
    context=[task2],
    output_file="report.md"  # Save to file
)

team = AgentTeam(agents=[researcher, analyst, writer], tasks=[task1, task2, task3])
team.start()

Complete Example

python
from praisonaiagents import Agent, Task, AgentTeam

# Create specialized agents
researcher = Agent(
    name="Researcher",
    instructions="Find accurate information on topics",
    web=True
)

writer = Agent(
    name="Writer",
    instructions="Write clear, engaging content"
)

# Define tasks
research_task = Task(
    description="Research the benefits of solar energy",
    expected_output="Key facts and statistics",
    agent=researcher
)

writing_task = Task(
    description="Write a blog post about solar energy benefits",
    expected_output="500-word blog post",
    agent=writer,
    context=[research_task],
    output_file="solar-blog.md"
)

# Run the workflow
team = AgentTeam(
    agents=[researcher, writer],
    tasks=[research_task, writing_task],
    process="sequential"
)

result = team.start()

Best Practices

Be Specific

“Research AI trends in healthcare” is better than “Research AI”

One Goal Per Task

Split complex work into multiple focused tasks

Use Context

Connect related tasks with context=[previous_task]

Define Expected Output

Tell the agent what format you want


Next: Creating Your First Agent

Build a complete agent application step by step.