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.
Quick Start
Simple Way – Direct Task
from praisonaiagents import Agent
agent = Agent(instructions="You are a research assistant")
agent.start("Research the latest AI trends") # This is the taskAdvanced Way – Task Class
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
| Option | Description | Example |
|---|---|---|
description | What to do | "Research AI trends" |
agent | Who does it | researcher |
expected_output | What to produce | "Summary report" |
context | Previous tasks to use | [task1] |
output_file | Save result to file | "report.md" |
Task Types
Research
Find, gather, and summarize information
CreateWrite articles, reports, or content
AnalyzeProcess data and find insights
InteractAnswer questions and chat
Task Dependencies
Tasks can use results from previous tasks:
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
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.