Skip to main content

AgentsGenerator Module

The AgentsGenerator module generates and runs agents from YAML configuration files, supporting multiple frameworks.

Supported Frameworks

  • PraisonAI Agents (recommended)
  • CrewAI
  • AutoGen
  • AutoGen v4

Import

from praisonai.agents_generator import AgentsGenerator

Quick Example

from praisonai.agents_generator import AgentsGenerator

# From YAML file
generator = AgentsGenerator("agents.yaml")
result = generator.run()
print(result)

# From YAML string
yaml_config = """
agents:
  - name: Researcher
    role: Research Specialist
    goal: Research topics thoroughly
    
tasks:
  - agent: Researcher
    task: Research AI trends
"""
generator = AgentsGenerator(yaml_config)
result = generator.run()

Constructor

AgentsGenerator(config, framework)

Creates a new AgentsGenerator instance. Parameters:
ParameterTypeDefaultDescription
configstrRequiredPath to YAML file or YAML string
frameworkstr"praisonai"Framework to use

YAML Configuration

Basic Structure

agents:
  - name: AgentName
    role: Agent Role
    goal: Agent Goal
    backstory: Agent Backstory (optional)
    tools:
      - tool_name
    llm: gpt-4o-mini (optional)

tasks:
  - agent: AgentName
    task: Task description
    expected_output: Expected output format (optional)

Full Example

framework: praisonai
topic: AI Research

agents:
  - name: Researcher
    role: Senior Research Analyst
    goal: Uncover cutting-edge developments in AI
    backstory: >
      You are a seasoned researcher with expertise in AI.
    tools:
      - web_search
      - wikipedia
    llm: gpt-4o

  - name: Writer
    role: Tech Content Writer
    goal: Write engaging technical content
    backstory: >
      You are an experienced tech writer.
    tools:
      - file_write

tasks:
  - agent: Researcher
    task: Research the latest AI developments
    expected_output: A comprehensive report

  - agent: Writer
    task: Write a blog post based on the research
    expected_output: A 1000-word blog post

Methods

run()

Run the configured agents and tasks. Returns: str - The final output
generator = AgentsGenerator("agents.yaml")
result = generator.run()

generate_agents()

Generate agent instances without running. Returns: list - List of agent instances

generate_tasks()

Generate task instances without running. Returns: list - List of task instances

Framework Selection

PraisonAI (Default)

framework: praisonai

agents:
  - name: Agent
    role: Role
    goal: Goal

CrewAI

framework: crewai

agents:
  - name: Agent
    role: Role
    goal: Goal

AutoGen

framework: autogen

agents:
  - name: Agent
    role: Role
    goal: Goal

Tools Configuration

Built-in Tools

agents:
  - name: Agent
    tools:
      - web_search
      - wikipedia
      - file_read
      - file_write
      - calculator

Custom Tools

agents:
  - name: Agent
    tools:
      - custom_tool_name
    
tools:
  custom_tool_name:
    type: function
    function:
      name: custom_tool_name
      description: Tool description
      parameters:
        type: object
        properties:
          param1:
            type: string
            description: Parameter description

Example: Programmatic Usage

from praisonai.agents_generator import AgentsGenerator

# Create configuration programmatically
config = {
    "agents": [
        {
            "name": "Researcher",
            "role": "Research Specialist",
            "goal": "Research topics",
            "tools": ["web_search"]
        }
    ],
    "tasks": [
        {
            "agent": "Researcher",
            "task": "Research AI trends"
        }
    ]
}

import yaml
yaml_str = yaml.dump(config)

generator = AgentsGenerator(yaml_str)
result = generator.run()