Repository navigation
fix: 修复 Playground-only Agent 工具 Schema 与联合类型兼容 - #47
Merged
Merged
Conversation
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.
问题:一个辅助工具的 Schema 阻断整个 Agent 任务
v0.2.4为保留开放 Schema 的语义,遇到 TYPE_UNSPECIFIED 节点时选择 Build。这对仅启用 Playground 的已有部署形成兼容变化。此 PR 最初加入显式开启的旧版缺省类型回退,但仍拒绝混合anyOf;实际文件/代码任务因此继续在生成前失败。本次基于真实失败请求的脱敏结构定位:工具列表中的
asktool参数路径为:选项同时支持字符串与
{label, description}对象:{ "anyOf": [ {"type": "string"}, { "type": "object", "properties": { "label": {"type": "string"}, "description": {"type": "string"} }, "required": ["label"] } ] }生成请求会携带整套工具,而不是只携带即将执行的 Read/Write。因此,即使任务只是操作文件、不准备提问,也会在本地收到:
此时尚未发起上游生成,模型没有机会选择文件工具。
修复内容与边界
保留
PLAYGROUND_SCHEMA_FALLBACK=false默认关闭,不更改官方严格模式。显式开启且 Build 未启用时:anyOf/oneOf,首个分支可推导出具体类型时,补充该根类型。不删除任意分支,也不删除分支上的 required、enum、数值限制或 oneOf 排他条件。 首分支为 array 时还需明确、可编码的 items,并保留它的类型。tool_choice:none忽略的工具不触发兼容处理。这是有损的旧版兼容模式,不是任意 JSON Schema 的无损转换。 上例会在保留原 anyOf 的同时增加
type:string,从而使用客户端本就接受的纯文本选项;对象选项不再由这条兼容请求生成。优先建议明确工具实际类型,或使用可完整表达原 Schema 的通道。关闭开关并重启生成服务即可恢复严格模式,无需账号/聊天数据迁移。
验证结果
修复前后同形对照
asktool.questions[].options[]的混合 Schema 上失败。Read(input.json) → Write(result.json) → 最终回复成功,结果文件解析为{"sum":10,"count":3}。用于确认该字段确是阻断点,不作为新程序验收替代。自动回归与构建
go test -count=1 ./...go vet ./...CGO_ENABLED=1 go test -race ./internal/aistudio ./internal/config ./internal/appnpm run lint、npm run build(含 vue-tsc)git diff --check回归覆盖原错误结构、string/object 分支顺序、oneOf 重叠条件保留、数组首分支元素类型、nullable 联合、未知/布尔/冲突组合拒绝、原请求不变、非相关文件工具不变、严格模式与 Build 路由、response schema 保留,以及原有配置往返/并发隔离测试。
已有缺省 items 工具调用、第二轮工具结果、流式输出、显式 false 仍拒绝、管理登录/退出与权限保护均实测通过。
PR 范围整理