来源:NousResearch Hermes 3 · Hermes Function Calling · Hermes 3 Technical Report | 整理时间:2026-04-11
为什么要关注 Hermes?
Hermes 3 是 2025-2026 年开源 Agent 场景里讨论度很高的一条路线:
- 对函数调用(Tool Calling)和结构化输出有专门训练
- 可本地部署,适合私有数据和成本可控场景
- 生态支持 GGUF、vLLM、Transformers,落地门槛较低
如果你想做“可控、可审计、可离线”的 Agent,Hermes 是值得上手的开源方案。
核心能力一览
| 能力 | Hermes 3 表现 | 适用场景 |
|---|---|---|
| 函数调用 | 支持多工具调用模板,输出格式稳定 | Agent 调 API、查库、执行动作 |
| 结构化输出 | 可按 Schema 输出 JSON | 表单抽取、流程自动化 |
| 对话连续性 | 多轮一致性较好 | 长任务执行与状态跟踪 |
| 本地部署 | 支持 GPU、本地推理框架 | 隐私敏感、内网系统 |
Hermes 的 Agent 执行链路
[用户问题]
↓
[Hermes 3 推理]
↓ (生成 tool_call JSON)
[应用层解析 tool_call]
↓
[执行真实工具函数/API]
↓ (tool_response)
[再次喂给 Hermes]
↓
[最终自然语言结果]
重点:Hermes 会负责“决定调用哪个工具”,但真正执行工具的责任在你的应用层。
最小可运行示例(Python + Transformers)
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = "NousResearch/Hermes-3-Llama-3.1-8B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{"role": "system", "content": "You are a function calling assistant."},
{"role": "user", "content": "帮我查询 TSLA 的基本面数据"},
]
prompt = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=256, temperature=0.2)
text = tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
print(text)
函数调用模板示例
Hermes 官方建议在系统提示里提供工具签名,然后让模型返回工具调用对象。
You are a function calling AI model.
You are provided with function signatures within <tools></tools>.
{
"type": "function",
"function": {
"name": "get_weather",
"description": "根据城市获取天气",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string" }
},
"required": ["city"]
}
}
}
模型输出(示例):
<tool_call>
{"arguments": {"city": "上海"}, "name": "get_weather"}
</tool_call>
应用层解析后执行 get_weather,再把结果作为 tool 角色消息回传给模型。
结构化输出(JSON Mode)
在需要稳定字段时,推荐强制 Schema 输出:
schema = {
"type": "object",
"properties": {
"risk_level": {"type": "string"},
"summary": {"type": "string"},
"actions": {
"type": "array",
"items": {"type": "string"}
}
},
"required": ["risk_level", "summary", "actions"]
}
典型用途:
- 工单分类与路由
- 安全审计结果结构化
- Agent 的中间状态持久化
部署方式对比
| 方式 | 优点 | 缺点 | 建议 |
|---|---|---|---|
| Transformers 直跑 | 灵活、调试方便 | 吞吐有限 | 本地开发和实验 |
| vLLM 服务化 | 高吞吐、OpenAI 兼容接口 | 部署稍复杂 | 团队共享推理服务 |
| GGUF + llama.cpp | 轻量、资源占用可控 | 性能和能力依量化而变 | 边缘设备/轻量场景 |
vLLM 启动示例:
vllm serve NousResearch/Hermes-3-Llama-3.1-8B
与主流 Agent 模型路线对比
| 维度 | Hermes 3 | 闭源旗舰模型 |
|---|---|---|
| 可控性 | 高(可本地、可改造) | 中(依赖平台策略) |
| 成本结构 | 固定算力成本 | 按调用计费 |
| 上线速度 | 中(需部署) | 高(API 即用) |
| 隐私合规 | 强(内网可跑) | 依赖供应商合规能力 |
实践建议:核心隐私链路用 Hermes,本地快速迭代;对极限推理难题按需回退到云端强模型。
常见坑与排查
- 工具调用格式不稳定:先固定 system prompt,再降低温度(如 0.1-0.3)。
- JSON 输出偶发多余文本:在提示中明确“仅返回 JSON 对象”。
- 多工具串联失败:把复杂流程拆成“单步可验证”的状态机,不要让模型一次规划过长链路。
- 延迟偏高:优先上 vLLM 并开启批处理,再考虑模型量化。