autogen-ext package.
Installation
Install the extension for your chosen provider:OpenAI
TheOpenAIChatCompletionClient supports GPT-4, GPT-3.5, o1, and o3 models.
Basic Usage
Configuration Options
The model name (e.g.,
gpt-4o, gpt-4-turbo, gpt-3.5-turbo)OpenAI API key. If not provided, reads from
OPENAI_API_KEY environment variableSampling temperature between 0 and 2
Nucleus sampling parameter
Maximum tokens to generate
Request timeout in seconds
Override the default OpenAI API endpoint
Advanced Example
Azure OpenAI
TheAzureOpenAIChatCompletionClient connects to Azure OpenAI Service.
Basic Usage
Configuration Options
The Azure OpenAI endpoint URL
Azure OpenAI API version (e.g.,
2024-02-01)Your deployment name in Azure
Azure OpenAI API key
Azure Active Directory token for authentication
Azure AD Authentication
Anthropic
TheAnthropicChatCompletionClient supports Claude models.
Basic Usage
Configuration Options
Claude model name:
claude-3-5-sonnet-20241022- Most capableclaude-3-opus-20240229- Previous flagshipclaude-3-sonnet-20240229- Balancedclaude-3-haiku-20240307- Fast and compact
Anthropic API key. Falls back to
ANTHROPIC_API_KEY environment variableMaximum tokens to generate. Required for Anthropic models
Sampling temperature between 0 and 1
Nucleus sampling parameter
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:AWS region (e.g.,
us-west-2, us-east-1)AWS access key ID
AWS secret access key
AWS session token for temporary credentials
Ollama
TheOllamaChatCompletionClient connects to local Ollama instances.
Basic Usage
Configuration Options
Ollama model name (e.g.,
llama3.2, mistral, qwen2.5)Ollama server URL
Sampling temperature
Nucleus sampling parameter
Top-K sampling parameter
Context window size
Maximum tokens to generate
Advanced Configuration
Llama.cpp
Run GGUF models locally withllama.cpp:
Installation
Basic Usage
Configuration Options
Path to the GGUF model file
Context window size
Number of layers to offload to GPU
Sampling temperature
Nucleus sampling
Top-K sampling
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