Skip to main content
Model clients provide the interface between AutoGen agents and large language models. AutoGen supports multiple LLM providers through the autogen-ext package.

Installation

Install the extension for your chosen provider:

OpenAI

The OpenAIChatCompletionClient supports GPT-4, GPT-3.5, o1, and o3 models.

Basic Usage

Configuration Options

string
required
The model name (e.g., gpt-4o, gpt-4-turbo, gpt-3.5-turbo)
string
OpenAI API key. If not provided, reads from OPENAI_API_KEY environment variable
float
default:"1.0"
Sampling temperature between 0 and 2
float
default:"1.0"
Nucleus sampling parameter
int
Maximum tokens to generate
float
default:"60.0"
Request timeout in seconds
string
Override the default OpenAI API endpoint

Advanced Example

Azure OpenAI

The AzureOpenAIChatCompletionClient connects to Azure OpenAI Service.

Basic Usage

Configuration Options

string
required
The Azure OpenAI endpoint URL
string
required
Azure OpenAI API version (e.g., 2024-02-01)
string
required
Your deployment name in Azure
string
Azure OpenAI API key
string
Azure Active Directory token for authentication

Azure AD Authentication

Anthropic

The AnthropicChatCompletionClient supports Claude models.

Basic Usage

Configuration Options

string
required
Claude model name:
  • claude-3-5-sonnet-20241022 - Most capable
  • claude-3-opus-20240229 - Previous flagship
  • claude-3-sonnet-20240229 - Balanced
  • claude-3-haiku-20240307 - Fast and compact
string
Anthropic API key. Falls back to ANTHROPIC_API_KEY environment variable
int
required
Maximum tokens to generate. Required for Anthropic models
float
default:"1.0"
Sampling temperature between 0 and 1
float
Nucleus sampling parameter
int
Only sample from top K options

Extended Thinking (Claude 3.5 Sonnet)

Claude 3.5 Sonnet supports extended thinking mode:

AWS Bedrock

Use Claude models through AWS Bedrock:
string
AWS region (e.g., us-west-2, us-east-1)
string
AWS access key ID
string
AWS secret access key
string
AWS session token for temporary credentials

Ollama

The OllamaChatCompletionClient connects to local Ollama instances.

Basic Usage

Configuration Options

string
required
Ollama model name (e.g., llama3.2, mistral, qwen2.5)
string
default:"http://localhost:11434"
Ollama server URL
float
Sampling temperature
float
Nucleus sampling parameter
int
Top-K sampling parameter
int
Context window size
int
Maximum tokens to generate

Advanced Configuration

Llama.cpp

Run GGUF models locally with llama.cpp:

Installation

Basic Usage

Configuration Options

string
required
Path to the GGUF model file
int
default:"2048"
Context window size
int
default:"0"
Number of layers to offload to GPU
float
default:"0.8"
Sampling temperature
float
default:"0.95"
Nucleus sampling
int
default:"40"
Top-K sampling
int
default:"512"
Maximum tokens to generate

Azure AI

Connect to Azure AI model deployments:

Streaming Responses

All model clients support streaming:

Model Capabilities

Query model capabilities:

Token Counting

Count tokens before sending requests:

Usage Tracking

Track token usage from responses:

Error Handling

Handle common errors:

Environment Variables

Model clients respect standard environment variables:

Best Practices

Use Environment Variables

Store API keys in environment variables instead of hardcoding:

Set Timeouts

Always configure appropriate timeouts:

Monitor Usage

Track token usage to manage costs:

Next Steps

Code Executors

Set up code execution environments

Tools

Add tools and capabilities to agents