fix(ai/gateway): wrap tool inputSchema with ai SDK's jsonSchema() helper#1748
Closed
michaeladair44 wants to merge 1 commit into
Closed
fix(ai/gateway): wrap tool inputSchema with ai SDK's jsonSchema() helper#1748michaeladair44 wants to merge 1 commit into
michaeladair44 wants to merge 1 commit into
Conversation
The bare `{ jsonSchema: t.inputSchema } as any` object was passed
directly to the Vercel AI SDK v6's tool definition. AI SDK v6's
`asSchema()` (provider-utils/dist/index.mjs:2126) routes a `Schema` (with
`[schemaSymbol]` + `validate`), a `ZodSchema`, a `StandardSchema`
(`~standard`), or a `LazySchema` (function). A bare `{ jsonSchema }`
object matches none of these, so the SDK falls through to invoking the
input as a function, throwing:
schema is not a function. (In 'schema()', 'schema' is an instance of Object)
Use the SDK's own `jsonSchema(...)` helper, which produces a proper
`Schema<T>` and is the documented public API for this case.
Surfaced when a gbrain agent fan-out (38 children) all died on the same
runtime error before any LLM call could fire. Refs ADA-495.
Owner
|
Landed in #1809 (v0.42.19.0). Your |
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.
Symptom
A subagent fan-out we run on top of
gbrain(one parent → 38 children, each callingchat()with tools defined) died — all 38 children — with the same runtime error before a single LLM call could fire:Root cause
src/core/ai/gateway.tsbuilds thetoolsmap for the Vercel AI SDK like this:The bare
{ jsonSchema: t.inputSchema } as anyis then handed to AI SDK v6'sasSchema()in@ai-sdk/provider-utils/dist/index.mjs(~line 2126).asSchema()branches on what kind of input it received:Schema(has[schemaSymbol]+validate)ZodSchemaStandardSchema(~standard)LazySchema(function)A plain
{ jsonSchema: ... }object matches none of these branches, so the SDK falls through to invoking the input as a function:schema()→schema is not a functionbecauseschemais anObjectliteral.Fix
aialready exports thejsonSchema()helper (re-exported from@ai-sdk/provider-utils) precisely for this case — it wraps a JSON Schema 7 object in a properSchema<T>with[schemaSymbol]and a no-opvalidate. Two-line change:Verification
bun build --compile --outfile bin/gbrain src/cli.ts— clean.gbrain autopilotagainst the patched source.13028, modelanthropic:claude-haiku-4-5-20251001, tools enabled) — the SDK now accepts the tool schema and the LLM call fires.Impact
Any caller of
chat()that passesopts.toolswill hit this. Hot path for tool-using minions / subagent fan-outs.Scope
One file, two lines. No new dependencies —
jsonSchemais already exported from theaipackage this repo pins (^6.0.168).