Skip to content

feat(deepagent): integrate You.com Search API as a DeepAgent tool - #224

Open
tra371 wants to merge 1 commit into
apconw:masterfrom
Cooperation-org:feature/youchannels-search
Open

feat(deepagent): integrate You.com Search API as a DeepAgent tool#224
tra371 wants to merge 1 commit into
apconw:masterfrom
Cooperation-org:feature/youchannels-search

Conversation

@tra371

@tra371 tra371 commented Jul 9, 2026

Copy link
Copy Markdown

PR描述(中文):

摘要

  • 集成 You.com Search API 作为 DeepAgent 的可调用工具 (youcom_search),在 REPORT_QA 流水线中启用实时网络搜索
  • 工具同时注册到 SQLAlchemy 和原生驱动工具列表中,无论查询走哪条后端路径都可以使用
  • 返回格式化的搜索结果,包含标题、链接、摘要和页面时间

改动

  • agent/deepagent/tools/youcom_search_tool.py — 新工具实现
  • agent/deepagent/deep_data_agent.py — 在 SQLAlchemy 和原生驱动工具列表中注册工具
  • .env.dev — 添加 YOU_SEARCH_API_KEY= 占位符

测试计划

  • 全部13个单元测试通过(独立运行,无外部依赖):python tests/test_youcom_search_tool.py
  • 使用有效 API key 验证 DeepAgent REPORT_QA 网络搜索端到端可用
  • 确认搜索结果在 SSE 流式响应中正确渲染

备注

  • 使用 X-API-Key 请求头(非 Authorization: Bearer)
  • 端点:https://ydc-index.io/v1/search
  • 需要在 .env.dev 中设置 YOU_SEARCH_API_KEY
  • 本地测试文件因 .gitignore: tests/* 规则未提交

Summary

  • Integrates You.com Search API into the DeepAgent system as a callable tool (youcom_search), enabling real-time web search within the REPORT_QA pipeline
  • Tool is registered in both SQLAlchemy and native driver tool lists, so it's available regardless of which backend path handles the query
  • Returns formatted results with title, link, snippet, and page age for each web result

Changes

  • agent/deepagent/tools/youcom_search_tool.py — new tool implementation
  • agent/deepagent/deep_data_agent.py — registered tool in SQLAlchemy and native driver tool lists
  • .env.dev — added YOU_SEARCH_API_KEY= placeholder

Test plan

  • All 13 unit tests pass (standalone, no external deps): python tests/test_youcom_search_tool.py
  • Verify DeepAgent REPORT_QA query with web search works end-to-end with a valid API key
  • Confirm search results render correctly in the SSE streaming response

Notes

  • Uses X-API-Key header (not Authorization: Bearer)
  • Endpoint: https://ydc-index.io/v1/search
  • Requires YOU_SEARCH_API_KEY to be set in .env.dev
  • Local tests are gitignored (tests/test_youcom_search_tool.py) — not committed due to .gitignore: tests/* rule in this repo

Adds `youcom_search` tool that calls `POST https://ydc-index.io/v1/search`
with `X-API-Key` header to enable real-time web search within the DeepAgent
REPORT_QA pipeline. The tool is registered in both the SQLAlchemy and
native driver tool lists.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tra371

tra371 commented Jul 9, 2026

Copy link
Copy Markdown
Author

@apconw 您好!由于时间关系这次没有提前创建 issue,直接提交了 PR,还请见谅。
这个 PR 为 DeepAgent 集成了 You.com Search API,填补了 DeepAgent 流水线中实时网络搜索的能力空白。目前 REPORT_QA 查询无法获取实时网络信息,集成后可以直接在深度问答场景中搜索最新资料,对需要引用外部信息的用户会很有帮助。
API 为免费层每天100次请求,使用 X-API-Key 认证,代码改动也很小(一个工具文件 + 两行注册),不会影响现有功能。麻烦帮忙 review 一下,有任何问题随时沟通 🙏

@apconw

apconw commented Aug 30, 2026

Copy link
Copy Markdown
Owner

感谢贡献。我核对了当前 You.com Search OpenAPI v1.1.0:POST /v1/search、X-API-Key、请求体以及 results.web 的解析方式都是正确的。不过目前还有几个需要先处理的阻断项:

  1. 搜索工具被无条件注册到数据库 Agent,模型可以把内部表结构、查询结果或用户敏感信息作为 query 发送给第三方。目前缺少功能开关、用户/租户授权以及必要的脱敏或查询边界。建议默认关闭,只在明确启用联网搜索且已配置密钥时注册,并禁止将数据库内容直接作为搜索词外发。

  2. youcom_search_tool._get_session_id() 复用了 native_sql_tools 的模块级全局 _current_datasource。并发创建多个 Agent 时,后一个会覆盖前一个的 session_id,造成调用统计串到其他会话,甚至误触发另一个会话的调用限制。建议使用真正的 ContextVar 会话上下文,并在 Agent 执行上下文中设置/恢复。

  3. 搜索结果是外部不可信内容,目前标题和摘要直接作为工具结果交给 Agent,缺少明确的不可信内容边界和防提示词注入规则。建议对结果加结构化边界,并在 Agent 指令中明确不得执行网页内容中的指令。

  4. 默认没有 YOU_SEARCH_API_KEY 时仍会把工具暴露给模型;调用失败还会计入连续失败次数。建议仅在 feature flag 开启且 key 存在时加入 tools。

  5. PR 描述提到本地有 13 个测试,但没有提交。即使 tests/* 被忽略,也可以使用 git add -f 提交。请至少覆盖:空 key、200/401/403/422、超时、畸形 JSON、空结果以及会话隔离。

工具文件的语法检查已通过。处理完以上配置边界、并发隔离和测试后可以再 review。

@tra371

tra371 commented Aug 30, 2026

Copy link
Copy Markdown
Author

@apconw 感谢您花时间查看代码并给出了详尽的评审意见。我会争取在本周内解决这些问题。🙏

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.

2 participants