aisuite Skill:一行代码切换全球主流 LLM 提供商的 Agent 开发框架

总结

aisuite 是一个轻量级 Python 库,通过统一的 Chat Completions API 和完整的 Agents API,让开发者用同一套代码无缝切换 OpenAI、Anthropic、Google、Ollama 等 10+ 家 LLM 提供商。它不绑平台、不锁供应商,开发者一行切换模型,搭配现成的文件/Git/Shell 工具包和 MCP 支持,快速搭建生产级 AI Agent。截至 2026-08-02,GitHub 已斩获 15,872 Star,周增 584,是当前多 Provider 接入场景下最热门的开源基础设施之一。

功能与原则

aisuite 在设计上遵循两条核心原则:统一抽象 + 最小侵入

第一层是 Chat Completions API:以 OpenAI 的标准接口为基准,对所有 Provider(Anthropic、Google、Mistral、Hugging Face、AWS、Cohere、Ollama、OpenRouter 等)做统一封装。开发者只需改一个字符串(如 "anthropic:claude-sonnet-4-6" 换成 "openai:gpt-4o"),即可切换 Provider,无需重写调用逻辑。

第二层是 Agents API:包含工具调用(Tools)、预建工具包(Toolkits)和工具策略(Tool Policies)。传入普通 Python 函数,aisuite 自动生成 schema、执行调用、回收结果;也可以直接挂载文件/Git/Shell 等现成工具包,或接入任何 MCP Server,一条配置即可。

认可度

  • GitHub Star:截至 2026-08-02,共 15,872 ⭐,本周新增 584
  • Trending:登顶 GitHub Trending 周榜(Python 类目)
  • 生态延伸:同作者基于 aisuite 打造了 OpenWorker 桌面 AI 助手,提供 macOS/Windows 下载,可完成文件读取、Slack/邮件集成、PDF 生成、自动化调度等日常任务
  • License:MIT,可商用

链接

GitHub:https://github.com/andrewyng/aisuite

原作者

andrewyng(GitHub)— 专注于 AI 基础设施与 Agent 开发,aisuite 是其最具影响力的开源项目,同期还孵化了 OpenWorker 桌面 AI 助手产品。

介绍

aisuite 诞生于一个朴素的诉求:每个 LLM Provider 都有自己的 SDK 和接口约定,在它们之间切换意味着大量样板代码。aisuite 用一个轻薄的 adapter 层解决了这个问题——所有 Provider 被映射为统一的 client.chat.completions.create() 接口,参数风格完全兼容 OpenAI 的标准格式,开发者不需要学习新的 SDK。

在接口统一之上,aisuite 构建了完整的 Agent 开发框架。工具调用从「手动拼 JSON schema + 手动执行循环」变成了「传入 Python 函数 + 设置 max_turns」,剩余的工作库全部包办。对于复杂的多步骤任务,Agents API 提供了状态持久化(内存/文件/Postgres)、Artifact 追踪和 Tool Policies(审批/白名单/自定义策略),足以支撑生产环境。

此外,aisuite 原生支持 Model Context Protocol(MCP),任何 MCP Server 的工具集可以通过 npx @modelcontextprotocol/server-filesystem 这样的命令直接注入到 Agent 的工具链中,无需编写额外适配代码。

特点

  • 一行切换 Provider:字符串 "provider:model" 替换即可换模型,代码零改动
  • 统一 Tool Calling:Python 函数直接作为工具,aisuite 自动生成 schema、执行、回收结果
  • 预建 Toolkits:文件操作、Git、Shell 开箱即用,无需从零构建
  • MCP 原生支持:通过 adapter 机制接入任意 MCP Server,扩展无上限
  • 生产级 Agent 框架:状态持久化、Tool Policies、Artifact 追踪,构建可靠 Agent 所需的全套能力
  • Stream 支持:所有支持 streaming 的 Provider 均可用统一的迭代器方式消费
  • 轻量依赖:基础包零 Provider SDK,可按需选择性安装(如 pip install 'aisuite[anthropic]'

使用方法

安装

pip install aisuite                           # 基础包
pip install 'aisuite[anthropic]'              # 加 Anthropic
pip install 'aisuite[all]'                    # 装全部 Provider

快速开始——多 Provider 对比

import aisuite as ai
client = ai.Client()

models = ["openai:gpt-4o", "anthropic:claude-3-5-sonnet-20240620"]
messages = [
    {"role": "system", "content": "Respond in Pirate English."},
    {"role": "user", "content": "Tell me a joke."}
]

for model in models:
    response = client.chat.completions.create(
        model=model, messages=messages, temperature=0.75
    )
    print(response.choices[0].message.content)

工具调用

import aisuite as ai
client = ai.Client()

def will_it_rain(location: str, time_of_day: str) -> str:
    """Check weather for a location at given time."""
    return "YES"

response = client.chat.completions.create(
    model="openai:gpt-4o",
    messages=[{"role": "user", "content": "I live in San Francisco. Plan an outdoor picnic at 2pm."}],
    tools=[will_it_rain],
    max_turns=2
)
print(response.choices[0].message.content)

Agent + Toolkits

import aisuite as ai
from aisuite import Agent, Runner

agent = Agent(
    name="repo-helper",
    model="anthropic:claude-sonnet-4-6",
    instructions="You are a careful repo assistant. Use your tools to answer from the code.",
    tools=[*ai.toolkits.files(root="."), *ai.toolkits.git(root=".")],
)

result = Runner.run(agent, "What changed in the last commit? Summarize in 3 bullets.")
print(result.final_output)

使用场景与人群

  • 多 Provider 评测/对比:同时调用多个模型跑同一组 prompt,横向对比输出质量,用于模型选型
  • Agent 开发:需要快速给 LLM 接工具、搭循环、做策略控制的开发者
  • 跨平台迁移:从 OpenAI 切换到 ClaudeGemini,不想重写业务逻辑的团队
  • MCP 生态接入:使用 MCP Server 的开发者,希望在 Agent 中统一使用 MCP 工具
  • 企业级 Agent 平台:需要 Tool Policies(审批流)、状态持久化、Trace 能力的生产系统

目标用户:AI 应用开发者、后端工程师、DevOps / MLOps 工程师、技术产品经理。

输入与输出案例

案例 1:多模型横向对比

输入(.messages):

[{"role": "user", "content": "解释量子纠缠,用 50 字"}]

输出:同一个 prompt 并发发给 openai:gpt-4oanthropic:claude-3-5-sonnet-20240620,两条回答并行返回,开发者自行对比质量。

案例 2:带工具调用的天气查询 + picnic 规划

输入:用户说”我在旧金山,帮我查天气并安排下午 2 点的户外野餐”。

Agent 自动判断需要调用 will_it_rain 工具,执行后获得天气结果,再生成野餐建议。最终回复:

It looks like it will rain in San Francisco today, so an outdoor picnic at 2pm isn’t ideal. I’d recommend moving the picnic indoors or rescheduling to a clearer day! 🏠


Star:15,872 ⭐(截至 2026-08-02)

GitHub:https://github.com/andrewyng/aisuite


GitHub: https://github.com/andrewyng/aisuite

评论区

0 条评论

登录后可评论。

Skill超级捕获手 12 阅读