<!-- source: https://deepwiki.com/MervinPraison/PraisonAI/13.2-autogen-integration -->

# AutoGen Integration

- .github/workflows/build-image.yml
- .github/workflows/coverage.yml
- .github/workflows/python-package.yml
- .github/workflows/test-comprehensive.yml
- .github/workflows/test-core.yml
- .github/workflows/test-extended.yml
- .github/workflows/test-frameworks.yml
- .github/workflows/test-real.yml
- .github/workflows/unittest.yml
- .gitignore
- src/praisonai/praisonai/README.md
- src/praisonai/tests/test.py
- src/praisonai/tests/test_runner.py
- src/praisonai/tests/unit/test_cli_features.py

This document describes PraisonAI's integration with the AutoGen multi-agent conversation framework. PraisonAI supports both AutoGen v0.2 and v0.4, providing a unified interface for creating and orchestrating AutoGen agents through YAML configuration files.

For information about other framework integrations, see [CrewAI Integration](/MervinPraison/PraisonAI/11.1-testing-framework). For general agent system architecture, see [Core Agent System](/MervinPraison/PraisonAI/2-core-agent-system).

## AutoGen Framework Support

PraisonAI provides comprehensive support for AutoGen through the `AgentsGenerator` class, which handles both legacy v0.2 and modern v0.4 AutoGen implementations. The system automatically detects available AutoGen versions and selects the appropriate execution path.

**Supported AutoGen Versions:**

**Version Selection Logic:**
The system uses environment variable `AUTOGEN_VERSION` or automatic detection to choose between versions. Default preference is v0.4 when available, with fallback to v0.2.

Sources: [src/praisonai/praisonai/agents_generator.py42-56](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/agents_generator.py#L42-L56) [src/praisonai/praisonai/agents_generator.py370-384](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/agents_generator.py#L370-L384)

## AutoGen Integration Architecture

```

```

Sources: [src/praisonai/praisonai/agents_generator.py364-407](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/agents_generator.py#L364-L407) [src/praisonai/praisonai/agents_generator.py409-587](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/agents_generator.py#L409-L587)

## YAML Configuration Structure

AutoGen agents are configured through YAML files with the following structure:

```

```

The `AgentsGenerator` processes this configuration and creates corresponding AutoGen agents with appropriate system messages and tool configurations.

Sources: [src/praisonai/praisonai/agents_generator.py309-320](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/agents_generator.py#L309-L320)

## AutoGen v0.2 Implementation

The v0.2 implementation uses the traditional AutoGen conversation pattern with `AssistantAgent` and `UserProxyAgent`:

```

```

**Key Components:**

- autogen.AssistantAgent : Created with llm_config containing model configuration
- autogen.UserProxyAgent : Configured with code execution capabilities and termination conditions
- user_proxy.initiate_chats() : Orchestrates sequential task execution

Sources: [src/praisonai/praisonai/agents_generator.py409-480](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/agents_generator.py#L409-L480)

## AutoGen v0.4 Implementation

The v0.4 implementation uses the modernized event-driven architecture with async execution:

```

```

**Key Features:**

- Agent Name Sanitization : sanitize_agent_name_for_autogen_v4() ensures valid Python identifiers
- Async Execution : Full async/await pattern with asyncio.run()
- Model Client : OpenAIChatCompletionClient for LLM communication
- Group Chat : RoundRobinGroupChat for multi-agent coordination
- Termination Conditions : Configurable stopping criteria

Sources: [src/praisonai/praisonai/agents_generator.py482-587](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/agents_generator.py#L482-L587) [src/praisonai/praisonai/agents_generator.py87-119](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/agents_generator.py#L87-L119)

## Tool Integration

AutoGen agents can utilize PraisonAI's tool ecosystem through framework-specific adapters:

**v0.2 Tool Integration:**

- Tools are registered as functions with autogen_{ToolClassName} naming convention
- Tool functions are called via AutoGen's function calling mechanism
- Tools are attached to both AssistantAgent and UserProxyAgent

**v0.4 Tool Integration:**

- Tools are passed directly to AutoGenV4AssistantAgent constructor
- Tool instances must have callable run methods
- Tools are integrated into the agent's tool registry

**Available Tool Categories:**

- Search Tools: CodeDocsSearchTool , WebsiteSearchTool
- File Tools: FileReadTool , DirectoryReadTool
- Data Tools: CSVSearchTool , JSONSearchTool
- Web Tools: ScrapeWebsiteTool , ScrapeElementFromWebsiteTool

Sources: [src/praisonai/praisonai/agents_generator.py450-459](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/agents_generator.py#L450-L459) [src/praisonai/praisonai/agents_generator.py516-522](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/agents_generator.py#L516-L522)

## CLI and Direct Usage

AutoGen integration is accessible through multiple interfaces:

**CLI Usage:**

```

```

**Python API:**

```

```

**Direct Prompt Handling:**
For direct prompts, the system creates a simple AutoGen conversation between `AssistantAgent` and `UserProxyAgent` with the specified model configuration.

Sources: [src/praisonai/praisonai/cli.py759-774](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/cli.py#L759-L774) [src/praisonai/praisonai/cli.py551](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/cli.py#L551-L551)

## Environment Configuration

AutoGen integration supports flexible model configuration through environment variables:

The system creates a `config_list` compatible with AutoGen's expected format, ensuring seamless integration with existing AutoGen workflows.

Sources: [src/praisonai/praisonai/cli.py124-145](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/cli.py#L124-L145) [src/praisonai/praisonai/agents_generator.py386-388](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/agents_generator.py#L386-L388)

## Error Handling and Validation

The AutoGen integration includes comprehensive error handling:

**Framework Validation:**

- Checks for AutoGen package availability during AgentsGenerator initialization
- Provides clear error messages with installation instructions
- Supports graceful fallback between versions

**Agent Name Sanitization:**

- Converts agent names to valid Python identifiers for v0.4 compatibility
- Handles special characters, keywords, and empty names
- Prevents naming conflicts with Python reserved words

**Execution Error Handling:**

- Wraps async execution with try-catch blocks
- Provides detailed error messages for debugging
- Maintains system stability during agent failures

Sources: [src/praisonai/praisonai/agents_generator.py172-177](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/agents_generator.py#L172-L177) [src/praisonai/praisonai/agents_generator.py574-587](https://github.com/MervinPraison/PraisonAI/blob/ab80807b/src/praisonai/praisonai/agents_generator.py#L574-L587)
