Skip to content

Conversation

@memoryforget
Copy link
Contributor

问题描述

OperatorQA 工作流中,OperatorRAGService 是在工厂函数 create_operator_qa_graph 中初始化的。由于初始化时没有传入 API Key(且环境变量可能未设置),导致 rag_service 实例中的 API Key 为空。
虽然用户在前端/Request 中传入了 API Key 并存储在 state 中,但由于闭包作用域隔离,rag_service 无法感知到 state 中的 Key。
这导致在执行 search_operators 工具时,底层调用 Embedding 模型失败,报错如下:

ERROR | dataflow_agent.agentroles.data_agents.operator_qa_agent | RAG 检索失败: 必须提供 OpenAI API-Key,可通过参数或环境变量 DF_API_KEY

解决方案

在 wf_operator_qa.py 的 operator_qa_node 节点执行逻辑中添加了状态同步逻辑:
从当前的 state.request.api_key 获取 API Key。
检查 rag_service 是否缺少 Key 或 Key 不一致。
如果需要,将 state 中的 Key 注入到 rag_service 中,并重置其内部的 _searcher 以便使用新 Key 重新懒加载。

验证结果

修复前: 调用工具失败,日志报错 RAG 检索失败,LLM 无法获取相关算子。
image
image

修复后: 日志显示 RAG 检索成功,并正确返回算子列表:
image

Runtowheres pushed a commit to Runtowheres/DataFlow-Agent that referenced this pull request Jan 19, 2026
@haolpku haolpku merged commit 66fcec1 into OpenDCAI:main Jan 20, 2026
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