Hermes v0.14.0 引入了原生 MCP 工具支持,使您可以轻松地为代理提供实时网络搜索,而无需自定义 API 包装器。本教程将 Scavio 配置为 Hermes 中的 MCP 搜索提供程序,以便您的代理可以使用实时 Web 数据回答问题,而不是仅仅依赖其训练截止时间。
前置条件
- 安装 Hermes Agent v0.14.0 或更高版本
- Python 3.11+
- 来自 https://scavio.dev 的 Scavio API 密钥
- Scavio MCP 服务器包 (pip install scavio-mcp)
操作指南
步骤 1: 安装和配置 Scavio MCP 服务器
安装 Scavio MCP 服务器包并设置 Hermes 将读取的配置文件以发现可用的工具。
# Install the Scavio MCP server
pip install scavio-mcp
# Create the MCP server config
cat > mcp_config.json << 'CONFIG'
{
"mcpServers": {
"scavio": {
"command": "scavio-mcp",
"env": {
"SCAVIO_API_KEY": "your-api-key"
},
"tools": ["web_search", "news_search"]
}
}
}
CONFIG
# Verify the server starts
scavio-mcp --health-check步骤 2: 在 Hermes v0.14.0 中注册 MCP 工具
将 Hermes 指向 MCP 配置文件,以便它在启动时发现 Scavio 工具。 Hermes v0.14.0 读取 MCP 工具架构并将其提供给代理。
from hermes import Agent, MCPToolProvider
# Load MCP tools from config
mcp_provider = MCPToolProvider.from_config("mcp_config.json")
# Create the Hermes agent with MCP tools
agent = Agent(
model="hermes-3",
tools=mcp_provider.get_tools(),
system_prompt="""You are a research assistant with live web search.
Use the web_search tool to find current information.
Always cite your sources with URLs."""
)
# Verify tools are registered
for tool in agent.available_tools:
print(f"Tool: {tool.name} - {tool.description}")步骤 3: 通过代理执行搜索查询
使用触发 Web 搜索的查询运行代理。 Hermes 自动决定何时调用搜索工具并将结果合并到其响应中。
import asyncio
async def research_query(agent: Agent, question: str) -> str:
response = await agent.run(question)
# Access tool call details
for step in response.steps:
if step.tool_call:
print(f"Tool used: {step.tool_call.name}")
print(f"Query sent: {step.tool_call.arguments.get('query')}")
result_count = len(step.tool_call.result.get("results", []))
print(f"Results returned: {result_count}")
return response.final_answer
async def main():
mcp_provider = MCPToolProvider.from_config("mcp_config.json")
agent = Agent(
model="hermes-3",
tools=mcp_provider.get_tools(),
system_prompt="Research assistant with live web search. Cite sources."
)
answer = await research_query(agent, "What are the top MCP servers in May 2026?")
print(f"Answer: {answer}")
asyncio.run(main())Python 示例
import asyncio
from hermes import Agent, MCPToolProvider
async def main():
# Set up MCP tools from Scavio
mcp_provider = MCPToolProvider.from_config("mcp_config.json")
agent = Agent(
model="hermes-3",
tools=mcp_provider.get_tools(),
system_prompt="Research assistant with web search. Always cite sources."
)
# Run a query
response = await agent.run("What are the latest AI agent frameworks in 2026?")
for step in response.steps:
if step.tool_call:
print(f"Searched: {step.tool_call.arguments.get('query')}")
print(f"Results: {len(step.tool_call.result.get('results', []))}")
print(f"Answer: {response.final_answer}")
asyncio.run(main())JavaScript 示例
// mcp_config.json must be in the working directory
// Hermes JS SDK example
import { Agent, MCPToolProvider } from "@hermes-ai/sdk";
const mcpProvider = MCPToolProvider.fromConfig("mcp_config.json");
const agent = new Agent({
model: "hermes-3",
tools: mcpProvider.getTools(),
systemPrompt: "Research assistant with web search. Cite sources."
});
async function main() {
const response = await agent.run("Latest AI agent frameworks in 2026?");
for (const step of response.steps) {
if (step.toolCall) {
console.log("Searched:", step.toolCall.arguments.query);
console.log("Results:", (step.toolCall.result.results || []).length);
}
}
console.log("Answer:", response.finalAnswer);
}
main();预期输出
Tool: web_search - Search the web using Scavio
Searched: latest AI agent frameworks 2026
Results: 10
Answer: Based on current web results, the top AI agent frameworks in 2026 include...