AutoAgents Module
Documentation for the praisonaiagents.agents.autoagents module
Module praisonaiagents.agents.autoagents
The AutoAgents module provides automatic creation and management of AI agents and tasks based on high-level instructions.
Classes
AutoAgents
The main class for automatically creating and managing AI agents and tasks.
Parameters
instructions: str– High-level task description for the agentstools: Optional[List[Any]] = None– List of tools available to the agentsverbose: bool = False– Enable detailed loggingprocess: str = "sequential"– Process type (sequential or hierarchical)manager_llm: Optional[str] = None– Language model for manager agentmax_retries: int = 5– Maximum retry attemptscompletion_checker: Optional[Any] = None– Custom completion checkerallow_code_execution: bool = False– ⚠️ Deprecated — useexecution=ExecutionConfig(code_execution=True)memory: bool = True– Enable agent memorymarkdown: bool = True– Enable markdown formattingself_reflect: bool = False– Enable agent self-reflectionmax_iterations: int = 3– Maximum reflection iterationsmin_iterations: int = 1– Minimum reflection iterationsllm: Optional[str] = None– Language model for agentsfunction_calling_llm: Optional[str] = None– Language model for tool callingcontext: bool | ManagerConfig = False– Context management (True for defaults, ManagerConfig for custom)code_execution_mode: str = "safe"– ⚠️ Deprecated — useexecution=ExecutionConfig(code_mode=)embedder_config: Optional[Dict[str, Any]] = None– Embedder configurationknowledge_sources: Optional[List[Any]] = None– Knowledge sourcesuse_system_prompt: bool = True– Use system promptscache: bool = True– Enable cachingallow_delegation: bool = False– ⚠️ Deprecated — usehandoffs=insteadstep_callback: Optional[Any] = None– Callback for each stepsystem_template: Optional[str] = None– Custom system templateprompt_template: Optional[str] = None– Custom prompt templateresponse_template: Optional[str] = None– Custom response templatemax_rpm: Optional[int] = None– Maximum requests per minutemax_execution_time: Optional[int] = None– Maximum execution timemax_iter: int = 20– Maximum iterationsreflect_llm: Optional[str] = None– Language model for reflectionmax_agents: int = 3– Maximum number of agents to create
Methods
# start()
Start the agents synchronously.
def start(self):
"""
Creates tasks based on the instructions, then starts execution.
Returns the task status and results dictionary.
"""
return super().start()# astart()
Start the agents asynchronously.
async def astart(self):
"""
Async version of start() method.
Creates tasks based on the instructions, then starts execution.
Returns the task status and results dictionary.
"""
return await super().astart()Internal Methods
# _generate_config()
Generate the configuration for agents and tasks.
def _generate_config(self) -> AutoAgentsConfig:
"""
Generate the configuration for agents and tasks based on instructions.
Returns AutoAgentsConfig object containing agent and task configurations.
"""# _create_agents_and_tasks()
Create agents and tasks from configuration.
def _create_agents_and_tasks(self, config: AutoAgentsConfig) -> tuple[List[Agent], List[Task]]:
"""
Create agents and tasks based on the generated configuration.
Returns tuple of (agents, tasks).
"""# _assign_tools_to_agent()
Assign appropriate tools to an agent.
def _assign_tools_to_agent(self, agent_config: AgentConfig) -> List[Any]:
"""
Assign tools to an agent based on its role and tasks.
Returns list of assigned tools.
"""Pydantic Models
TaskConfig
Configuration for a task.
Attributes
name: str– Task namedescription: str– Task descriptionexpected_output: str– Expected output descriptiontools: List[str]– Required tools for the task
AgentConfig
Configuration for an agent.
Attributes
name: str– Agent namerole: str– Agent rolegoal: str– Agent goalinstructions: # Canonical: use 'instructions' instead of 'backstory' str– Agent backstorytools: List[str]– Required toolstasks: List[TaskConfig]– Tasks assigned to the agent
AutoAgentsConfig
Overall configuration for AutoAgents.
Attributes
main_instruction: str– Main instruction for the agentsprocess_type: str– Process type (sequential/hierarchical)agents: List[AgentConfig]– List of agent configurations
Example Usage
Basic Usage
from praisonaiagents import AutoAgents
from praisonaiagents import SerperDevTool
agents = AutoAgentTeam(
instructions="Research recent AI developments",
tools=[SerperDevTool()],
)
result = agents.start()Async Usage
async def main():
agents = AutoAgentTeam(
instructions="Research recent AI developments",
tools=[SerperDevTool()],
process="hierarchical"
)
result = await agents.astart()
import asyncio
asyncio.run(main())Advanced Configuration
agents = AutoAgentTeam(
instructions="Complex research task",
tools=[SerperDevTool()],
max_agents=5,
process="hierarchical",
manager_llm="gpt-4o",
memory=True,
max_execution_time=600,
reflection=True
)