AutoGen is a development framework designed for creating AI-driven agents and orchestrating multi-agent systems.
1.1 Usage
Method 1: OpenAI-Compatible Endpoint (Recommended for AutoGen 0.2+)
from autogen_ext.models.openai import OpenAIChatCompletionClient
client = OpenAIChatCompletionClient(
model="your-model-name",
base_url="https://api.rygen.io/v1",
api_key="your-rygen-api-key",
model_info={
"vision": False,
"function_calling": True,
"json_output": True,
}
)
# Use with an agent
from autogen_agentchat import AssistantAgent
agent = AssistantAgent(
name="assistant",
model_client=client,
)Method 2: config_list (Legacy)
config_list (Legacy)import autogen
llm_config = {
"config_list": [
{
"model": "your-model-name",
"api_base": "https://api.rygen.io/v1",
"api_key": "your-rygen-api-key",
"api_type": "openai"
}
]
}
assistant = autogen.AssistantAgent(
name="assistant",
llm_config=llm_config
)Method 3: Custom Model Client (Advanced)
from autogen_core.models import ChatCompletionClient, CreateResult, LLMMessage, ModelInfo
from typing import List
class CustomModelClient(ChatCompletionClient):
def __init__(self, api_key, base_url, model, **kwargs):
self.api_key = api_key
self.base_url = base_url
self.model = model
self._model_info = ModelInfo(
vision=False,
function_calling=True,
json_output=True
)
@property
def model_info(self) -> ModelInfo:
return self._model_info
async def create(self, messages: List[LLMMessage], **kwargs) -> CreateResult:
import requests
headers = {"Authorization": f"Bearer {self.api_key}"}
payload = {
"model": self.model,
"messages": [
{"role": m.role, "content": m.content} for m in messages
]
}
response = requests.post(
f"{self.base_url}/chat/completions",
headers=headers,
json=payload
)
data = response.json()
return CreateResult(
content=data["choices"][0]["message"]["content"],
finish_reason=data["choices"][0].get("finish_reason", "stop"),
usage=data.get("usage", {})
)
client = CustomModelClient(
api_key="your-rygen-api-key",
base_url="https://api.rygen.io/v1",
model="your-model-name"
)1.2 Troubleshooting
| Issue | Fix |
|---|---|
| Version compatibility | Use autogen_ext.models.openai for AutoGen 0.2+ |
model_info errors | Ensure flags like vision, function_calling, and json_output match model capabilities |
| Async/await issues | Use the async interface required by newer AutoGen versions |

