最近被问的比较多:搭智能体,通常用啥大,比较顺手?
当时第一反应是:“搭?用开源,再+AI按需求改。”
按我的想法:开源领域已经有 OpenCode这种编程智能体,有 龙虾 OpenClaw这种个人助手智能体,更古早的 LangChain 框架(新的框架 LangGraph),Dify 大模型的低代码平台,为什么还要自己搭?
再细问下去,原来是企业内的需求,希望开发一个智能体(平台),能将现有业务系统粘合起来,又或者领导需要一个“智能体”帮助他及时了解公司财务数据。
由于在企业内部用,必然要求智能体的安全与合规。
其实按我的看法,企业业务集成智能体,确切的说,本质是"AI驱动的业务流程重排"。
比较合适的路径:先用 Dify 跑通业务逻辑,做 DEMO/POC 验证需求真实存在后,再决定是否在 LangGraph / CrewAI / AutoGen + 自研核心网关等框架基础上自研生产系统。
客户经常会要求说搭一个智能体,这个就是像互联网时代,需求是写一个网站,还是需要进一步引导客户挖掘需求,再有针对业务场景定制方案。
寻找这个问题答案,翻开源项目时,发现吴恩达的开源仓库有两个好东西:
一个桌面 AI 助手 OpenCoworker,可以聊天,还能进行深度研究,读取文件,创建 PDF 报告、文档、电子表格,支持定时自动化操作。
跟我现在常用的 WorkBuddy 比较像,但是它后面需要自己买大模型会员,填 API Key 才能用。
另一个是 OpenCoworker 用的底层库 aisuite,用统一 API 打通所有主流大模型。
OpenCoworker 是一个桌面 AI 代理,自动化、连接器、MCP、记忆、大模型供应商切换、工具调用、子代理、Web 界面,这些都帮你做好了。
macOS(Apple Silicon,M1 及以上)和 Windows 10/11 都有安装包。
安装完界面是这样:

Windows 下载 EXE,首次运行时 SmartScreen 会弹警告,选"更多信息"再选"仍要运行"即可。
打开应用后,选一个大模型供应商,粘贴 API Key。
支持 OpenAI、Anthropic(Claude)、Google(Gemini)。
也可以选 Ollama,完全本地运行。
OpenCoworker 没有后端服务器,数据不经手第三方。
可以同时连接多个供应商,在对话中随时切换模型。
API Key、对话记录、文件,全部留在你的机器上。
模型调用直接本地直连供应商,中间不经过 OpenCoworker 的服务器。
OpenCoworker 的源码在仓库的 platform/ 目录下,基于 aisuite 构建。
如果你想搭一个自己的智能体框架,这就是现成的参考实现。
aisuite 是一个轻量级 Python 库,解决一个核心痛点:不同大模型供应商的 API 各不相同,切换模型意味着改大量代码。
aisuite 的做法是,提供一套统一的 OpenAI 风格接口,覆盖所有主流供应商。
目前支持 11 个供应商:
OpenAI(GPT 系列),Anthropic(Claude 系列),Google(Gemini 系列),Mistral,Hugging Face(开源模型),AWS(Amazon Bedrock),Cohere,Ollama(本地模型),OpenRouter(多模型路由),Groq(高速推理),Nebius(云 AI 平台)。
模型名称用 <provider>:<model-name> 格式。
比如 openai:gpt-4o 或 anthropic:claude-sonnet-4-6。
aisuite 会自动路由到正确的供应商,翻译参数和响应格式。
如果只用 OpenAI,装基础包再单独装 openai SDK 也行。 按需安装,不浪费空间。
只需要为你实际调用的供应商设置 Key。
通过环境变量设置:
export OPENAI_API_KEY="your-openai-api-key"
export ANTHROPIC_API_KEY="your-anthropic-api-key"也可以在代码里直接传给 Client 构造函数:
client = ai.Client({"openai": {"api_key": "..."}})同一段代码,循环调用两个不同供应商的模型:
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)切换模型只是改了 model 参数里的字符串。
messages、temperature 这些参数对所有供应商都一样,aisuite 在底层帮你做了翻译。
核心参数(temperature、max_tokens、tools 等)都是跨供应商通用的。
用 Ollama 跑本地模型,不需要 API Key:
response = client.chat.completions.create(
model="ollama:llama3.3",
messages=[{"role": "user", "content": "Hello!"}],
)一行 ollama:llama3.3 就从云端模型切到本地模型了。
写一个普通的 Python 函数,aisuite 从函数签名和 docstring 自动生成工具 schema,执行调用,把结果喂回模型。
import aisuite as ai
def will_it_rain(location: str, time_of_day: str):
"""Check if it will rain in a location at a given time today.
Args:
location (str): Name of the city
time_of_day (str): Time of the day in HH:MM format.
"""
return "YES"
client = ai.Client()
response = client.chat.completions.create(
model="openai:gpt-4o",
messages=[{
"role": "user",
"content": "I live in San Francisco. Can you check for weather "
"and plan an outdoor picnic for me at 2pm?"
}],
tools=[will_it_rain],
max_turns=2
)
print(response.choices[0].message.content)关键在 tools=[will_it_rain] 和 max_turns=2。
直接把函数对象放进列表传给 tools 参数。
aisuite 读取函数的参数类型注解和 docstring,自动生成符合 OpenAI 格式的工具描述。
模型决定调用工具时,aisuite 执行函数,把返回值发回模型,模型继续推理。
max_turns=2 表示最多来回两轮工具调用,整个循环是自动的。
response.choices[0].intermediate_messages 保存了完整的工具交互历史。
把它追加到 messages 列表里,就可以继续对话。
如果需要更精细的控制,比如自定义错误处理、选择性执行、或者接入已有的工具管道,可以省略 max_turns,手动传 JSON 格式的工具规范:
tools = [{
"type": "function",
"function": {
"name": "will_it_rain",
"description": "Check if it will rain in a location at a given time today",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "Name of the city"},
"time_of_day": {"type": "string", "description": "Time of the day in HH:MM format."}
},
"required": ["location", "time_of_day"]
}
}
}]
response = client.chat.completions.create(
model="openai:gpt-4o",
messages=messages,
tools=tools
)这种模式下,aisuite 返回模型的工具调用请求,由你来决定执行、验证还是过滤。
两种风格可以混用,看场景选择。
对于更复杂的、长时间运行的任务,aisuite 提供了 Agents API。 声明一个 Agent,然后用 Runner 执行。
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)定义了一个叫 repo-helper 的代理,用 Claude Sonnet 模型。
给它挂了两组工具:文件操作工具包(限定在当前目录 . 下)和 git 工具包。
然后用 Runner.run 执行,传入用户指令。
工具包(Toolkits)是预构建的、沙盒化的工具集合。
目前有文件操作、git 操作和 Shell 命令三种。
直接用 ai.toolkits.files(root=".") 就能拿到一组文件读写工具,不需要自己写。
Agents API 还提供了一系列生产级功能:
工具策略:用 RequireApprovalPolicy 控制哪些工具需要人工审批。
用 AllowToolsPolicy 或 DenyAllToolPolicy 做允许/拒绝列表。
也可以传一个自定义 callable,接收 ToolPolicyContext 做更细粒度的控制。
状态存储:持久化运行状态,跨进程恢复对话。
支持 InMemoryStateStore(内存)、FileStateStore(文件)和 PostgresStateStore(PostgreSQL)。
通过 thread_id 关联同一次会话。
Artifacts:存储代理产出的文件。
支持 FileArtifactStore 和 InMemoryArtifactStore。
Tracing:每次运行的结果 RunResult 都携带完整的执行步骤、原始响应和 trace_id。
可以接入 trace sink 做可观测性。
aisuite 原生支持 Model Context Protocol。 任何 MCP 服务器的工具都能直接传给模型,需要先装 MCP 依赖:
pip install 'aisuite[mcp]';简单场景用内联配置,直接在 tools 参数里声明 MCP 服务器:
response = client.chat.completions.create(
model="openai:gpt-4o",
messages=[{"role": "user", "content": "List the files in the current directory"}],
tools=[{
"type": "mcp",
"name": "filesystem",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/directory"]
}],
max_turns=3
)复杂场景用显式客户端,创建一次复用多次,支持安全过滤和工具前缀:
from aisuite.mcp import MCPClient
mcp = MCPClient(
command="npx",
args=["-y", "@modelcontextprotocol/server-filesystem", "/path/to/directory"]
)
response = client.chat.completions.create(
model="openai:gpt-4o",
messages=[{"role": "user", "content": "List the files"}],
tools=mcp.get_callable_tools(),
max_turns=3
)
mcp.close()用完记得 mcp.close() 释放资源。
如果 aisuite 内置的供应商不够用,可以自己写。
在 providers/ 目录下新建一个文件,命名规则是 <provider>_provider.py。
类名规则是 <Provider>Provider,首字母大写。
比如要添加一个叫 mycloud 的供应商:
文件名:providers/mycloud_provider.py
类名:MycloudProvider
继承 BaseProvider,实现必要的方法。
之后就能用 mycloud:some-model 的格式调用了。
aisuite 还附带两个实用工具:
Agent Runs Viewer:一个本地 Web 查看器,用于检查代理运行记录和执行轨迹。
调试代理时非常有用,能看到每一步的输入输出。
aisuite-code CLI:一个编码代理命令行工具。
可以在终端里直接用 aisuite 做代码相关任务。
仓库地址:https://github.com/andrewyng/aisuite
推荐阅读:
Loop Engineering 如何使用AI编程智能体:构建可循环系统
Claude Fable 5 系统提示词曝光:Anthropic 为适应最强大模型做了哪些改动?