Agents are the core building blocks of PraisonAI. Each agent is an autonomous AI entity with specific roles, goals, and capabilities.

Understanding Agents

Key Components

Role & Goal

Defines the agent’s purpose and objectives through role definition and specific goals

Capabilities

Tools and functions available to the agent for task execution

Memory

Context retention and learning capabilities across interactions

Language Model

The underlying AI model powering the agent’s intelligence

Component Details

Role and Goal

Clear role and goal definitions are crucial for optimal agent performance.

ComponentDescriptionExample
RoleAgent’s function and expertiseResearch Analyst, Code Developer
GoalSpecific objectives to achieveAnalyze market trends, Generate reports
BackstoryContextual backgroundExpert with 10 years of experience

Capabilities

Agent Types

1

Basic Agent

  • Single-purpose focus
  • Direct user interaction
  • Limited tool set
2

Specialized Agent

  • Domain expertise
  • Advanced capabilities
  • Custom tools
3

Collaborative Agent

  • Team interaction
  • Task delegation
  • Shared context

Best Practices

Always implement proper error handling and resource management in your agent configurations.

Agent Design

  1. Clear role definition
  2. Specific, measurable goals
  3. Relevant tool selection
  4. Appropriate memory configuration

Agent Interaction

  1. Clear communication protocols
  2. Defined delegation rules
  3. Error handling mechanisms
  4. Resource management

Advanced Features

Memory Management

  • Short-term conversation memory
  • Long-term knowledge retention
  • Context preservation

Tool Integration

  • Custom tool development
  • External API integration
  • Resource access control

Async Support

Agents now support asynchronous operations through the following methods:

  • achat: Async version of the chat method
  • astart: Async version of start method
  • aexecute_task: Async version of execute_task method
  • arun_task: Async version of run_task method
  • arun_all_tasks: Async version of run_all_tasks method

Example Usage:

import asyncio
from praisonaiagents import Agent, Task, PraisonAIAgents

async def main():
    # Create an async agent
    async_agent = Agent(
        name="AsyncAgent",
        role="Async Task Specialist",
        goal="Perform async operations",
        backstory="Expert in async operations",
        tools=[async_search_tool],  # Your async tool
        verbose=True
    )

    # Create an async task
    async_task = Task(
        description="Perform async operation",
        expected_output="Async result",
        agent=async_agent,
        async_execution=True  # Enable async execution
    )

    # Create and start agents with async support
    agents = PraisonAIAgents(
        agents=[async_agent],
        tasks=[async_task],
        verbose=True
    )
    
    # Start async execution
    result = await agents.astart()
    print(result)

# Run the async main function
if __name__ == "__main__":
    asyncio.run(main())

Key Features:

  • Full async/await support
  • Parallel task execution
  • Async tool integration
  • Async callback support
  • Mixed sync/async operations

Next Steps

Was this page helpful?