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.
graph LR
subgraph "Task Flow"
Define[๐ Define Task] --> Assign[๐ค Assign Agent]
Assign --> Execute[โก Execute]
Execute --> Result[โ
Result]
end
classDef define fill:#8B0000,stroke:#7C90A0,color:#fff
classDef agent fill:#189AB4,stroke:#7C90A0,color:#fff
classDef result fill:#2E8B57,stroke:#7C90A0,color:#fff
class Define define
class Assign,Execute agent
class Result resultQuick 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
graph TB
subgraph "Task Types"
Research[๐ Research<br/>Find information]
Create[โ๏ธ Create<br/>Generate content]
Analyze[๐ Analyze<br/>Process data]
Interact[๐ฌ Interact<br/>Chat with users]
end
classDef research fill:#8B0000,stroke:#7C90A0,color:#fff
classDef create fill:#189AB4,stroke:#7C90A0,color:#fff
classDef analyze fill:#2E8B57,stroke:#7C90A0,color:#fff
classDef interact fill:#F59E0B,stroke:#7C90A0,color:#fff
class Research research
class Create create
class Analyze analyze
class Interact interactResearch
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:
graph LR
subgraph "Task Chain"
T1[๐ Task 1<br/>Research] --> T2[๐ Task 2<br/>Analyze]
T2 --> T3[๐ Task 3<br/>Write]
end
classDef task fill:#189AB4,stroke:#7C90A0,color:#fff
class T1,T2,T3 taskfrom 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.