feat(agent): allow manual tools to supply a wire input schema - #118
feat(agent): allow manual tools to supply a wire input schema#118sambarnes wants to merge 1 commit into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Original prompt from sam
|
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Summary
Manual tools (
execute: false) may now carry a caller-owned JSON Schema inwireInputSchema, whichconvertToolsToAPIFormatserializes instead of regenerating one frominputSchema.The SDK never executes or input-validates a manual tool, so the Zod schema on such a tool exists only to be converted back to JSON Schema at serialization time. A caller that already holds the JSON Schema therefore pays a full round trip for nothing:
That round trip is not free and not lossless. It allocates a Zod object graph per tool per request, and constructs Zod cannot represent (
anyOf,oneOf) degrade on the way through.wireInputSchemashort-circuits it:sanitizeJsonSchemastill runs, so~-prefixed Standard Schema metadata never reaches a provider, and because it deep-copies, the caller's schema object is not mutated.The knob is gated to manual tools on both sides. At runtime
isManualToolexcludes HITL (onToolCalled), unified (run), generator, regular and server tools, so every other path keeps its exact current behavior. At the type levelToolConfigWithSharedContextbecomes an intersection with a two-branch union, so the field is available withexecute: falseandneverwith anexecutefunction:Motivation is a hot path in
openrouter-web: the server-tools plugin rebuilt a Zod schema from each caller-supplied function tool on every request purely so the SDK could serialize it back, and it currently carries this behavior as a local patch against@openrouter/agent@0.10.0(openrouter-web#36877, openrouter-web#36878). Upstreaming it lets that patch hunk be deleted at the next version bump. The win generalizes to any caller whose tool schemas originate as JSON Schema (proxies, MCP bridges, anything forwarding a downstream client'stoolsarray).API example
Additive and optional: a manual tool without
wireInputSchemaserializes exactly as before.Tests
packages/agent/tests/unit/manual-tool-wire-schema.test.tsasserts againstconvertToolsToAPIFormatoutput —anyOf/oneOfsurvive,~keys are stripped at the root and nested underproperties, the caller's object is neither mutated nor emitted by reference, a manual tool without the field still gets the Zod-derived schema, and an executable shared-context tool is unaffected.manual-tool-wire-schema.test-d.tspins the type-level gate (accepted withexecute: false,@ts-expect-erroralongside anexecutefunction).pnpm run lint,pnpm run typecheck, andpnpm --filter @openrouter/agent test(104 files, 1221 tests, no type errors) pass locally.Link to Devin session: https://openrouter.devinenterprise.com/sessions/acb44a847f1c4670b21a50fdfae26ef0
Requested by: @sambarnes