> ## Documentation Index
> Fetch the complete documentation index at: https://docs.neosantara.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# AutoGen (AG2)

> Build conversational multi-agent systems and automated code workflows using Neosantara and AG2.

[AG2](https://ag2.ai/?utm_source=neosantara-docs\&utm_medium=referral) (formerly AutoGen) is an open-source framework for building multi-agent conversational systems. It enables LLM-driven agents to converse with one another, execute code, and complete complex software engineering tasks collaboratively.

## Setup

Install the `autogen` package:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
pip install -U autogen
```

```bash Bash / zsh icon="terminal" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
export NEOSANTARA_API_KEY="nsk_your_api_key_here"
```

```env .env icon="file-code" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
NEOSANTARA_API_KEY=nsk_your_api_key_here
```

```powershell PowerShell icon="terminal" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
$env:NEOSANTARA_API_KEY="nsk_your_api_key_here"
```

## LLM Configuration

AutoGen uses a `config_list` dictionary array to define provider endpoints. Point `base_url` to Neosantara and set `api_type: "openai"`.

```python theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
import os

config_list = [
    {
        "model": "deepseek-v4.1-flash",
        "base_url": "https://api.neosantara.xyz/v1",
        "api_key": os.environ["NEOSANTARA_API_KEY"],
        "api_type": "openai"
    }
]
```

## Two-Agent Collaboration Example

The following example configures an `AssistantAgent` acting as a backend architect and a `UserProxyAgent` acting as an engineering lead verifying the plan:

```python theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
import os
from autogen import AssistantAgent, UserProxyAgent

config_list = [
    {
        "model": "deepseek-v4.1-flash",
        "base_url": "https://api.neosantara.xyz/v1",
        "api_key": os.environ["NEOSANTARA_API_KEY"],
        "api_type": "openai"
    }
]

assistant = AssistantAgent(
    name="Architect",
    llm_config={"config_list": config_list},
    system_message="You are a senior backend architect. Propose a concise distributed database architecture and conclude your reply with 'TERMINATE' once the design is complete."
)

user_proxy = UserProxyAgent(
    name="Engineer",
    human_input_mode="NEVER",
    max_consecutive_auto_reply=2,
    is_termination_msg=lambda msg: "TERMINATE" in msg.get("content", "")
)

user_proxy.initiate_chat(
    assistant,
    message="What is the recommended Postgres sharding strategy for an analytics table tracking hundreds of millions of events?"
)
```

## AutoGen Collaboration Patterns

| Pattern | Key Classes | Ideal Scenario |
| :- | :- | :- |
| **Two-Agent Chat** | `AssistantAgent` + `UserProxyAgent` | Direct code generation, technical review, or guided brainstorming |
| **GroupChat** | `GroupChat` + `GroupChatManager` | Multi-role workflows (e.g. Planner, Coder, Validator) |
| **Code Execution** | `LocalCommandLineCodeExecutor` | Sandboxed local Python testing and automated iteration |

## Next Steps

* [CrewAI Integration Guide](https://docs.neosantara.xyz/en/integrations/crewai.md)
* [Model Context Protocol (MCP)](https://docs.neosantara.xyz/en/agents/overview.md)
* [Model Catalog and Pricing](https://docs.neosantara.xyz/en/gateway/models.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.