Skip to content

新增 search_web 工具:接入 You.com 联网检索作为带引用的补充来源 - #3

Open
Emos21 wants to merge 1 commit into
biao994:mainfrom
Cooperation-org:feature/youcom-search
Open

新增 search_web 工具:接入 You.com 联网检索作为带引用的补充来源#3
Emos21 wants to merge 1 commit into
biao994:mainfrom
Cooperation-org:feature/youcom-search

Conversation

@Emos21

@Emos21 Emos21 commented Jul 30, 2026

Copy link
Copy Markdown

概要 / Summary

新增 search_web Agent 工具,接入 You.com 联网检索作为本地知识库之外的带引用补充来源。配置 YDC_API_KEY 后工具才挂载(未配置则不挂载、系统提示不变,零回归)。遵循 AGENTS.md 分层(外部 I/O 在 infra,编排在 usecases),结果复用现有引用管线,不改 Citation schema。

Adds a search_web agent tool that uses You.com Search as a grounded, cited source beyond the local KB. Only mounted when YDC_API_KEY is set (no key -> not mounted, prompt unchanged, zero regression). Follows AGENTS.md layering (I/O in infra, orchestration in usecases); reuses the existing citation pipeline with no schema change.

关联 / Closes #2

改动 / Changes

  • backend/docpaws/infra/websearch/youcom_client.py: 外部 I/O 层(httpx),归一化 web/news,异常统一返回 []
  • backend/docpaws/usecases/chat_agent_tools.py: search_web 工具与系统提示按 Key 可用性挂载,写入 ctx.last_citations(source=标题,URL 随 snippet 持久化)。
  • backend/docpaws/settings.py: YDC_API_KEY + YDC_WEB_SEARCH_COUNT
  • backend/requirements.txt: 声明 httpx(此前仅为传递依赖)。
  • backend/tests/: infra 客户端 9 例 + Agent 工具 3 例。
  • .env.example / backend/README.md: 配置与说明。

测试 / How to test

不需要 Key(infra 单测走 mock,不联网 / No key needed, mocked):

cd backend && python tests/test_youcom_websearch.py
# 或全量 / or full: python -m pytest tests/test_youcom_websearch.py tests/test_chat_agent_search_web.py -q

带 Key / With a real key:

export YDC_API_KEY=<your key>   # 或写入 backend/.env

启动后,在对话中提一个需要最新信息的问题,Agent 会调用 search_web,回答带来源 URL 引用。不设 Key 时该工具不挂载,行为不变。

说明 / Notes

  • Web 引用用合成 chunk_idweb:{i})经现有引用管线持久化,URL 随 snippet 保留;后续可考虑给 Citation 增加独立 url 字段(本 PR 刻意不改 schema)。
  • Key 仅出现在 X-API-Key 请求头;现网验证 / Live-verified: GET https://ydc-index.io/v1/search 真实返回结果。

配置 YDC_API_KEY 后,对话 Agent 多出 search_web 工具,把公开网页作为本地
知识库之外的补充来源;结果复用现有引用管线(source=标题,snippet 含来源 URL),
回答须标注 URL。未配置 Key 时不挂载该工具,行为完全不变。

- infra/websearch/youcom_client.py:外部 I/O 层(AGENTS 规则 9),httpx 调用
  You.com Search API(X-API-Key + 团队约定 User-Agent),归一化 web/news、
  count 夹取与总数截断;网络/状态码/解析异常统一返回空结果,绝不抛出。
- usecases/chat_agent_tools.py:search_web 工具与系统提示按 Key 可用性挂载,
  写入 ctx.last_citations(合成 web:{i} chunk_id,URL 随 snippet 持久化)。
- settings.py:新增 YDC_API_KEY 与 YDC_WEB_SEARCH_COUNT。
- tests:infra 客户端 8 例(映射/鉴权头/夹取截断/各类降级/Key 不泄露)+
  Agent 工具 3 例(无 Key 不挂载、写入 Web 引用、空查询)。
- .env.example / backend/README:同步 YDC_API_KEY 与联网检索说明。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

新增 search_web 工具:接入 You.com 联网检索作为带引用的补充来源

1 participant