模型、工具与 Agent
与常见的 LLM 聚合器仅统一模型不同,BitRouter 聚合了模型、工具和 Agent,使服务可以以高度灵活、Agent 原生的方式进行组合和集成。
服务原语
在 BitRouter 上注册的所有服务都属于三种原语之一:模型、工具和 Agent,以其 API 标准进行区分。
单个服务可以同时实现多种原语。
模型
模型服务通过 OpenAI/Anthropic/Google 兼容的端点提供 LLM 推理能力(默认为 openai-chat/completion)。
// Request
POST /v1/chat/completions
{
"model": "deepseek/deepseek-v3.2",
"messages": [
{ "role": "user", "content": "Hello" }
]
}
// Response
{
"id": "chatcmpl-123",
"choices": [{
"message": { "role": "assistant", "content": "Hi there!" }
}]
}多模态支持
模型可以支持文本之外的多种输入和输出模态:
- 视觉:向支持视觉的模型发送图像进行分析、描述和 OCR
- 图像生成:使用兼容模型从文本提示生成图像
多模态输入使用相同的 /v1/chat/completions 端点。图像可以作为直接 URL(https://example.com/image.jpg)或 base64 编码数据(data:image/jpeg;base64,{data})提供。
访问 Marketplace 查找支持所需模态的模型。
工具(MCP)
工具服务遵循 MCP (Model Context Protocol) 标准,通过 JSON-RPC 2.0 暴露功能。BitRouter 作为 MCP 代理,通过单一网关将你的 Agent 连接到 MCP 工具服务器。
// 发现可用工具
{ "jsonrpc": "2.0", "id": 1, "method": "tools/list" }
// 调用工具
{ "jsonrpc": "2.0", "id": 2, "method": "tools/call",
"params": { "name": "web_search", "arguments": { "query": "latest AI news" } } }配置 MCP 服务器
mcp_servers:
- name: "github"
transport:
type: stdio
command: "npx"
args: ["-y", "@modelcontextprotocol/server-github"]
env:
GITHUB_TOKEN: "${GITHUB_TOKEN}"
- name: "remote-tools"
transport:
type: http
url: "http://localhost:3000/mcp"
headers:
Authorization: "Bearer ${TOOLS_TOKEN}"| 传输类型 | 描述 |
|---|---|
stdio | 启动本地进程,通过 stdin/stdout 通信 |
http | 通过 HTTP+SSE 连接远程 MCP 服务器 |
工具过滤
限制 MCP 服务器暴露的工具:
mcp_servers:
- name: "github"
transport:
type: stdio
command: "npx"
args: ["-y", "@modelcontextprotocol/server-github"]
tool_filter:
allow: ["search_repositories", "get_file_contents"]服务器分组
将 MCP 服务器组织为命名分组以进行访问控制:
mcp_groups:
dev_tools: ["github", "jira"]
comms: ["slack", "email"]支持的 MCP 方法
| 方法 | 描述 |
|---|---|
initialize | 初始化 MCP 会话 |
ping | 健康检查 |
tools/list | 列出可用工具 |
tools/call | 调用工具 |
resources/list | 列出资源 |
resources/read | 读取资源 |
resources/templates/list | 列出资源模板 |
resources/subscribe | 订阅资源更新 |
resources/unsubscribe | 取消订阅更新 |
prompts/list | 列出可用提示 |
prompts/get | 获取特定提示 |
logging/setLevel | 设置服务器日志级别 |
completion/complete | 请求补全 |
端点: POST /mcp(JSON-RPC)和 GET /mcp/sse(服务器推送事件流)。
尚未支持:tasks/*、sampling/createMessage、roots/list、elicitation/create 和 Streamable HTTP 传输。这些在路线图中。
Agent(ACP)
Agent 服务遵循 Zed Industries 的 ACP(Agent Communication Protocol)协议,通过基于 HTTP 的 JSON-RPC 2.0 实现自主的 Agent 间通信。
配置上游 Agent
acp_agents:
- name: "research-agent"
url: "https://research.example.com"
headers:
Authorization: "Bearer ${RESEARCH_TOKEN}"
- name: "search-agent"
url: "https://search.example.com"
card_path: "/custom/card.json" # 默认为 /.well-known/agent-card.json支持的 ACP 方法
JSON-RPC(POST /acp):
| 方法 | 描述 |
|---|---|
message/send | 向 Agent 发送消息 |
message/stream | 流式消息响应(SSE) |
tasks/get | 获取任务状态和历史 |
tasks/list | 列出任务 |
tasks/cancel | 取消正在运行的任务 |
tasks/resubscribe | 重新订阅任务更新(SSE) |
agent/getAuthenticatedExtendedCard | 获取已认证的 Agent 卡片 |
REST 端点:
| 方法 | 路径 | 描述 |
|---|---|---|
GET | /.well-known/agent-card.json | 标准 Agent 卡片发现 |
POST | /message:send | 发送消息 |
POST | /message:stream | 流式消息(SSE) |
GET | /tasks/{id} | 获取特定任务 |
GET | /tasks | 列出所有任务 |
POST | /tasks/{id}:cancel | 取消任务 |
示例:发送消息
curl -X POST http://localhost:8787/acp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "message/send",
"params": {
"message": {
"role": "user",
"parts": [{"kind": "text", "text": "总结最近的机器学习论文"}]
}
}
}'传输协议为 HTTP(JSON-RPC + REST)并支持 SSE 流式传输。目前不支持 gRPC。
Agent Skills
BitRouter 支持 Agent Skills 开放标准,用于注册 Agent 可以发现和使用的提示级知识。技能是 SKILL.md 文件——注入到 LLM 上下文中的结构化提示——与提供运行时工具连接的 MCP 工具不同。
| 技能 | MCP 工具 | |
|---|---|---|
| 内容 | 提示级知识(SKILL.md) | 运行时工具调用(JSON-RPC) |
| 时机 | 推理前注入到 LLM 上下文 | 推理期间由 LLM 调用 |
| 发现 | GET /v1/tools(统一) | GET /v1/tools(统一) |
配置技能
skills:
- name: "code-review"
description: "审查代码质量、安全问题和最佳实践"
source: "https://github.com/anthropics/skills"
required_apis:
- provider: anthropic
- name: "translate"
description: "使用 LLM 驱动的翻译在语言之间翻译文本"技能也可以通过 CLI 安装:
npx skills add BitRouterAI/agent-skills技能 API
| 方法 | 路径 | 描述 |
|---|---|---|
POST | /v1/skills | 注册新技能 |
GET | /v1/skills | 列出所有已注册技能 |
GET | /v1/skills/:name | 获取特定技能 |
DELETE | /v1/skills/:name | 删除技能 |
统一工具发现
所有 MCP 工具和技能通过单一端点可发现:
curl http://localhost:8787/v1/tools[
{
"name": "code-review",
"type": "skill",
"description": "审查代码质量、安全问题和最佳实践"
},
{
"name": "github:search_repositories",
"type": "mcp_tool",
"description": "搜索 GitHub 仓库"
}
]最佳实践
单个服务可以根据使用场景暴露不同的原语。选择合适的原语有助于 AI Agent 更高效地与 BitRouter 交互。
示例:AI 研究 Agent
| 使用场景 | 推荐原语 | 协议 |
|---|---|---|
| 前端应用的后端 | 模型 | Chat/Completion |
| 供其他 Agent 调用的工具 | 工具 | MCP |
| 自主的 Agent 间交互 | Agent | ACP |
How is this guide?
Last updated on