模型抽象层

一句话总结
用统一接口屏蔽不同 LLM provider(OpenAI / Anthropic / 本地模型 / 国产模型…)的差异:聊天、流式、函数调用、多模态、token 计数。让上层 agent 逻辑与具体模型解耦、可切换。

它解决什么问题

各家 API 形态不一、能力不一。抽象层让你”一次编写、多模型运行”,并便于做成本/质量权衡与回退。

设计维度 / 实现谱系

  • 覆盖广度:单一 provider ↔ 几家主流 ↔ 100+(PraisonAI 借 LiteLLM)
  • 能力面:纯文本 ↔ 流式 ↔ 原生 function calling ↔ 多模态 ↔ 结构化输出
  • 本地/边缘:是否支持本地推理 / WASM 浏览器内运行(Ailoy
  • 统一程度:薄封装(暴露原始差异)↔ 厚抽象(统一消息/工具格式)
  • 回退/路由:失败切换、按任务路由到不同模型

关键要点

  • 很多框架直接复用 LiteLLM 等聚合层,而非自己适配每家。
  • 是否支持原生 function calling 显著影响 工具调用的可靠性。
  • 本地/WASM 支持是”随处运行”类框架的差异化点。

关联

各框架实现对比

下表汇总 46 个实现了「模型抽象」的框架(源码级阅读结论)。网站上以可展开 + 源码节选呈现。

框架实现方式
Aeon模型名为字符串,三级覆盖:workflow_dispatch 入参 > per-skill model: > aeon.yml 顶层 model:(默认 claude-opus-4-8)。Gateway 路由:gateway.provider: bankr 时改写 ANTHROPIC_BASE_URL=https://llm.bankr.bot 解锁 Gemini/GPT/Kimi/Qwen;或 vars.ANTHROPIC_BASE_URL 接任意 Anthropic 兼容端点
AG2ModelClient 是 Protocol(须实现 create/message_retrieval/cost/get_usage);OpenAIWrapper 按 config 的 api_type 路由到各 provider client(openai/azure/anthropic/gemini/bedrock/mistral/groq/cohere/ollama/together/cerebras/deepseek 等);统一以 OpenAI ChatCompletion 格式为内部协议;支持 config_list 故障转移与 register_model_client 自定义
Agency Swarm直接复用 SDK 的 Model/ModelSettings;默认 gpt-5.4-mini,OpenAI 走 OpenAIResponsesModel,其它厂商(Claude/Gemini/Grok/Azure/OpenRouter)经可选 LitellmModel(litellm extra)路由
Agent-LLM (AGiXT)provider = CATEGORY=“AI Provider” 的 extension,按 services()(llm/tts/image/embeddings/vision…)分类自动发现;get_providers_by_service 路由;内置 OpenAI/Anthropic/Gemini/Azure/DeepSeek/HuggingFace/ezlocalai 等(extensions/.py)
AgentDockCoreLLM 统一封装 Vercel AI SDK LanguageModel,暴露 generateText/streamText/generateObject 等;createLLM 工厂 + ProviderRegistry 按 provider 路由 adapter(anthropic/openai/google/groq/deepseek/cerebras);支持 primary+fallback 双 LLM
AgentField经 LiteLLM 统一 100+ LLM provider(AIConfig(model=“anthropic/…”));app.ai(schema=…) 通过 system prompt 注入 schema 指令 + LiteLLM response_format=json_schema 双保险得到 typed 输出;支持 stream、多模态(image/audio)、temperature 等
Agentic Context Engine (ACE)经 PydanticAI 统一;resolve_model() 把 LiteLLM 风格模型名路由到 PydanticAI 原生 provider 或 litellm: 代理(100+ provider:OpenAI/Anthropic/Google/Bedrock/Groq…);可按角色分别配模型(ACEModelConfig)
AgentScopeChatModelBase 抽象 async call(messages, tools, tool_choice),统一 stream/重试/count_tokens/context_size;8 家实现(Anthropic/DashScope/DeepSeek/Gemini/Ollama/OpenAIChat/OpenAIResponse/XAI/Moonshot);各家配套 formatter/ 把 Msg+block 转 provider 报文;credential/ 解耦密钥
Agentset全栈基于 Vercel AI SDK(generateText/streamText/embed/generateObject);LLM 经 Azure 网关按名映射(gpt-4.1/gpt-5),embedding 工厂支持 Azure/OpenAI/Voyage/Google,按 namespace 配置动态 import
AgentVerseBaseLLM 抽象(generate_response/agenerate_response/get_spend,统一返回 LLMResult)+ llm_registry;主实现 OpenAIChat(含 Azure 分支);本地模型经 vLLM / FSChat 走 OpenAI 兼容端点,LOCAL_LLMS/LOCAL_LLMS_MAPPING 列表登记
AiloyLangModel 包 LangModelInner::{Local, StreamAPI, Custom}(src/model/language_model.rs:184),统一 LangModelInference trait(infer / infer_delta,src/model/language_model.rs:135)。Local=TVM;StreamAPI 经 APISpecification 枚举支持 ChatCompletion/OpenAI(Responses)/Gemini/Claude/Grok(src/model/api/mod.rs:36);EmbeddingModel 同构(本地/远程)
Astron AgentBaseLLMModel(默认走 OpenAI 兼容 AsyncOpenAI.chat.completions)+ ProviderLLMModel 子类按 provider 适配:AnthropicLLMModel(/v1/messages + SSE 归一化)、GoogleLLMModel(generateContent SSE);OpenAI 兼容白名单含 deepseek/doubao/qwen/zhipu/moonshot/minimax 等;create_model() 按 provider 字符串分发
AutoGenChatCompletionClient 抽象基类定义 create/create_stream/model_info(ModelInfo TypedDict 描述 vision/function-calling/family 等能力);统一 LLMMessage(System/User/Assistant/FunctionExecutionResult)与 CreateResult;具体 OpenAI/Azure/Anthropic 等 client 在 autogen-ext
BotpressCognitive 客户端封装多 provider:best/fast/auto 预设或 integration:model-id ModelRef;按 tag/价格/vendor 打分排序;provider 宕机自动标 degraded 并回退下一个模型(5 分钟);统一 generateContent
ConnectOnionLLM 抽象基类 + create_llm() 工厂按模型名前缀路由;OpenAI/Anthropic/Gemini/Groq/Grok/Mistral/OpenRouter/OpenOnion(co/);OpenAI message 格式为 lingua franca,统一 ToolCall dataclass
Cortex MemoryLLMClient trait(llm/client.rs) + EmbeddingClient(embedding/client.rs:334 embed,:364 embed_batch),均走 OpenAI 兼容 HTTP 端点;底层依赖 rig-core 0.31(Cargo.toml:41);模型在 config.toml 配 model_efficient/model_reasoning
CrewAIBaseLLM 抽象基类 + LLM.new 工厂按 provider/model 前缀路由:openai/anthropic/azure/bedrock/gemini 走原生 SDK,其余回退 LiteLLM;create_llm 统一构造
Dust两层:新 front 原生 LLM router getLLM 按 modelId 路由到各 provider 客户端(Anthropic/OpenAI/Google/Mistral/xAI/Fireworks/Noop);旧 core 的 LLM trait + provider 实现(迁移中)
Haystack基于 Protocol(鸭子类型)而非基类:ChatGenerator 协议仅要求 run(messages)->dict、返回 replies: list[ChatMessage];OpenAI/Azure/HF 内置,其余厂商在 haystack-core-integrations;ChatMessage/ToolCall 为统一数据格式;FallbackChatGenerator 多模型故障转移
Hermes Agent声明式 ProviderProfile dataclass(auth/endpoint/api_mode/quirks),插件式注册(plugins/model-providers//,用户插件 last-writer-wins 可覆盖内置);底座是 OpenAI SDK,另带 anthropic/bedrock/gemini-native/codex-responses 等专属 adapter;hermes model 一条切换、credential pool 多 key 轮换、无代码改动
HiveLLMProvider ABC(acomplete/stream,统一 LLMResponse 含 token/cost);实现:LiteLLM(100+ provider,含 ollama 本地)、原生 Anthropic、Antigravity、Mock;model_catalog.py 管定价
LagentBaseLLM/AsyncBaseLLM 定义 chat/generate/stream_chat;LMTemplateParser 用 meta_template 把对话拼成模型专属字符串;多 provider wrapper:GPTAPI、ClaudeAPI、HFTransformer、VllmModel、LMDeploy、Sensenova;AsyncOpenAIWrapper.chat 直接返回原生 ChatCompletion(含 tool_calls)
LangChainBaseChatModel(core) 为统一接口,暴露 invoke/stream/bind_tools/with_structured_output;init_chat_model(“provider:model”) 按前缀懒加载 partner 实现(_BUILTIN_PROVIDERS 表覆盖 anthropic/openai/google/groq/ollama…);模型可整体互换
Llama Agentic System (llama-stack-apps)模型抽象在服务端 Inference API;客户端按 model_id 字符串选模型,client.models.list() 发现可用模型(区分 model_type==“llm” 与含 “guard” 的安全模型)。模型族=Llama 3.1/3.2 等
LlamaIndexBaseLLM→LLM→FunctionCallingLLM 三层抽象;统一 ChatMessage/ChatResponse 与 block 化多模态;achat_with_tools/get_tool_calls_from_response/predict_and_call 抹平各家 function calling;300+ provider 在 integrations 包;Settings.llm 全局默认
llm-agents单一 ChatLLM pydantic 类,硬编码调用 OpenAI 旧版 openai.ChatCompletion.create;只暴露 model/temperature,无多 provider 路由、无统一消息抽象(单条 user message)
LoongFlowBaseLLMModel 抽象 + LiteLLMModel 默认实现,底层走 LiteLLM,统一 CompletionRequest/CompletionResponse,async generator 支持流式;from_config 读 model/url/api_key,默认 provider=openai(如 openai/gemini-3-pro-preview);ClaudeCodeAgent 另走 Anthropic 兼容端点
Maestromaestro.py 直接绑定 Anthropic SDK;跨 provider 抽象在 maestro-anyapi.py 经 LiteLLM completion() 统一 OpenAI-style 接口(Anthropic/OpenAI/Gemini/Cohere…),另有 groq/ollama/lmstudio 专用变体
Mastra字符串 provider/model 经 ModelRouterLanguageModel 解析(gateway-resolver + provider-registry.json,覆盖 40+ provider),统一为 AI SDK v5/v6 LanguageModelV2;也接受直接传入 AI SDK model 实例;resolveModelConfig 兜底 v4 包装;支持 model fallbacks / retries
MetaGPTBaseLLM 抽象基类(aask/acompletion/acompletion_text)+ @register_provider 按 LLMType 注册,create_llm_instance 工厂按 api_type 路由;内置 OpenAI/Azure/Anthropic/Gemini/Ollama/Bedrock/Qianfan/Zhipu/Spark/Dashscope/Ark 等十余 provider;统一 OpenAI message 格式
Modus泛型接口 Model[TIn,TOut]{Info();Invoke(in)} + GetModelTModel 工厂;按 manifest 名解析,Invoke 经 host function hostInvokeModel 走 Runtime 调用 provider;内置 OpenAI/Anthropic/Gemini/Meta-Llama 及 experimental 分类/嵌入封装
nanobotLLMProvider ABC(OpenAI message 为通用格式,统一 LLMResponse/ToolCallRequest);factory.make_provider 按 provider backend 路由:openai_compat/anthropic/azure/bedrock/github_copilot/openai_codex/openai_responses;FallbackProvider 做多模型 failover,原生 openai+anthropic SDK(已弃用 litellm)
Open Multi-AgentLLMAdapter 接口(chat+stream) + createAdapter() 懒加载工厂,按 provider 名路由;12 内置 provider + 任意 OpenAI 兼容端点(baseURL);统一 thinking 配置映射到 Anthropic thinking / Gemini thinkingConfig / OpenAI reasoning_effort;Vercel AI SDK 经 AISdkAdapter 桥接
OpenClaw两层:packages/llm-core 定义统一 Model 接口(api/provider/cost/contextWindow/thinkingLevelMap) 与 StreamFn;packages/llm-runtime/api-registry.ts 按 model.api 注册/路由 provider 适配器;src/llm/providers/ 实现 OpenAI(completions/responses/chatgpt)/Anthropic/Google(+Vertex)/Mistral/Azure/Copilot 等;OAuth 订阅(ChatGPT/Codex)走 src/llm/oauth.ts,支持 auth profile 轮换与 failover
Pipecat服务基类体系 AIService→LLMService/STTService/TTSService/VisionService;60+ provider 实现(openai/anthropic/google/groq…);BaseLLMAdapter(泛型)把统一 LLMContext/ToolsSchema 转成各家 provider 的 messages/tools 格式
PraisonAILLM 类包一层 LiteLLM,覆盖 100+ provider(OpenAI/Anthropic/Gemini/Ollama/Groq/Bedrock/Vertex…);drop_params/modify_params 抹平差异;ModelRouter.select_model() 按任务能力/预算自动路由到最便宜可用模型;failover / rate_limiter / cost 计量
Semantic KernelIChatCompletionService(及 ITextGeneration/IEmbeddingGenerator/ITextToImage 等)为统一接口,每厂商一个 Connectors. 包;IAIServiceSelector(默认 OrderedAIServiceSelector) 按 serviceId/modelId 选服务;正向 Microsoft.Extensions.AI.IChatClient 收敛(AsChatCompletionService() 桥接)
smolagentsModel 基类统一 generate()/generate_stream(),_prepare_completion_kwargs 把消息归一为 OpenAI 格式 + tools schema;子类覆盖各 provider,支持 stop/structured output/vision
Strands Agents框架核心:Model ABC 仅需 stream/structured_output/get_config;13+ provider,默认 BedrockModel(Claude Sonnet);传 str 走 Bedrock model-id,传实例走自定义;stateful 属性标记服务端托管会话
Swarm仅 OpenAI,硬编码 OpenAI() client,无抽象层
SwarmClawbuildChatModel:Anthropic 用 ChatAnthropic,其余 23+ provider 全部 OpenAI 兼容(patch baseURL→streamOpenAiChat/ChatOpenAI);含 DeepSeek reasoning bridge、Ollama local/cloud、OpenClaw endpoint、gateway profile
Swarms不自研 provider:LiteLLM 包装类持有模型名/参数,run() 内组装 completion_params 调 litellm.completion;自动探测 vision/reasoning 支持,映射 reasoning_effort/thinking_tokens
Transformers Agentsllm_engine(HfApiEngine / TransformersEngine / 兼容 OpenAI 等)
Upsonicprovider/model 字符串 → infer_model() 路由到具体 Model(Runnable 子类);20+ provider(openai/anthropic/google/azure/bedrock/cohere/mistral/groq/xai/ollama/vllm…);model_registry.py 带 benchmark/tier 元数据支持自动选型
vectara-agenticget_llm(role, config)(llm_utils.py:174)按 provider 枚举工厂式实例化 LlamaIndex LLM;支持 OpenAI/Anthropic/Gemini/Together/GROQ/Bedrock/Cohere/Private(OpenAILike)。主 LLM 与工具 LLM 可分别配置(LLMRole.MAIN/TOOL,types.py:52);带 LLM 实例缓存与各 provider 默认模型表
VoltAgent直接复用 Vercel AI SDK 的 LanguageModel/EmbeddingModel(OpenAI/Anthropic/Google/Groq/Mistral/xAI/Bedrock/Vertex/Ollama 等十余 provider 作 deps);另有 model-provider-registry 把字符串模型名经 models.dev API 解析为 provider,按 env 自动选 + 本地缓存

各框架实现对比 · 源码级

46 个框架实现该组件 · 45 个附源码节选 · 点击任意框架展开看实现要点与代码

Aeon yaml 模型名为字符串,三级覆盖:workflow_dispatch 入参 > per-skill model: > aeon.yml 顶层 model:(默认 claude-opus-4-8)。Gateway 路由:gateway.provider: bankr 时改写 ANTHROPIC_BASE_URL=https://llm.bankr.bot 解锁 Gemini/GPT/Kimi/Qwen;或 vars.ANTHROPIC_BASE_URL 接任意 Anthropic 兼容端点

模型名为字符串,三级覆盖:workflow_dispatch 入参 > per-skill model: > aeon.yml 顶层 model:(默认 claude-opus-4-8)。Gateway 路由:gateway.provider: bankr 时改写 ANTHROPIC_BASE_URL=https://llm.bankr.bot 解锁 Gemini/GPT/Kimi/Qwen;或 vars.ANTHROPIC_BASE_URL 接任意 Anthropic 兼容端点

github/workflows/aeon.yml:279github/workflows/aeon.yml:293aeon.yml:287
.github/workflows/aeon.yml:279 yaml
        run: |
          TODAY=$(date -u +%Y-%m-%d)
          export SKILL_NAME
          CONFIG_MODEL=$(grep -E '^model:' aeon.yml | sed 's/^model: *//' | tr -d ' ')
          # Check for per-skill model override in aeon.yml (extract quoted value, ignore comments)
          SKILL_MODEL=$(grep "^  ${SKILL_NAME}:" aeon.yml | sed -n 's/.*model: *"\([^"]*\)".*/\1/p')
          if [ -n "$INPUT_MODEL" ] && [ "$INPUT_MODEL" != "(config default)" ]; then
            MODEL="$INPUT_MODEL"
          elif [ -n "$SKILL_MODEL" ]; then
            MODEL="$SKILL_MODEL"
          else
            MODEL="${CONFIG_MODEL:-claude-opus-4-8}"
          fi
查看 Aeon 完整笔记 →
AG2 python ModelClient 是 Protocol(须实现 create/message_retrieval/cost/get_usage);OpenAIWrapper 按 config 的 api_type 路由到各 provider client(openai/azure/anthropic/gemini/bedrock/mistral/groq/cohere/ollama/together/cerebras/deepseek 等);统一以 OpenAI ChatCompletion 格式为内部协议;支持 config_list 故障转移与 register_model_client 自定义

ModelClient 是 Protocol(须实现 create/message_retrieval/cost/get_usage);OpenAIWrapper 按 config 的 api_type 路由到各 provider client(openai/azure/anthropic/gemini/bedrock/mistral/groq/cohere/ollama/together/cerebras/deepseek 等);统一以 OpenAI ChatCompletion 格式为内部协议;支持 config_list 故障转移与 register_model_client 自定义

llm_config/client.py:14oai/client.py:761
autogen/llm_config/client.py:14 python


@export_module("autogen")
class ModelClient(Protocol):
    """A client class must implement the following methods:
    - create must return a response object that implements the ModelClientResponseProtocol
    - cost must return the cost of the response
    - get_usage must return a dict with the following keys:
        - prompt_tokens
        - completion_tokens
        - total_tokens
        - cost
        - model
查看 AG2 完整笔记 →
Agency Swarm python 直接复用 SDK 的 Model/ModelSettings;默认 gpt-5.4-mini,OpenAI 走 OpenAIResponsesModel,其它厂商(Claude/Gemini/Grok/Azure/OpenRouter)经可选 LitellmModel(litellm extra)路由

直接复用 SDK 的 Model/ModelSettings;默认 gpt-5.4-mini,OpenAI 走 OpenAIResponsesModel,其它厂商(Claude/Gemini/Grok/Azure/OpenRouter)经可选 LitellmModel(litellm extra)路由

agent/core.py:140__init__.py:53pyproject.toml:64
src/agency_swarm/agent/core.py:140 python
            handoff_reminder (str | None): Custom reminder for handoffs.
                Defaults to `Transfer completed. You are {recipient_agent_name}. Please continue the task.`

        ## OpenAI Agents SDK Parameters:
            prompt (Prompt | DynamicPromptFunction | None): Dynamic prompt configuration.
            model (str | Model | None): Model identifier (e.g., "gpt-5.4") or Model instance.
                Defaults to "gpt-5.4-mini".
            model_settings (ModelSettings | None): Model configuration (temperature, max_tokens, etc.).
            tools (list[Tool] | None): Tool instances for the agent. Defaults to empty list.
            mcp_servers (list[MCPServer] | None): Model Context Protocol servers.
            mcp_config (MCPConfig | None): MCP server configuration.
            input_guardrails (list[InputGuardrail] | None): Pre-execution validation checks.
            output_guardrails (list[OutputGuardrail] | None): Post-execution validation checks.
查看 Agency Swarm 完整笔记 →
Agent-LLM (AGiXT) python provider = CATEGORY="AI Provider" 的 extension,按 services()(llm/tts/image/embeddings/vision…)分类自动发现;get_providers_by_service 路由;内置 OpenAI/Anthropic/Gemini/Azure/DeepSeek/HuggingFace/ezlocalai 等(extensions/.py)

provider = CATEGORY="AI Provider" 的 extension,按 services()(llm/tts/image/embeddings/vision…)分类自动发现;get_providers_by_service 路由;内置 OpenAI/Anthropic/Gemini/Azure/DeepSeek/HuggingFace/ezlocalai 等(extensions/.py)

Providers.py:23Providers.py:204
agixt/Providers.py:23 python
_AI_PROVIDER_CACHE_TTL = 300  # 5 minutes cache TTL


def _get_ai_provider_extensions(use_cache=True):
    """Get all extension files with CATEGORY = 'AI Provider'

    Args:
        use_cache: If True, use cached results when available (default: True)
    """
    global _ai_provider_cache, _ai_provider_cache_time

    # Return cached result if valid
    if use_cache and _ai_provider_cache is not None:
查看 Agent-LLM (AGiXT) 完整笔记 →
AgentDock typescript CoreLLM 统一封装 Vercel AI SDK LanguageModel,暴露 generateText/streamText/generateObject 等;createLLM 工厂 + ProviderRegistry 按 provider 路由 adapter(anthropic/openai/google/groq/deepseek/cerebras);支持 primary+fallback 双 LLM

CoreLLM 统一封装 Vercel AI SDK LanguageModel,暴露 generateText/streamText/generateObject 等;createLLM 工厂 + ProviderRegistry 按 provider 路由 adapter(anthropic/openai/google/groq/deepseek/cerebras);支持 primary+fallback 双 LLM

llm/core-llm.ts:84nodes/agent-node.ts:152
agentdock-core/src/llm/core-llm.ts:84 typescript
 * Callers like AgentNode should use `setCurrentUsageCallback` before invoking methods like `streamText`
 * or `generateText` to ensure usage is captured for state updates or other tracking purposes.
 */
export class CoreLLM {
  private model: LanguageModel;
  private config: LLMConfig;
  private lastTokenUsage: TokenUsage | null = null;

  constructor({ model, config }: { model: LanguageModel; config: LLMConfig }) {
    this.model = model;
    this.config = config;

    logger.debug(LogCategory.LLM, 'CoreLLM', 'Created LLM instance', {
查看 AgentDock 完整笔记 →
AgentField go 经 LiteLLM 统一 100+ LLM provider(AIConfig(model="anthropic/..."));app.ai(schema=...) 通过 system prompt 注入 schema 指令 + LiteLLM response_format=json_schema 双保险得到 typed 输出;支持 stream、多模态(image/audio)、temperature 等

经 LiteLLM 统一 100+ LLM provider(AIConfig(model="anthropic/..."));app.ai(schema=...) 通过 system prompt 注入 schema 指令 + LiteLLM response_format=json_schema 双保险得到 typed 输出;支持 stream、多模态(image/audio)、temperature 等

agent_ai.py:26agent_ai.py:403agent_ai.py:546
sdk/python/agentfield/agent_ai.py:26 python
_openai = None


def _get_litellm():
    """Lazy import of litellm - only loads when AI features are used."""
    global _litellm
    if _litellm is None:
        try:
            import litellm

            litellm.suppress_debug_info = True
            _litellm = litellm
        except Exception:  # pragma: no cover
查看 AgentField 完整笔记 →
Agentic Context Engine (ACE) python 经 PydanticAI 统一;resolve_model() 把 LiteLLM 风格模型名路由到 PydanticAI 原生 provider 或 litellm: 代理(100+ provider:OpenAI/Anthropic/Google/Bedrock/Groq…);可按角色分别配模型(ACEModelConfig)

经 PydanticAI 统一;resolve_model() 把 LiteLLM 风格模型名路由到 PydanticAI 原生 provider 或 litellm: 代理(100+ provider:OpenAI/Anthropic/Google/Bedrock/Groq…);可按角色分别配模型(ACEModelConfig)

ace/providers/pydantic_ai.py:107
ace/providers/pydantic_ai.py:107 python
)


def resolve_model(model: str) -> Any:
    """Resolve an ACE/LiteLLM model string for PydanticAI.

    Returns either a string (for PydanticAI's auto-provider detection)
    or a ``(provider, model_name)`` tuple when explicit provider
    configuration is needed (e.g. Bedrock API key auth).

    Resolution paths:

    1. **PydanticAI-native prefix** -- Already starts with a known
查看 Agentic Context Engine (ACE) 完整笔记 →
AgentScope python ChatModelBase 抽象 async __call__(messages, tools, tool_choice),统一 stream/重试/count_tokens/context_size;8 家实现(Anthropic/DashScope/DeepSeek/Gemini/Ollama/OpenAIChat/OpenAIResponse/XAI/Moonshot);各家配套 formatter/ 把 Msg+block 转 provider 报文;credential/ 解耦密钥

ChatModelBase 抽象 async __call__(messages, tools, tool_choice),统一 stream/重试/count_tokens/context_size;8 家实现(Anthropic/DashScope/DeepSeek/Gemini/Ollama/OpenAIChat/OpenAIResponse/XAI/Moonshot);各家配套 formatter/ 把 Msg+block 转 provider 报文;credential/ 解耦密钥

model/_base.py:35formatter/_formatter_base.py:22
src/agentscope/model/_base.py:35 python
_TOOL_CHOICE_LITERAL_MODES = {"auto", "none", "required"}


class ChatModelBase:
    """The base class for chat models."""

    class Parameters(BaseModel):
        """Each subclass should implement this inner class to define its
        parameters."""

    credential: CredentialBase
    """The API credential."""
查看 AgentScope 完整笔记 →
Agentset typescript 全栈基于 Vercel AI SDK(generateText/streamText/embed/generateObject);LLM 经 Azure 网关按名映射(gpt-4.1/gpt-5),embedding 工厂支持 Azure/OpenAI/Voyage/Google,按 namespace 配置动态 import

全栈基于 Vercel AI SDK(generateText/streamText/embed/generateObject);LLM 经 Azure 网关按名映射(gpt-4.1/gpt-5),embedding 工厂支持 Azure/OpenAI/Voyage/Google,按 namespace 配置动态 import

engine/src/llm/index.ts:23engine/src/embedding/index.ts:22
packages/engine/src/llm/index.ts:23 typescript
  "openai:gpt-5-nano": "gpt-5-nano",
};

export const getNamespaceLanguageModel = (
  model: LLM = DEFAULT_LLM,
): LanguageModel => {
  const modelId = modelToId[model];
  return openaiAzure.languageModel(modelId);
};
查看 Agentset 完整笔记 →
AgentVerse python BaseLLM 抽象(generate_response/agenerate_response/get_spend,统一返回 LLMResult)+ llm_registry;主实现 OpenAIChat(含 Azure 分支);本地模型经 vLLM / FSChat 走 OpenAI 兼容端点,LOCAL_LLMS/LOCAL_LLMS_MAPPING 列表登记

BaseLLM 抽象(generate_response/agenerate_response/get_spend,统一返回 LLMResult)+ llm_registry;主实现 OpenAIChat(含 Azure 分支);本地模型经 vLLM / FSChat 走 OpenAI 兼容端点,LOCAL_LLMS/LOCAL_LLMS_MAPPING 列表登记

llms/base.py:19llms/__init__.py:3
agentverse/llms/base.py:19 python
    pass


class BaseLLM(BaseModel):
    args: BaseModelArgs = Field(default_factory=BaseModelArgs)
    max_retry: int = Field(default=3)
    client_args: Optional[Dict] = Field(default={})
    is_azure: bool = Field(default=False)

    @abstractmethod
    def get_spend(self) -> float:
        """
        Number of USD spent
查看 AgentVerse 完整笔记 →
Ailoy rust LangModel 包 LangModelInner::{Local, StreamAPI, Custom}(src/model/language_model.rs:184),统一 LangModelInference trait(infer / infer_delta,src/model/language_model.rs:135)。Local=TVM;StreamAPI 经 APISpecification 枚举支持 ChatCompletion/OpenAI(Responses)/Gemini/Claude/Grok(src/model/api/mod.rs:36);EmbeddingModel 同构(本地/远程)

LangModel 包 LangModelInner::{Local, StreamAPI, Custom}(src/model/language_model.rs:184),统一 LangModelInference trait(infer / infer_delta,src/model/language_model.rs:135)。Local=TVM;StreamAPI 经 APISpecification 枚举支持 ChatCompletion/OpenAI(Responses)/Gemini/Claude/Grok(src/model/api/mod.rs:36);EmbeddingModel 同构(本地/远程)

src/model/language_model.rs:135src/model/api/mod.rs:36
src/model/language_model.rs:135 rust
}

#[maybe_send_sync]
pub trait LangModelInference {
    /// Runs the language model with the given tools and messages, returning a stream of `MessageOutput`s.
    fn infer_delta<'a>(
        &'a mut self,
        msgs: Vec<Message>,
        tools: Vec<ToolDesc>,
        docs: Vec<Document>,
        config: LangModelInferConfig,
    ) -> BoxStream<'a, anyhow::Result<MessageDeltaOutput>>;
查看 Ailoy 完整笔记 →
Astron Agent python BaseLLMModel(默认走 OpenAI 兼容 AsyncOpenAI.chat.completions)+ ProviderLLMModel 子类按 provider 适配:AnthropicLLMModel(/v1/messages + SSE 归一化)、GoogleLLMModel(generateContent SSE);OpenAI 兼容白名单含 deepseek/doubao/qwen/zhipu/moonshot/minimax 等;create_model() 按 provider 字符串分发

BaseLLMModel(默认走 OpenAI 兼容 AsyncOpenAI.chat.completions)+ ProviderLLMModel 子类按 provider 适配:AnthropicLLMModel(/v1/messages + SSE 归一化)、GoogleLLMModel(generateContent SSE);OpenAI 兼容白名单含 deepseek/doubao/qwen/zhipu/moonshot/minimax 等;create_model() 按 provider 字符串分发

domain/models/base.py:15service/builder/base_builder.py:274
core/workflow/domain/models/base.py:15 python


def orjson_dumps(
    v: Any, *, default: Any = None, sort_keys: bool = False, indent_2: bool = True
) -> str:
    """
    Serialize Python objects to JSON string using orjson with custom options.

    :param v: Object to serialize
    :param default: Default function for non-serializable objects
    :param sort_keys: Whether to sort dictionary keys
    :param indent_2: Whether to use 2-space indentation
    :return: JSON string representation
查看 Astron Agent 完整笔记 →
AutoGen python ChatCompletionClient 抽象基类定义 create/create_stream/model_info(ModelInfo TypedDict 描述 vision/function-calling/family 等能力);统一 LLMMessage(System/User/Assistant/FunctionExecutionResult)与 CreateResult;具体 OpenAI/Azure/Anthropic 等 client 在 autogen-ext

ChatCompletionClient 抽象基类定义 create/create_stream/model_info(ModelInfo TypedDict 描述 vision/function-calling/family 等能力);统一 LLMMessage(System/User/Assistant/FunctionExecutionResult)与 CreateResult;具体 OpenAI/Azure/Anthropic 等 client 在 autogen-ext

autogen-core/src/autogen_core/models/_model_client.py:209
python/packages/autogen-core/src/autogen_core/models/_model_client.py:209 python
            )


class ChatCompletionClient(ComponentBase[BaseModel], ABC):
    # Caching has to be handled internally as they can depend on the create args that were stored in the constructor
    @abstractmethod
    async def create(
        self,
        messages: Sequence[LLMMessage],
        *,
        tools: Sequence[Tool | ToolSchema] = [],
        tool_choice: Tool | Literal["auto", "required", "none"] = "auto",
        json_output: Optional[bool | type[BaseModel]] = None,
查看 AutoGen 完整笔记 →
Botpress typescript Cognitive 客户端封装多 provider:best/fast/auto 预设或 integration:model-id ModelRef;按 tag/价格/vendor 打分排序;provider 宕机自动标 degraded 并回退下一个模型(5 分钟);统一 generateContent

Cognitive 客户端封装多 provider:best/fast/auto 预设或 integration:model-id ModelRef;按 tag/价格/vendor 打分排序;provider 宕机自动标 degraded 并回退下一个模型(5 分钟);统一 generateContent

packages/cognitive/src/client.ts:235packages/cognitive/src/client.ts:143packages/cognitive/readme.md:36
packages/cognitive/src/client.ts:235 typescript
    return def
  }

  public async generateContent(input: InputProps): Promise<Response> {
    const primaryInputModel = this._getPrimaryModel(input)

    if (!this._useBeta || !isKnownV2Model(primaryInputModel)) {
      return this._generateContent(input)
    }

    try {
      return await this._generateContentV2(input)
    } catch (err) {
查看 Botpress 完整笔记 →
ConnectOnion python LLM 抽象基类 + create_llm() 工厂按模型名前缀路由;OpenAI/Anthropic/Gemini/Groq/Grok/Mistral/OpenRouter/OpenOnion(co/);OpenAI message 格式为 lingua franca,统一 ToolCall dataclass

LLM 抽象基类 + create_llm() 工厂按模型名前缀路由;OpenAI/Anthropic/Gemini/Groq/Grok/Mistral/OpenRouter/OpenOnion(co/);OpenAI message 格式为 lingua franca,统一 ToolCall dataclass

core/llm.py:1130
connectonion/core/llm.py:1130 python
        return None


def create_llm(model: str, api_key: Optional[str] = None, **kwargs) -> LLM:
    """Factory function to create the appropriate LLM based on model name.
    
    Args:
        model: The model name (e.g., "gpt-4o", "claude-3-5-sonnet", "gemini-1.5-pro")
        api_key: Optional API key to override environment variable
        **kwargs: Additional arguments to pass to the LLM constructor
    
    Returns:
        An LLM instance for the specified model
查看 ConnectOnion 完整笔记 →
Cortex Memory rust LLMClient trait(llm/client.rs) + EmbeddingClient(embedding/client.rs:334 embed,:364 embed_batch),均走 OpenAI 兼容 HTTP 端点;底层依赖 rig-core 0.31(Cargo.toml:41);模型在 config.toml 配 model_efficient/model_reasoning

LLMClient trait(llm/client.rs) + EmbeddingClient(embedding/client.rs:334 embed,:364 embed_batch),均走 OpenAI 兼容 HTTP 端点;底层依赖 rig-core 0.31(Cargo.toml:41);模型在 config.toml 配 model_efficient/model_reasoning

llm/client.rs:184embedding/client.rs:334Cargo.toml:41
cortex-mem-core/src/llm/client.rs:184 rust
    }

    /// Extract memories from conversation
    pub async fn extract_memories(&self, prompt: &str) -> Result<MemoryExtractionResponse> {
        let response: String = self.complete(prompt).await?;
        
        // Extract JSON from response (handles markdown code blocks)
        let json_str = Self::extract_json_from_response_static(&response);
        
        // Try to parse as structured response first
        if let Ok(extracted) = serde_json::from_str::<MemoryExtractionResponse>(json_str) {
            tracing::debug!("Successfully parsed MemoryExtractionResponse");
            return Ok(extracted);
查看 Cortex Memory 完整笔记 →
CrewAI python BaseLLM 抽象基类 + LLM.__new__ 工厂按 provider/model 前缀路由:openai/anthropic/azure/bedrock/gemini 走原生 SDK,其余回退 LiteLLM;create_llm 统一构造

BaseLLM 抽象基类 + LLM.__new__ 工厂按 provider/model 前缀路由:openai/anthropic/azure/bedrock/gemini 走原生 SDK,其余回退 LiteLLM;create_llm 统一构造

crewai/llms/base_llm.py:129crewai/llm.py:315crewai/utilities/llm_utils.py:13
lib/crewai/src/crewai/llms/base_llm.py:129 python
    return call_id


class BaseLLM(BaseModel, ABC):
    """Abstract base class for LLM implementations.

    This class defines the interface that all LLM implementations must follow.
    Users can extend this class to create custom LLM implementations that don't
    rely on litellm's authentication mechanism.

    Custom LLM implementations should handle error cases gracefully, including
    timeouts, authentication failures, and malformed responses. They should also
    implement proper validation for input parameters and provide clear error
查看 CrewAI 完整笔记 →
Dust typescript 两层:新 front 原生 LLM router getLLM 按 modelId 路由到各 provider 客户端(Anthropic/OpenAI/Google/Mistral/xAI/Fireworks/Noop);旧 core 的 LLM trait + provider 实现(迁移中)

两层:新 front 原生 LLM router getLLM 按 modelId 路由到各 provider 客户端(Anthropic/OpenAI/Google/Mistral/xAI/Fireworks/Noop);旧 core 的 LLM trait + provider 实现(迁移中)

front/lib/api/llm/index.ts:50core/src/providers/llm.rs:217
front/lib/api/llm/index.ts:50 typescript
  return { ...credentials, ANTHROPIC_API_KEY: eapApiKey };
}

export async function getLLM(
  auth: Authenticator,
  {
    credentials,
    getTraceInput,
    getTraceOutput,
    modelId,
    temperature,
    reasoningEffort,
    responseFormat,
查看 Dust 完整笔记 →
Haystack python 基于 Protocol(鸭子类型)而非基类:ChatGenerator 协议仅要求 run(messages)->dict、返回 replies: list[ChatMessage];OpenAI/Azure/HF 内置,其余厂商在 haystack-core-integrations;ChatMessage/ToolCall 为统一数据格式;FallbackChatGenerator 多模型故障转移

基于 Protocol(鸭子类型)而非基类:ChatGenerator 协议仅要求 run(messages)->dict、返回 replies: list[ChatMessage];OpenAI/Azure/HF 内置,其余厂商在 haystack-core-integrations;ChatMessage/ToolCall 为统一数据格式;FallbackChatGenerator 多模型故障转移

components/generators/chat/types/protocol.py:10components/generators/chat/openai.py:58components/generators/chat/fallback.py:21
haystack/components/generators/chat/types/protocol.py:10 python
from haystack.dataclasses import ChatMessage


class ChatGenerator(Protocol):
    """
    Protocol for Chat Generators.

    This protocol defines the minimal interface that Chat Generators must implement.
    Chat Generators are components that process a list of `ChatMessage` objects as input and generate
    responses using a Language Model. They return a dictionary.
    """

    def run(self, messages: list[ChatMessage]) -> dict[str, Any]:
查看 Haystack 完整笔记 →
Hermes Agent python 声明式 ProviderProfile dataclass(auth/endpoint/api_mode/quirks),插件式注册(plugins/model-providers/<name>/,用户插件 last-writer-wins 可覆盖内置);底座是 OpenAI SDK,另带 anthropic/bedrock/gemini-native/codex-responses 等专属 adapter;hermes model 一条切换、credential pool 多 key 轮换、无代码改动

声明式 ProviderProfile dataclass(auth/endpoint/api_mode/quirks),插件式注册(plugins/model-providers/<name>/,用户插件 last-writer-wins 可覆盖内置);底座是 OpenAI SDK,另带 anthropic/bedrock/gemini-native/codex-responses 等专属 adapter;hermes model 一条切换、credential pool 多 key 轮换、无代码改动

providers/base.py:38providers/__init__.py:1
providers/base.py:38 python
        return "hermes-cli"


@dataclass
class ProviderProfile:
    """Base provider profile — subclass or instantiate with overrides."""

    # ── Identity ─────────────────────────────────────────────
    name: str
    api_mode: str = "chat_completions"
    aliases: tuple = ()

    # ── Human-readable metadata ───────────────────────────────
查看 Hermes Agent 完整笔记 →
Hive python LLMProvider ABC(acomplete/stream,统一 LLMResponse 含 token/cost);实现:LiteLLM(100+ provider,含 ollama 本地)、原生 Anthropic、Antigravity、Mock;model_catalog.py 管定价

LLMProvider ABC(acomplete/stream,统一 LLMResponse 含 token/cost);实现:LiteLLM(100+ provider,含 ollama 本地)、原生 Anthropic、Antigravity、Mock;model_catalog.py 管定价

llm/provider.py:73llm/litellm.py:1
core/framework/llm/provider.py:73 python
    is_skill_content: bool = False  # AS-10: marks activated skill body, protected from pruning


class LLMProvider(ABC):
    """
    Abstract LLM provider - plug in any LLM backend.

    Implementations should handle:
    - API authentication
    - Request/response formatting
    - Token counting
    - Error handling
    """
查看 Hive 完整笔记 →
Lagent python BaseLLM/AsyncBaseLLM 定义 chat/generate/stream_chat;LMTemplateParser 用 meta_template 把对话拼成模型专属字符串;多 provider wrapper:GPTAPI、ClaudeAPI、HFTransformer、VllmModel、LMDeploy、Sensenova;AsyncOpenAIWrapper.chat 直接返回原生 ChatCompletion(含 tool_calls)

BaseLLM/AsyncBaseLLM 定义 chat/generate/stream_chat;LMTemplateParser 用 meta_template 把对话拼成模型专属字符串;多 provider wrapper:GPTAPI、ClaudeAPI、HFTransformer、VllmModel、LMDeploy、Sensenova;AsyncOpenAIWrapper.chat 直接返回原生 ChatCompletion(含 tool_calls)

llms/base_llm.py:96llms/base_llm.py:5llms/openai.py:31llms/openai.py:823
lagent/llms/base_llm.py:96 python
        return res


class BaseLLM:
    """Base class for model wrapper.

    Args:
        path (str): The path to the model.
        max_new_tokens (int): Maximum length of output expected to be generated by the model. Defaults
            to 512.
        tokenizer_only (bool): If True, only the tokenizer will be initialized.
            Defaults to False.
        meta_template (list of dict, optional): The model's meta prompt
查看 Lagent 完整笔记 →
LangChain python BaseChatModel(core) 为统一接口,暴露 invoke/stream/bind_tools/with_structured_output;init_chat_model("provider:model") 按前缀懒加载 partner 实现(_BUILTIN_PROVIDERS 表覆盖 anthropic/openai/google/groq/ollama…);模型可整体互换

BaseChatModel(core) 为统一接口,暴露 invoke/stream/bind_tools/with_structured_output;init_chat_model("provider:model") 按前缀懒加载 partner 实现(_BUILTIN_PROVIDERS 表覆盖 anthropic/openai/google/groq/ollama…);模型可整体互换

chat_models/base.py:175base.py:38core/.../chat_models.py:270
libs/partners/openai/langchain_openai/chat_models/base.py:175 python
        _ssrf_client = ssrf_safe_client(
            verify=global_ssl_context, follow_redirects=False
        )
    return _ssrf_client


_MODEL_PROFILES = cast(ModelProfileRegistry, _PROFILES)


def _get_default_model_profile(model_name: str) -> ModelProfile:
    default = _MODEL_PROFILES.get(model_name) or {}
    return default.copy()
查看 LangChain 完整笔记 →
Llama Agentic System (llama-stack-apps) python 模型抽象在服务端 Inference API;客户端按 model_id 字符串选模型,client.models.list() 发现可用模型(区分 model_type=="llm" 与含 "guard" 的安全模型)。模型族=Llama 3.1/3.2 等

模型抽象在服务端 Inference API;客户端按 model_id 字符串选模型,client.models.list() 发现可用模型(区分 model_type=="llm" 与含 "guard" 的安全模型)。模型族=Llama 3.1/3.2 等

examples/agents/utils.py:5examples/agent_store/api.py:35README.md:5
examples/agents/utils.py:5 python
from termcolor import colored


def check_model_is_available(client: LlamaStackClient, model: str):
    available_models = [
        model.identifier
        for model in client.models.list()
        if model.model_type == "llm" and "guard" not in model.identifier
    ]

    if model not in available_models:
        print(
            colored(
查看 Llama Agentic System (llama-stack-apps) 完整笔记 →
LlamaIndex python BaseLLM→LLM→FunctionCallingLLM 三层抽象;统一 ChatMessage/ChatResponse 与 block 化多模态;achat_with_tools/get_tool_calls_from_response/predict_and_call 抹平各家 function calling;300+ provider 在 integrations 包;Settings.llm 全局默认

BaseLLM→LLM→FunctionCallingLLM 三层抽象;统一 ChatMessage/ChatResponse 与 block 化多模态;achat_with_tools/get_tool_calls_from_response/predict_and_call 抹平各家 function calling;300+ provider 在 integrations 包;Settings.llm 全局默认

base/llms/base.py:26llms/llm.py:163llms/function_calling.py:24
llama-index-core/llama_index/core/base/llms/base.py:26 python
from llama_index.core.schema import BaseComponent


class BaseLLM(BaseComponent, DispatcherSpanMixin):
    """BaseLLM interface."""

    model_config = ConfigDict(arbitrary_types_allowed=True)
    callback_manager: CallbackManager = Field(
        default_factory=lambda: CallbackManager([]), exclude=True
    )
    # Expected type: BaseRateLimiter (from llama_index.core.rate_limiter)
    rate_limiter: Optional[Any] = Field(
        default=None,
查看 LlamaIndex 完整笔记 →
llm-agents python 单一 ChatLLM pydantic 类,硬编码调用 OpenAI 旧版 openai.ChatCompletion.create;只暴露 model/temperature,无多 provider 路由、无统一消息抽象(单条 user message)

单一 ChatLLM pydantic 类,硬编码调用 OpenAI 旧版 openai.ChatCompletion.create;只暴露 model/temperature,无多 provider 路由、无统一消息抽象(单条 user message)

llm.py:8llm.py:13
llm_agents/llm.py:8 python
from typing import List


class ChatLLM(BaseModel):
    model: str = 'gpt-3.5-turbo'
    temperature: float = 0.0
    openai.api_key = os.environ["OPENAI_API_KEY"]  # Credentials setup

    def generate(self, prompt: str, stop: List[str] = None):
        response = openai.ChatCompletion.create(
            model=self.model,
            messages=[{"role": "user", "content": prompt}],
            temperature=self.temperature,
查看 llm-agents 完整笔记 →
LoongFlow python BaseLLMModel 抽象 + LiteLLMModel 默认实现,底层走 LiteLLM,统一 CompletionRequest/CompletionResponse,async generator 支持流式;from_config 读 model/url/api_key,默认 provider=openai(如 openai/gemini-3-pro-preview);ClaudeCodeAgent 另走 Anthropic 兼容端点

BaseLLMModel 抽象 + LiteLLMModel 默认实现,底层走 LiteLLM,统一 CompletionRequest/CompletionResponse,async generator 支持流式;from_config 读 model/url/api_key,默认 provider=openai(如 openai/gemini-3-pro-preview);ClaudeCodeAgent 另走 Anthropic 兼容端点

agentsdk/models/litellm_model.py:19
src/loongflow/agentsdk/models/litellm_model.py:19 python
logger = get_logger(__name__)


class LiteLLMModel(BaseLLMModel):
    """
    LoongFlow model backend implementation based on LiteLLM.

    Each model instance holds static configuration (model name, base_url, api_key),
    while each `generate` call handles dynamic per-request parameters
    (messages, tools, temperature, etc.).
    """

    def __init__(
查看 LoongFlow 完整笔记 →
Maestro python maestro.py 直接绑定 Anthropic SDK;跨 provider 抽象在 maestro-anyapi.py 经 LiteLLM completion() 统一 OpenAI-style 接口(Anthropic/OpenAI/Gemini/Cohere…),另有 groq/ollama/lmstudio 专用变体

maestro.py 直接绑定 Anthropic SDK;跨 provider 抽象在 maestro-anyapi.py 经 LiteLLM completion() 统一 OpenAI-style 接口(Anthropic/OpenAI/Gemini/Cohere…),另有 groq/ollama/lmstudio 专用变体

maestro.py:2maestro-anyapi.py:7
maestro.py:2 python
import os
from anthropic import Anthropic
import re
from rich.console import Console
from rich.panel import Panel
from datetime import datetime
import json
from tavily import TavilyClient

# Set up the Anthropic API client
client = Anthropic(api_key="YOUR KEY")
查看 Maestro 完整笔记 →
Mastra typescript 字符串 provider/model 经 ModelRouterLanguageModel 解析(gateway-resolver + provider-registry.json,覆盖 40+ provider),统一为 AI SDK v5/v6 LanguageModelV2;也接受直接传入 AI SDK model 实例;resolveModelConfig 兜底 v4 包装;支持 model fallbacks / retries

字符串 provider/model 经 ModelRouterLanguageModel 解析(gateway-resolver + provider-registry.json,覆盖 40+ provider),统一为 AI SDK v5/v6 LanguageModelV2;也接受直接传入 AI SDK model 实例;resolveModelConfig 兜底 v4 包装;支持 model fallbacks / retries

llm/model/router.ts:108
packages/core/src/llm/model/router.ts:108 typescript
 */
export const gateways = defaultGateways;

export class ModelRouterLanguageModel implements MastraLanguageModelV2 {
  readonly specificationVersion = 'v2' as const;
  readonly defaultObjectGenerationMode = 'json' as const;
  readonly supportsStructuredOutputs = true;
  readonly supportsImageUrls = true;

  /**
   * Supported URL patterns by media type for the provider.
   * This is a lazy promise that resolves the underlying model's supportedUrls.
   * Models like Mistral define which URL patterns they support (e.g., application/pdf for https URLs).
查看 Mastra 完整笔记 →
MetaGPT python BaseLLM 抽象基类(aask/acompletion/acompletion_text)+ @register_provider 按 LLMType 注册,create_llm_instance 工厂按 api_type 路由;内置 OpenAI/Azure/Anthropic/Gemini/Ollama/Bedrock/Qianfan/Zhipu/Spark/Dashscope/Ark 等十余 provider;统一 OpenAI message 格式

BaseLLM 抽象基类(aask/acompletion/acompletion_text)+ @register_provider 按 LLMType 注册,create_llm_instance 工厂按 api_type 路由;内置 OpenAI/Azure/Anthropic/Gemini/Ollama/Bedrock/Qianfan/Zhipu/Spark/Dashscope/Ark 等十余 provider;统一 OpenAI message 格式

metagpt/provider/base_llm.py:35provider/llm_provider_registry.py:38llm_provider_registry.py:24provider/openai_api.py:58
metagpt/provider/base_llm.py:35 python
from metagpt.utils.token_counter import TOKEN_MAX


class BaseLLM(ABC):
    """LLM API abstract class, requiring all inheritors to provide a series of standard capabilities"""

    config: LLMConfig
    use_system_prompt: bool = True
    system_prompt = "You are a helpful assistant."

    # OpenAI / Azure / Others
    aclient: Optional[Union[AsyncOpenAI]] = None
    cost_manager: Optional[CostManager] = None
查看 MetaGPT 完整笔记 →
Modus go 泛型接口 Model[TIn,TOut]{Info();Invoke(in)} + GetModel[TModel](name) 工厂;按 manifest 名解析,Invoke 经 host function hostInvokeModel 走 Runtime 调用 provider;内置 OpenAI/Anthropic/Gemini/Meta-Llama 及 experimental 分类/嵌入封装

泛型接口 Model[TIn,TOut]{Info();Invoke(in)} + GetModel[TModel](name) 工厂;按 manifest 名解析,Invoke 经 host function hostInvokeModel 走 Runtime 调用 provider;内置 OpenAI/Anthropic/Gemini/Meta-Llama 及 experimental 分类/嵌入封装

sdk/go/pkg/models/models.go:27sdk/assemblyscript/src/assembly/models.ts:63lib/manifest/model.go:8
sdk/go/pkg/models/models.go:27 go
}

// Provides a generic interface for interacting with an AI model.
type Model[TIn, TOut any] interface {
	Info() *ModelInfo
	Invoke(input *TIn) (*TOut, error)
}

// Provides a generic interface for setting the model information (used internally).
type modelPtr[TModel any] interface {
	*TModel
	setInfo(info *ModelInfo)
}
查看 Modus 完整笔记 →
nanobot python LLMProvider ABC(OpenAI message 为通用格式,统一 LLMResponse/ToolCallRequest);factory.make_provider 按 provider backend 路由:openai_compat/anthropic/azure/bedrock/github_copilot/openai_codex/openai_responses;FallbackProvider 做多模型 failover,原生 openai+anthropic SDK(已弃用 litellm)

LLMProvider ABC(OpenAI message 为通用格式,统一 LLMResponse/ToolCallRequest);factory.make_provider 按 provider backend 路由:openai_compat/anthropic/azure/bedrock/github_copilot/openai_codex/openai_responses;FallbackProvider 做多模型 failover,原生 openai+anthropic SDK(已弃用 litellm)

providers/base.py:92providers/factory.py:31
nanobot/providers/base.py:92 python
_SYNTHETIC_USER_CONTENT = "(conversation continued)"


class LLMProvider(ABC):
    """Base class for LLM providers."""

    supports_progress_deltas = False

    _CHAT_RETRY_DELAYS = (1, 2, 4)
    _PERSISTENT_MAX_DELAY = 60
    _PERSISTENT_IDENTICAL_ERROR_LIMIT = 10
    _RETRY_HEARTBEAT_CHUNK = 30
    _TRANSIENT_ERROR_MARKERS = (
查看 nanobot 完整笔记 →
Open Multi-Agent typescript LLMAdapter 接口(chat+stream) + createAdapter() 懒加载工厂,按 provider 名路由;12 内置 provider + 任意 OpenAI 兼容端点(baseURL);统一 thinking 配置映射到 Anthropic thinking / Gemini thinkingConfig / OpenAI reasoning_effort;Vercel AI SDK 经 AISdkAdapter 桥接

LLMAdapter 接口(chat+stream) + createAdapter() 懒加载工厂,按 provider 名路由;12 内置 provider + 任意 OpenAI 兼容端点(baseURL);统一 thinking 配置映射到 Anthropic thinking / Gemini thinkingConfig / OpenAI reasoning_effort;Vercel AI SDK 经 AISdkAdapter 桥接

src/llm/adapter.ts:76src/llm/adapter.ts:42
src/llm/adapter.ts:76 typescript
 * @param region   - Optional AWS region for `bedrock`; falls back to `AWS_REGION` env var, then `'us-east-1'`. Ignored by all other providers.
 * @throws {Error} When the provider string is not recognised.
 */
export async function createAdapter(
  provider: SupportedProvider,
  apiKey?: string,
  baseURL?: string,
  region?: string,
): Promise<LLMAdapter> {
  switch (provider) {
    case 'anthropic': {
      const { AnthropicAdapter } = await import('./anthropic.js')
      return new AnthropicAdapter(apiKey, baseURL)
查看 Open Multi-Agent 完整笔记 →
OpenClaw typescript 两层:packages/llm-core 定义统一 Model 接口(api/provider/cost/contextWindow/thinkingLevelMap) 与 StreamFn;packages/llm-runtime/api-registry.ts 按 model.api 注册/路由 provider 适配器;src/llm/providers/ 实现 OpenAI(completions/responses/chatgpt)/Anthropic/Google(+Vertex)/Mistral/Azure/Copilot 等;OAuth 订阅(ChatGPT/Codex)走 src/llm/oauth.ts,支持 auth profile 轮换与 failover

两层:packages/llm-core 定义统一 Model 接口(api/provider/cost/contextWindow/thinkingLevelMap) 与 StreamFn;packages/llm-runtime/api-registry.ts 按 model.api 注册/路由 provider 适配器;src/llm/providers/ 实现 OpenAI(completions/responses/chatgpt)/Anthropic/Google(+Vertex)/Mistral/Azure/Copilot 等;OAuth 订阅(ChatGPT/Codex)走 src/llm/oauth.ts,支持 auth profile 轮换与 failover

packages/llm-core/src/types.ts:574packages/llm-runtime/src/api-registry.ts:50src/llm/model-registry.ts:5
packages/llm-core/src/types.ts:574 typescript
}

// Model interface for the unified model system
export interface Model<TApi extends Api = Api> {
  id: string;
  name: string;
  api: TApi;
  provider: Provider;
  baseUrl: string;
  reasoning: boolean;
  /**
   * Maps OpenClaw thinking levels to provider/model-specific values.
   * Missing keys use provider defaults. null marks a level as unsupported.
查看 OpenClaw 完整笔记 →
Pipecat python 服务基类体系 AIService→LLMService/STTService/TTSService/VisionService;60+ provider 实现(openai/anthropic/google/groq…);BaseLLMAdapter(泛型)把统一 LLMContext/ToolsSchema 转成各家 provider 的 messages/tools 格式

服务基类体系 AIService→LLMService/STTService/TTSService/VisionService;60+ provider 实现(openai/anthropic/google/groq…);BaseLLMAdapter(泛型)把统一 LLMContext/ToolsSchema 转成各家 provider 的 messages/tools 格式

services/llm_service.py:245adapters/base_llm_adapter.py:33
src/pipecat/services/llm_service.py:245 python
TAdapter = TypeVar("TAdapter", bound=BaseLLMAdapter, default=BaseLLMAdapter)


class LLMService(UserTurnCompletionLLMServiceMixin, AIService, Generic[TAdapter]):
    """Base class for all LLM services.

    Handles function calling registration and execution with support for both
    parallel and sequential execution modes. Provides event handlers for
    completion timeouts and function call lifecycle events.

    The service supports the following event handlers:

    - on_completion_timeout: Called when an LLM completion timeout occurs
查看 Pipecat 完整笔记 →
PraisonAI python LLM 类包一层 LiteLLM,覆盖 100+ provider(OpenAI/Anthropic/Gemini/Ollama/Groq/Bedrock/Vertex…);drop_params/modify_params 抹平差异;ModelRouter.select_model() 按任务能力/预算自动路由到最便宜可用模型;failover / rate_limiter / cost 计量

LLM 类包一层 LiteLLM,覆盖 100+ provider(OpenAI/Anthropic/Gemini/Ollama/Groq/Bedrock/Vertex…);drop_params/modify_params 抹平差异;ModelRouter.select_model() 按任务能力/预算自动路由到最便宜可用模型;failover / rate_limiter / cost 计量

llm/llm.py:131llm/model_router.py:222
src/praisonai-agents/praisonaiagents/llm/llm.py:131 python
            'audio_output_tokens': self.audio_output_tokens,
        }

class LLM:
    """
    Easy to use wrapper for language models. Supports multiple providers like OpenAI, 
    Anthropic, and others through LiteLLM.
    """
    
    # Class-level flag for one-time logging configuration
    _logging_configured = False
    
    # Class-level cache for LiteLLM module (avoids repeated import overhead)
查看 PraisonAI 完整笔记 →
Semantic Kernel csharp IChatCompletionService(及 ITextGeneration/IEmbeddingGenerator/ITextToImage 等)为统一接口,每厂商一个 Connectors. 包;IAIServiceSelector(默认 OrderedAIServiceSelector) 按 serviceId/modelId 选服务;正向 Microsoft.Extensions.AI.IChatClient 收敛(AsChatCompletionService() 桥接)

IChatCompletionService(及 ITextGeneration/IEmbeddingGenerator/ITextToImage 等)为统一接口,每厂商一个 Connectors. 包;IAIServiceSelector(默认 OrderedAIServiceSelector) 按 serviceId/modelId 选服务;正向 Microsoft.Extensions.AI.IChatClient 收敛(AsChatCompletionService() 桥接)

dotnet/src/SemanticKernel.Abstractions/AI/ChatCompletion/IChatCompletionService.cs:14dotnet/src/Agents/Core/ChatCompletionAgent.cs:261
dotnet/src/SemanticKernel.Abstractions/AI/ChatCompletion/IChatCompletionService.cs:14 csharp
/// <summary>
/// Interface for chat completion services.
/// </summary>
public interface IChatCompletionService : IAIService
{
    /// <summary>
    /// Get chat multiple chat content choices for the prompt and settings.
    /// </summary>
    /// <remarks>
    /// This should be used when the settings request for more than one choice.
    /// </remarks>
    /// <param name="chatHistory">The chat history context.</param>
    /// <param name="executionSettings">The AI execution settings (optional).</param>
查看 Semantic Kernel 完整笔记 →
smolagents python Model 基类统一 generate()/generate_stream(),_prepare_completion_kwargs 把消息归一为 OpenAI 格式 + tools schema;子类覆盖各 provider,支持 stop/structured output/vision

Model 基类统一 generate()/generate_stream(),_prepare_completion_kwargs 把消息归一为 OpenAI 格式 + tools schema;子类覆盖各 provider,支持 stop/structured output/vision

models.py:452models.py:1456models.py:1205models.py:1646
src/smolagents/models.py:452 python
REMOVE_PARAMETER = _ParameterRemove()


class Model:
    """Base class for all language model implementations.

    This abstract class defines the core interface that all model implementations must follow
    to work with agents. It provides common functionality for message handling, tool integration,
    and model configuration while allowing subclasses to implement their specific generation logic.

    Parameters:
        flatten_messages_as_text (`bool`, default `False`):
            Whether to flatten complex message content into plain text format.
查看 smolagents 完整笔记 →
Strands Agents python 框架核心:Model ABC 仅需 stream/structured_output/get_config;13+ provider,默认 BedrockModel(Claude Sonnet);传 str 走 Bedrock model-id,传实例走自定义;stateful 属性标记服务端托管会话

框架核心:Model ABC 仅需 stream/structured_output/get_config;13+ provider,默认 BedrockModel(Claude Sonnet);传 str 走 Bedrock model-id,传实例走自定义;stateful 属性标记服务端托管会话

models/model.py:158models/bedrock.py:72agent.py:231
strands-py/src/strands/models/model.py:158 python
    ttl: str | None = None


class Model(abc.ABC):
    """Abstract base class for Agent model providers.

    This class defines the interface for all model implementations in the Strands Agents SDK. It provides a
    standardized way to configure and process requests for different AI model providers.
    """

    @property
    def stateful(self) -> bool:
        """Whether the model manages conversation state server-side.
查看 Strands Agents 完整笔记 →
Swarm python 仅 OpenAI,硬编码 OpenAI() client,无抽象层

仅 OpenAI,硬编码 OpenAI() client,无抽象层

core.py:8
swarm/core.py:8 python
from typing import List, Callable, Union

# Package/library imports
from openai import OpenAI


# Local imports
from .util import function_to_json, debug_print, merge_chunk
from .types import (
    Agent,
    AgentFunction,
    ChatCompletionMessage,
    ChatCompletionMessageToolCall,
查看 Swarm 完整笔记 →
SwarmClaw typescript buildChatModel:Anthropic 用 ChatAnthropic,其余 23+ provider 全部 OpenAI 兼容(patch baseURL→streamOpenAiChat/ChatOpenAI);含 DeepSeek reasoning bridge、Ollama local/cloud、OpenClaw endpoint、gateway profile

buildChatModel:Anthropic 用 ChatAnthropic,其余 23+ provider 全部 OpenAI 兼容(patch baseURL→streamOpenAiChat/ChatOpenAI);含 DeepSeek reasoning bridge、Ollama local/cloud、OpenClaw endpoint、gateway profile

build-llm.ts:67
src/lib/server/build-llm.ts:67 typescript
 * Uses the provider registry for endpoint defaults — no hardcoded provider list.
 * Anthropic is the only special case (different LangChain class); everything else is OpenAI-compatible.
 */
export function buildChatModel(opts: {
  provider: string
  model: string
  ollamaMode?: 'local' | 'cloud' | null
  apiKey: string | null
  credentialId?: string | null
  apiEndpoint?: string | null
  thinkingLevel?: 'minimal' | 'low' | 'medium' | 'high'
  responseFormat?: GenerationResponseFormat
}) {
查看 SwarmClaw 完整笔记 →
Swarms python 不自研 provider:LiteLLM 包装类持有模型名/参数,run() 内组装 completion_params 调 litellm.completion;自动探测 vision/reasoning 支持,映射 reasoning_effort/thinking_tokens

不自研 provider:LiteLLM 包装类持有模型名/参数,run() 内组装 completion_params 调 litellm.completion;自动探测 vision/reasoning 支持,映射 reasoning_effort/thinking_tokens

utils/litellm_wrapper.py:132litellm_wrapper.py:1151litellm_wrapper.py:1335agent.py:1065
swarms/utils/litellm_wrapper.py:132 python
        return response_content


class LiteLLM:
    """
    A comprehensive wrapper for LiteLLM that provides a unified interface for interacting
    with various Large Language Models (LLMs).

    This class supports multiple model providers including OpenAI, Anthropic, Google,
    and many others through the LiteLLM library. It provides features such as:

    - Text generation with customizable parameters
    - Vision capabilities (image understanding)
查看 Swarms 完整笔记 →
Transformers Agents python llm_engine(HfApiEngine / TransformersEngine / 兼容 OpenAI 等)

llm_engine(HfApiEngine / TransformersEngine / 兼容 OpenAI 等)

查看 Transformers Agents 完整笔记 →
Upsonic python provider/model 字符串 → infer_model() 路由到具体 Model(Runnable 子类);20+ provider(openai/anthropic/google/azure/bedrock/cohere/mistral/groq/xai/ollama/vllm…);model_registry.py 带 benchmark/tier 元数据支持自动选型

provider/model 字符串 → infer_model() 路由到具体 Model(Runnable 子类);20+ provider(openai/anthropic/google/azure/bedrock/cohere/mistral/groq/xai/ollama/vllm…);model_registry.py 带 benchmark/tier 元数据支持自动选型

src/upsonic/models/__init__.py:2064models/__init__.py:655models/model_registry.py:97
src/upsonic/models/__init__.py:2064 python
    # No alias found, return original
    return model_id

def infer_model(  # noqa: C901
    model: Model | KnownModelName | str, provider_factory: Callable[[str], Provider[Any]] = infer_provider
) -> Model:
    """Infer the model from the name.

    Args:
        model:
            Model name to instantiate, in the format of `provider/model`. Use the string "test" to instantiate TestModel.
        provider_factory:
            Function that instantiates a provider object. The provider name is passed into the function parameter. Defaults to `provider.infer_provider`.
查看 Upsonic 完整笔记 →
vectara-agentic python get_llm(role, config)(llm_utils.py:174)按 provider 枚举工厂式实例化 LlamaIndex LLM;支持 OpenAI/Anthropic/Gemini/Together/GROQ/Bedrock/Cohere/Private(OpenAILike)。主 LLM 与工具 LLM 可分别配置(LLMRole.MAIN/TOOL,types.py:52);带 LLM 实例缓存与各 provider 默认模型表

get_llm(role, config)(llm_utils.py:174)按 provider 枚举工厂式实例化 LlamaIndex LLM;支持 OpenAI/Anthropic/Gemini/Together/GROQ/Bedrock/Cohere/Private(OpenAILike)。主 LLM 与工具 LLM 可分别配置(LLMRole.MAIN/TOOL,types.py:52);带 LLM 实例缓存与各 provider 默认模型表

llm_utils.py:174llm_utils.py:19agent_config.py:28
vectara_agentic/llm_utils.py:174 python
        _llm_cache.clear()


def get_llm(role: LLMRole, config: Optional[AgentConfig] = None) -> LLM:
    """
    Get the LLM for the specified role, using the provided config
    or a default if none is provided.

    Uses a cache based on configuration parameters to avoid repeated LLM instantiation.
    """
    if config is None:
        config = AgentConfig()
    # Check cache first
查看 vectara-agentic 完整笔记 →
VoltAgent typescript 直接复用 Vercel AI SDK 的 LanguageModel/EmbeddingModel(OpenAI/Anthropic/Google/Groq/Mistral/xAI/Bedrock/Vertex/Ollama 等十余 provider 作 deps);另有 model-provider-registry 把字符串模型名经 models.dev API 解析为 provider,按 env 自动选 + 本地缓存

直接复用 Vercel AI SDK 的 LanguageModel/EmbeddingModel(OpenAI/Anthropic/Google/Groq/Mistral/xAI/Bedrock/Vertex/Ollama 等十余 provider 作 deps);另有 model-provider-registry 把字符串模型名经 models.dev API 解析为 provider,按 env 自动选 + 本地缓存

registries/model-provider-registry.ts:12registries/model-provider-registry.ts:33core/package.json:5
packages/core/src/registries/model-provider-registry.ts:12 typescript
type EmbeddingModelInstance = Exclude<EmbeddingModel, string>;
export type EmbeddingModelFactory = (modelId: string) => EmbeddingModelInstance;

export type ModelProvider = {
  languageModel: LanguageModelFactory;
  embeddingModel?: EmbeddingModelFactory;
  embedding?: EmbeddingModelFactory;
  textEmbeddingModel?: EmbeddingModelFactory;
  textEmbedding?: EmbeddingModelFactory;
};

export type ModelProviderEntry = ModelProvider | LanguageModelFactory;
export type ModelProviderLoader = () => Promise<ModelProviderEntry>;
查看 VoltAgent 完整笔记 →