新增 search_web 工具:接入 You.com 联网检索作为带引用的补充来源 - #3
Open
Emos21 wants to merge 1 commit into
Open
Conversation
配置 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 与联网检索说明。
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要 / Summary
新增
search_webAgent 工具,接入 You.com 联网检索作为本地知识库之外的带引用补充来源。配置YDC_API_KEY后工具才挂载(未配置则不挂载、系统提示不变,零回归)。遵循 AGENTS.md 分层(外部 I/O 在infra,编排在usecases),结果复用现有引用管线,不改 Citation schema。Adds a
search_webagent tool that uses You.com Search as a grounded, cited source beyond the local KB. Only mounted whenYDC_API_KEYis 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):
带 Key / With a real key:
启动后,在对话中提一个需要最新信息的问题,Agent 会调用
search_web,回答带来源 URL 引用。不设 Key 时该工具不挂载,行为不变。说明 / Notes
chunk_id(web:{i})经现有引用管线持久化,URL 随snippet保留;后续可考虑给Citation增加独立url字段(本 PR 刻意不改 schema)。X-API-Key请求头;现网验证 / Live-verified:GET https://ydc-index.io/v1/search真实返回结果。