一款双语言统一 LLM SDK,支持 GPT/Claude/Gemini 等多模型无缝切换,提供零代码修改的多模型接入、标准化工具调用与细粒度追踪能力,内置 Web UI 调试工具。
项目概述#
AgentHub SDK 是由 Prism-Shadow 组织开发的开源工具包(Apache-2.0 许可),旨在解决多 LLM 提供商接口碎片化、切换成本高以及 Agent 调试困难的问题。通过定义 UniMessage、UniConfig、UniEvent 等统一数据结构,屏蔽底层模型差异,允许开发者通过修改 model 参数即可在多个模型间零成本切换。
核心价值:
- 统一接口封装,屏蔽不同厂商 API 差异
- 支持异步流式响应处理
- 内置细粒度追踪功能,无需数据库依赖
- 双语言支持(Python >=3.11, TypeScript)
核心能力#
AutoLLMClient#
核心客户端类,支持通过 model 参数(如 gpt-5.2, claude-4.5, gemini-3)自动路由至对应 SDK,实现零代码修改切换模型。
支持的模型#
- Gemini 3 (Official): 支持推理、工具调用、图像理解
- Claude 4.5 (Official): 支持推理、工具调用、图像理解
- GPT-5.2 (Official): 支持推理、工具调用、图像理解
- GLM-5 (Official/OpenRouter/SiliconFlow): 支持推理、工具调用
- Qwen3 (OpenRouter/SiliconFlow/vLLM): 支持推理、工具调用
主要功能#
- 统一接口: 为不同 LLM 提供一致且直观的接口进行 Agent 开发
- 精准处理: 自动处理多步工具调用过程中的交错思考,防止性能下降
- 可追溯性: 通过
trace_id参数实现轻量级细粒度追踪 - 细粒度 Token 统计: 区分 cached_tokens、prompt_tokens、thoughts_tokens、response_tokens
安装部署#
Python (PyPI)#
uv add agenthub-python
# 或
pip install agenthub-python
TypeScript (npm)#
npm install @prismshadow/agenthub
快速开始示例#
import asyncio
import os
from agenthub import AutoLLMClient
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"
async def main():
client = AutoLLMClient(model="gpt-5.2")
async for event in client.streaming_response_stateful(
message={"role": "user", "content_items": [{"type": "text", "text": "Hello!"}]},
config={"temperature": 1.0}
):
print(event)
asyncio.run(main())
核心 API#
streaming_response: 无状态方法,需每次传递完整消息历史streaming_response_stateful: 有状态方法,内部自动维护对话历史clear_history(): 清除对话历史get_history(): 获取对话历史
集成工具#
Tracer Web Server#
from agenthub.integration.tracer import Tracer
tracer = Tracer()
tracer.start_web_server(host="127.0.0.1", port=5000)
LLM Playground#
from agenthub.integration.playground import start_playground_server
start_playground_server(host="127.0.0.1", port=5001)
项目结构#
├── src_py/ # Python 实现
├── src_ts/ # TypeScript 实现
└── llmsdk_docs/ # 各模型专用文档
版本信息#
- 当前版本: v0.2.0
- 许可证: Apache-2.0
- 主要语言: Python (52.5%), TypeScript (47.2%)
注意: 文档中提及的 GPT-5.2、Claude 4.5、Gemini 3 等模型名称版本号较高,具体对应版本待确认。npm 包因 Cloudflare 保护无法完全验证。