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

# AutoGen

> 通过 OpenAI 兼容客户端在 Microsoft AutoGen 中使用 AI Sonar 模型

## 概述

AutoGen 可以通过 `OpenAIChatCompletionClient` 使用 AI Sonar，这与它用于其他自定义 Chat Completions 端点的 OpenAI 兼容客户端路径相同。

<Note>
  **类型**: 智能体框架 (Agent Framework)

  **主要路径**: OpenAI 兼容的聊天补全 (Chat Completions)

  **支持置信度**: 支持的自定义端点路径
</Note>

## 安装

```bash theme={null}
pip install -U autogen-agentchat "autogen-ext[openai]" pyyaml
```

## 环境

```bash theme={null}
export API_KEY="sk-your-api-key"
```

## YAML 模型配置

将 AI Sonar 的 `/v1` 端点用作 `base_url`：

```yaml theme={null}
provider: autogen_ext.models.openai.OpenAIChatCompletionClient
config:
  model: claude-sonnet-5
  base_url: https://api.aisonar.dev/v1
  api_key: ${API_KEY}
  model_info:
    function_calling: true
    json_output: true
    vision: false
    family: claude
```

## Python 客户端

```python theme={null}
import os

from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient

model_client = OpenAIChatCompletionClient(
    model="claude-sonnet-5",
    base_url="https://api.aisonar.dev/v1",
    api_key=os.environ["API_KEY"],
    model_info={
        "function_calling": True,
        "json_output": True,
        "vision": False,
        "family": "claude",
    },
)

agent = AssistantAgent("assistant", model_client=model_client)
```

## 端点注意事项

AutoGen 的 OpenAI 扩展期望使用 OpenAI 兼容的请求格式。对于 Anthropic Messages 或 Gemini `generateContent` 等提供商原生功能，请使用直接支持这些协议的客户端调用 AI Sonar 的原生端点。
