Supported Model Providers in AgentScope: Configuration Guide and Code Examples
AgentScope supports nine major LLM providers—OpenAI, Azure OpenAI, Anthropic, Google Gemini, Alibaba DashScope, Ollama, DeepSeek, Moonshot, and AWS Bedrock—through a unified ChatModelBase interface that standardizes authentication and request handling.
AgentScope is a multi-agent framework that abstracts diverse language model APIs behind a consistent Python interface. When you instantiate a model, the framework uses provider-name mapping logic defined in the tracing utilities to identify the vendor and generate appropriate telemetry attributes. Understanding the supported model providers in AgentScope and their configuration patterns is essential for building robust agent workflows.
Overview of Supported Model Providers
AgentScope currently integrates with the following providers, each mapped to a specific implementation class and identified by a unique provider key:
- OpenAI (
openaiortrinity): Implemented inOpenAIChatModelinsrc/agentscope/model/_openai_model.py. Supports models likegpt-4oandgpt-3.5-turbo. - Azure OpenAI (
azure_ai_openai): UsesOpenAIChatModelwith a custombase_urlpointing to your Azure endpoint. - Alibaba DashScope (
dashscope): Implemented inDashScopeChatModelinsrc/agentscope/model/_dashscope_model.py. Supportsqwen-maxand DeepSeek models. - DeepSeek (
deepseek): Uses the DashScope implementation viaDashScopeChatModelwith DeepSeek-specific model names. - Anthropic (
anthropic): Implemented inAnthropicChatModelinsrc/agentscope/model/_anthropic_model.py. Supports Claude models likeclaude-3-opus-20240229. - Google Gemini (
gemini): Implemented inGeminiChatModelinsrc/agentscope/model/_gemini_model.py. - Ollama (
ollama): Implemented inOllamaChatModelinsrc/agentscope/model/_ollama_model.pyfor local deployment. - Moonshot AI (
moonshot): UsesOpenAIChatModelwith an OpenAI-compatible API endpoint. - AWS Bedrock (
aws_bedrock): UsesOpenAIChatModelwith Bedrock's OpenAI-compatible endpoint.
The provider enumeration is defined in src/agentscope/tracing/_attributes.py within the ProviderNameValues enum, while the resolution logic resides in src/agentscope/tracing/_extractor.py.
How AgentScope Detects Providers
When you create a model instance, AgentScope determines the provider through a cascading inspection process defined in src/agentscope/tracing/_extractor.py (lines 31-48):
- Class Name Inspection: The extractor first examines the concrete model class (e.g.,
OpenAIChatModel,DashScopeChatModel). - Base URL Fragment Analysis: For generic implementations like
OpenAIChatModel, the framework inspects thebase_urlparameter for known fragments (api.openai.com,openai.azure.com,dashscope, etc.) to resolve ambiguous cases. - Telemetry Attribution: The resolved provider name is stored in the
GEN_AI_PROVIDER_NAMEspan attribute for OpenTelemetry tracing, as defined insrc/agentscope/tracing/_attributes.py(lines 153-182).
This detection mechanism enables AgentScope to distinguish between OpenAI and Azure OpenAI even when both use the same underlying class.
Common Configuration Parameters
All model classes inherit from ChatModelBase and accept the following standardized arguments:
model_name: The provider-specific model identifier (e.g.,gpt-4o,qwen-max).api_key: Authentication token. If omitted, the class automatically reads from standard environment variables (OPENAI_API_KEY,DASHSCOPE_API_KEY,ANTHROPIC_API_KEY, etc.) as implemented in each model's__init__method.base_url(optional): Override the default API endpoint. Required for Azure OpenAI, custom OpenAI-compatible servers, and certain third-party providers.**kwargs: Provider-specific parameters (e.g.,temperature,max_tokens) passed directly to the underlying SDK client.
In src/agentscope/model/_openai_model.py (line 91), the OpenAIChatModel class explicitly implements the fallback logic: api_key=os.environ.get("OPENAI_API_KEY").
Provider Configuration Examples
OpenAI
Configure OpenAI models using the OpenAIChatModel class. The framework automatically reads OPENAI_API_KEY from your environment if not provided explicitly.
from agentscope.model import OpenAIChatModel
model = OpenAIChatModel(
model_name="gpt-4o-mini",
api_key="sk-your-openai-key", # Optional: falls back to OPENAI_API_KEY env var
temperature=0.7,
)
response = model.chat(messages=[{"role": "user", "content": "Hello!"}])
print(response.content)
Azure OpenAI
Azure deployments require the base_url parameter pointing to your Azure OpenAI endpoint, along with the api_version parameter.
from agentscope.model import OpenAIChatModel
model = OpenAIChatModel(
model_name="gpt-4o",
api_key="your-azure-key",
base_url="https://my-resource.openai.azure.com/",
api_version="2024-02-01",
)
Alibaba DashScope
DashScope provides access to Qwen models. Configure using DashScopeChatModel with your DASHSCOPE_API_KEY.
from agentscope.model import DashScopeChatModel
model = DashScopeChatModel(
model_name="qwen-max",
api_key="your-dashscope-key", # Optional: falls back to DASHSCOPE_API_KEY
temperature=0.5,
)
DeepSeek via DashScope
DeepSeek models are accessed through the DashScope provider using the same DashScopeChatModel class with DeepSeek-specific model identifiers.
from agentscope.model import DashScopeChatModel
model = DashScopeChatModel(
model_name="deepseek-chat",
api_key="your-dashscope-key",
)
Anthropic Claude
Configure Anthropic models using AnthropicChatModel, which reads ANTHROPIC_API_KEY from the environment by default.
from agentscope.model import AnthropicChatModel
model = AnthropicChatModel(
model_name="claude-3-opus-20240229",
api_key="your-anthropic-key", # Optional: falls back to ANTHROPIC_API_KEY
max_tokens=1024,
)
Google Gemini
Gemini models require the GeminiChatModel class and a GEMINI_API_KEY environment variable or explicit parameter.
from agentscope.model import GeminiChatModel
model = GeminiChatModel(
model_name="gemini-1.5-pro",
api_key="your-gemini-key", # Optional: falls back to GEMINI_API_KEY
)
Ollama Local Deployment
Ollama enables local inference without API keys. The OllamaChatModel connects to your local Ollama server.
from agentscope.model import OllamaChatModel
model = OllamaChatModel(
model_name="llama3",
temperature=0.8,
# base_url defaults to http://localhost:11434 if not specified
)
Moonshot AI
Moonshot uses an OpenAI-compatible API, allowing configuration through OpenAIChatModel with a custom base_url.
from agentscope.model import OpenAIChatModel
model = OpenAIChatModel(
model_name="moonshot-v1-8k",
api_key="your-moonshot-key",
base_url="https://api.moonshot.cn/v1",
)
Summary
- AgentScope unifies nine providers—OpenAI, Azure OpenAI, Anthropic, Gemini, DashScope, DeepSeek, Ollama, Moonshot, and AWS Bedrock—behind the
ChatModelBaseinterface. - Provider detection occurs via class inspection in
src/agentscope/tracing/_extractor.pyand URL fragment analysis, storing results inGEN_AI_PROVIDER_NAMEattributes defined insrc/agentscope/tracing/_attributes.py. - Configuration requires
model_nameand optionallyapi_key(with automatic environment variable fallback) andbase_urlfor custom endpoints. - Implementation classes like
OpenAIChatModel,DashScopeChatModel, andAnthropicChatModelhandle provider-specific SDK initialization while exposing a consistent.chat()interface.
Frequently Asked Questions
How do I switch between different providers in AgentScope?
Import the specific model class for your provider (e.g., AnthropicChatModel for Anthropic, DashScopeChatModel for Alibaba) and instantiate it with the appropriate model_name and credentials. All classes share the same .chat() method signature, so you can swap implementations without changing your agent conversation logic.
Can I use local models without API keys in AgentScope?
Yes. The OllamaChatModel class supports local inference via Ollama without requiring API keys. Simply specify the model_name corresponding to your locally downloaded model (e.g., llama3), and ensure your Ollama server is running on the default port or specify a custom base_url.
How does AgentScope determine the provider name for tracing?
The framework inspects the concrete model class name and, for OpenAI-compatible implementations, analyzes the base_url for provider-specific fragments (like openai.azure.com for Azure or api.moonshot.cn for Moonshot). This logic in src/agentscope/tracing/_extractor.py maps instances to provider keys defined in src/agentscope/tracing/_attributes.py for OpenTelemetry telemetry.
What environment variables does AgentScope check for authentication?
Each model class checks for a provider-specific variable: OPENAI_API_KEY for OpenAI/Azure, DASHSCOPE_API_KEY for DashScope/DeepSeek, ANTHROPIC_API_KEY for Anthropic, and GEMINI_API_KEY for Gemini. If the api_key parameter is omitted during instantiation, the constructor automatically falls back to these environment variables as implemented in the respective _xxx_model.py files.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →