> ## 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":"ayu-dark","dark":"catppuccin-latte"}}
pip install -U autogen
```

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

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

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

## 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":"ayu-dark","dark":"catppuccin-latte"}}
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":"ayu-dark","dark":"catppuccin-latte"}}
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](/en/integrations/crewai)
* [Model Context Protocol (MCP)](/en/agents/overview)
* [Model Catalog and Pricing](/en/gateway/models)


## Related topics

- [CrewAI](/en/integrations/crewai.md)
- [MCP & Agent Architecture](/en/agents/overview.md)
- [Model Catalog](/en/gateway/models.md)
- [Integrations Overview](/en/integrations/overview.md)
