Conversation
ImageInputCompatibilityMiddleware 通过类属性 tools 硬编码注入 ocr_parse_file,LangChain create_agent 无条件将其合并进模型默认工具集,导致智能体配置中关闭 OCR 工具后模型仍可调用。修复:删除中间件 tools 类属性,OCR fallback 改为仅在当前请求工具集已启用 ocr_parse_file 时触发,否则返回禁用提示。验证:11 个单元测试通过,133 个 agents 回归通过,负向测试自证有效。
This branch has not been deployed
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.
变更说明
智能体配置中禁用 OCR 工具后,模型仍可调用
ocr_parse_file。根因:ImageInputCompatibilityMiddleware通过类属性tools = [ocr_parse_file]硬编码注入,LangChaincreate_agent会无条件将其合并进模型默认工具集,与配置中的工具开关无关。修复:删除该中间件的
tools类属性;OCR fallback 仅在当前请求工具集已启用ocr_parse_file时触发,否则返回禁用提示。bug-fixocr_parse_file;非目标:不改变 OCR 启用时的 fallback 行为与其他工具装配路径工程主张与 Owner
ocr_parse_file,OCR fallback 不触发并返回禁用提示;(2) 配置启用 OCR 时,非 vision 模型的 OCR fallback 行为不变。backend/package/yuxi/agents/middlewares/model_input.py拥有该行为;中间件位于组合最内层,其看到的request.tools即最终绑定给模型的工具列表,fallback 判定与模型可见性一致;可在模型请求 tools 与中间件返回内容处观察。验证情况
禁用 OCR 配置后模型无法再调用 ocr_parse_file,且启用时行为不变
model_input.py的ImageInputCompatibilityMiddlewareiva_yuxi-api:0.7.3镜像内运行python -m pytest test/unit/middlewares/test_model_input_middleware.py test/unit/agents:209 passed;python3 scripts/verify_engineering_contracts.py通过,python -m unittest scripts.test_verify_engineering_contracts63 passedmodel_input.py到修复前实现、保留新测试,运行两个禁用用例test_no_ocr_fallback_when_tool_disabled[_sync]:2 failed,能捕获原缺陷真实 HTTP integration / worker / 浏览器链路:
Not run(见未验证范围)。简化 / 删除验收
不涉及(
tools类属性的删除是本 bug-fix 的根因修复,非独立简化;无其他 consumer 依赖该注入路径)。独立语义 Review
由不继承开发上下文的独立 Reviewer 覆盖:完整 diff、
model_input.py全文、langchaincreate_agent源码确认根因、chatbot/subagent graph 与resolve_configured_runtime_tools的中间件组合顺序、Skill 依赖门控交互、新测试正反跑。结论:可提交。低严重度备注:_ocr_tool_enabled对 dict 形态工具判定为禁用(fail-closed 方向,本仓库工具均为 BaseTool 实例,无实际影响)。未验证范围与风险
iva_yuxi-api:0.7.3镜像依赖环境执行,非上游 CI 环境;事故反馈
未达到高影响逃逸缺陷门槛,无 postmortem。
界面变更
不涉及。
关联事项
无。
补充说明
无。