Skip to content

subagent: schema is not a function — AI SDK v6 tool schema incompatibility #1782

@GangdanLee

Description

@GangdanLee

Description

Subagent jobs (agent run) fail with schema is not a function across all providers (DeepSeek, OpenAI/Qwen, Anthropic). All other gbrain features (search, sync, extract, dream cycle) work correctly.

Error

[chat(deepseek:deepseek-chat)] schema is not a function. (In 'schema()', 'schema' is an instance of Object)

Same error regardless of provider:

  • anthropic:claude-sonnet-4-6 → same
  • openai:qwen3.7-max → same

Environment

Component Version
gbrain 0.42.8.0 (commit 0bfe0d0c)
ai (AI SDK) 6.0.174
@ai-sdk/openai 3.0.58
@ai-sdk/openai-compatible 2.0.45
@ai-sdk/anthropic 3.0.74
zod 3.25.76 (also tested 4.3.6)
bun 1.3.14
Engine PostgreSQL (not PGLite)

Root Cause Analysis

The error occurs in the gatewayToolLoopgenerateText call path. In src/core/ai/gateway.ts line 2531, tool schemas are constructed as:

inputSchema: { jsonSchema: t.inputSchema } as any

The AI SDK v6 internally calls .schema() on a tool schema object during processing, but the object lacks this method as a callable function. This happens regardless of:

  • zod version (tested v3.25.76 with package.json overrides and v4.3.6)
  • provider (tested DeepSeek via @ai-sdk/openai-compatible, Qwen via @ai-sdk/openai, Anthropic via @ai-sdk/anthropic)
  • run mode (tested both bun build --compile binary and bun run source)
  • agent.use_gateway_loop setting (tested both true and false)

The issue appears to be an API mismatch between gbrain's tool schema construction ({ jsonSchema: ... }) and how AI SDK v6.0.174 processes tool schemas internally.

Steps to Reproduce

# On a fresh gbrain v0.42.8.0 install with PostgreSQL engine:
gbrain config set models.tier.subagent deepseek:deepseek-chat
gbrain jobs work --queue default &  # start worker
gbrain jobs submit subagent --params '{"prompt":"reply with exactly: working"}'
sleep 15
gbrain jobs get <id>  # shows DEAD with schema error

What Was Tried (all failed)

  1. Upgraded from v0.42.1.0 to v0.42.8.0
  2. Clean rm -rf node_modules && bun install
  3. Pinned zod to v3.25.76 via package.json overrides
  4. Tested compiled binary (bun build --compile)
  5. Tested source mode (bun run src/cli.ts)
  6. Tested all three provider types
  7. Toggled agent.use_gateway_loop
  8. Fresh rebuild after each change

Impact

All subagent/agent-run functionality is completely non-functional. Other gbrain features (search, sync, extract, dream cycle, skillopt) operate normally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions