fix: use jsonSchema() wrapper and 'parameters' key for AI SDK tool definitions#1488
fix: use jsonSchema() wrapper and 'parameters' key for AI SDK tool definitions#1488justemu wants to merge 1 commit into
Conversation
…finitions
The gateway.chat() function passed raw JSON Schema objects under the
'inputSchema' key to generateText(). The Vercel AI SDK expects tools to
use the 'parameters' key with jsonSchema()-wrapped values. The
'inputSchema' key is silently ignored for openai-compatible providers.
This causes non-Anthropic subagent tool loops (agent.use_gateway_loop=true)
to fail with:
[chat(deepseek:...)] schema is not a function
because the SDK tries to call .schema() on whatever lands under
'parameters', which is undefined, falling through to a plain Object.
Fix:
- Import jsonSchema from 'ai'
- Replace inputSchema: { jsonSchema: ... } with parameters: jsonSchema(...)
Affected: all releases with agent.use_gateway_loop support (v0.38+).
|
Friendly nudge 🙏 — been running this as a local patch on v0.42.26.0 for ~2 weeks, works cleanly. Any chance it could get a review/merge? Thanks for the fix! |
|
Thanks for this contribution — and apologies for the slow triage. We did a full pass over the entire PR backlog. gbrain has moved fast, and the maintainer's larger "cathedral" rewrites have superseded a big share of community PRs: the AI gateway + recipes + user_provided_models system replaced almost all individual provider PRs; #1805 fixed the whole Postgres module-singleton class; #1542 unified the type taxonomy; #1657 the retrieval path; #1802 the doctor; and so on. We're closing this one in that cleanup — either the fix already landed on master, it duplicates another PR or merged change, or it's outside the current merge bar. Where a closed PR carried a genuinely valuable idea, we've recorded it in docs/designs/COMMUNITY_IDEAS.md so nothing good is lost (a few may graduate into TODOs). Please don't read the close as a judgment of the work — thank you for contributing. If you believe the underlying issue is still live on the latest master, reopen with a quick note and we'll take another look. 🙏 |
Summary
Fixes #1487 - the gateway chat() function passes tool schemas in a format incompatible with the Vercel AI SDK for non-Anthropic providers.
Problem
When agent.use_gateway_loop=true, the subagent handler routes through gateway.toolLoop(), which calls gateway.chat(). The chat() function passes tool schemas as { inputSchema: { jsonSchema: rawObject } } to generateText(). The AI SDK expects { parameters: jsonSchema(rawObject) } where jsonSchema is imported from the ai package.
This causes all non-Anthropic subagent tool loops to fail with: [chat(deepseek:...)] schema is not a function
Changes
2 lines changed in src/core/ai/gateway.ts. Import jsonSchema from ai, and use parameters: jsonSchema(t.inputSchema) instead of inputSchema: { jsonSchema: t.inputSchema }.
Testing
Tested with DeepSeek v4 Flash as the subagent model. The Anthropic-direct path is unaffected.
Affected versions
All releases with agent.use_gateway_loop support (v0.38+ through current HEAD).