返回资讯中心
外部精选
大数据
#数据科学#机器学习

开发者用Hermes Agent和Ollama搭建本地多智能体旅行规划器

来源标题:What I Did with Hermes Agent, Ollama & Local Models

开发者利用Hermes Agent、Ollama和本地模型gemma4:31b构建了一个多智能体旅行规划系统,由一个协调者调度三个专职智能体,分别负责目的地调研、住宿推荐和生成真实的Google Flights搜索链接。配置通过Ollama本地端点(localhost:11434)接入,无需API key。

KDnuggetsShittu Olumide2026/11/5 · 12 天前16 分钟阅读

以下正文由 AI 翻译自 KDnuggets(原文版权归原站所有),可能存在偏差,重要内容请以原文为准。

curl -fsSL https://ollama.com/install.sh | sh 拉取一个真正支持工具调用的模型。前面说的道理在这里同样适用:不支持工具调用的模型只能聊天,无法真正委派任务或调用自定义工具,而这恰恰是多 agent 团队的核心所在。 ollama pull gemma4:31b 代码说明:gemma4:31b 之所以值得多占一些内存,是因为这个项目要在四个独立的 agent 之间分派任务,并调用一个自定义 Python 工具,这两件事都要求模型能可靠地判断何时以及如何调用工具,而不只是生成流畅的文本。 在 ~/.hermes/config.yaml 中把 Hermes 指向 Ollama 的本地端点: model: default: "gemma4:31b" provider: "custom" base_url: "http://localhost:11434/v1" 代码说明:provider: "custom" 告诉 Hermes 把它当作一个通用的 OpenAI 兼容端点,base_url 则指向本地 11434 端口上运行的 Ollama。不需要 API key,因为 Ollama 根本不校验。

这才是真正的架构。一个根协调者接收旅行请求,然后把任务分派给三个专家,每个专家都有狭窄而明确的职责。 agents: root: description: "Travel planning coordinator" instruction: | You are a travel planning coordinator. When given a trip request, delegate destination research to destination-scout, accommodation guidance to stay-finder, and flight options to flight-finder. Combine their findings into one clear trip briefing. sub_agents: [destination-scout, stay-finder, flight-finder] toolsets:

  • type: think
  • type: memory path: ./trip_preferences.db destination-scout: description: "Researches destinations, attractions, and entry requirements" instruction: | Search the web for current information on the requested destination: notable places to visit, best time of year, and any visa or entry requirements. Always search fresh for entry requirements, never answer from memory, since these change and being wrong has real consequences for travelers. Cite where each fact came from. toolsets:
  • type: mcp ref: docker:duckduckgo stay-finder: description: "Finds well-regarded neighborhoods and accommodation types" instruction: | Search the web for current, well-regarded recommendations on where to stay in the destination, neighborhoods, accommodation styles, and typical price ranges from recent travel sources. Never invent specific listings or prices, only report what current sources actually say. toolsets:
  • type: mcp ref: docker:duckduckgo flight-finder: description: "Builds real flight search links and current price context" instruction: | Given an origin, destination, and travel dates, use the build_flight_search_url tool to generate a real search link. Also search the web briefly for current typical fare ranges on this route, clearly labeling them as approximate. toolsets:
  • type: mcp ref: docker:duckduckgo
  • type: custom path: ./tools/flight_link.py 代码说明:root 上的 sub_agents 列表正是把四个独立的 agent 定义变成一个协同团队的关键,它让协调者获得一个内置工具,可以把任务分派给任意指定的专家,并等它返回结果后再继续。

注意 destination-scout 里那条明确的指令:入境要求必须每次重新搜索,不能凭模型自己的训练数据作答。这是一个刻意的、重要的安全选择:签证和入境规则会变,模型自信地复述记忆中的过期信息在这里不是小错,而是那种可能让人到了机场却发现证件不对的错误。

stay-finder 在价格上也遵循同样的纪律:明确要求绝不编造具体数字,只报告真实、当前来源实际说了什么。flight-finder 是唯一拥有两个工具集的 agent —— 一个用于获取背景信息的网页搜索,以及一个指向 Python 文件的自定义工具,也就是整个项目赖以成立的、诚实的航班搜索机制。

这是整个项目所依赖的诚实之处。由于目前不存在免费、实时的航班价格 API,实际且真正有用的做法是用自然语言查询参数生成一个真实的 Google Flights 搜索 URL —— 这完全不需要 API key,而且生成的链接确实可用。

tools/flight_link.py

import urllib.parse from datetime import datetime def build_flight_search_url(origin: str, destination: str, depart_date: str, return_date: str | None = None) -> str: """Builds a real Google Flights search URL. Raises ValueError on malformed input rather than silently producing a broken link.""" if not origin.strip() or not destination.strip(): raise ValueError("Origin and destination cannot be empty") try: datetime.strptime(depart_date, "%Y-%m-%d") except ValueError: raise ValueError(f"depart_date must be in YYYY-MM-DD format, got '{depart_date}'") query = f"Flights from {origin.strip()} to {destination.strip()} on {depart_date}" if return_date: try: datetime.strptime(return_date, "%Y-%m-%d") except ValueError: raise ValueError(f"return_date must be in YYYY-MM-DD format, got '{return_date}'") query += f" returning {return_date}" encoded_query = urllib.parse.quote(query) return f"https://www.google.com/travel/flights?q={encoded_query}" 代码说明:urllib.parse.quote 正是让这段代码真正可靠、而非脆弱字符串拼接的关键;它对查询中的每个空格和特殊字符做百分号编码,因此像 "Ho Chi Minh City" 或 "New York" 这样的多词城市名会生成格式正确的 URL,而不会一到浏览器里就失效。

日期解析外面的两个 try/except 块,专门是为了让格式错误的日期抛出一个清晰、即时的错误,调用方 agent 可以据此反应并请用户更正,而不是悄悄生成一个指向无用之处的链接。

(原文较长,此处译出前 6000 字,完整内容请点「打开原文」。)

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →