Repository navigation
Conversation
…thing A tool whose execute returns undefined (a side-effect tool such as "log" or "notify") produced function_call_output with output: undefined, because JSON.stringify(undefined) is undefined, not a string. The SDK's request schema requires a string or content array, so the follow-up request failed with SDKValidationError after the tool had already run and callModel never got its next turn. Serialize tool results through one stringifyToolOutput helper that falls back to "null", and use it at the four JSON.stringify(result) sites.
toFunctionCallOutputValue used JSON.stringify directly, so a HITL tool whose onResponseReceived hook returns undefined (valid with outputSchema z.void()) still sent output: undefined and the next request failed SDK validation. Use the same stringifyToolOutput helper as the other function_call_output sites.
This branch has not been deployed
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.
What
Adds
stringifyToolOutput(value)(JSON.stringify(value) ?? 'null') inconversation-state.tsand uses it where a tool result becomes afunction_call_output:computeToolOutputForModel(both paths) inmodel-result.ts,unsentResultsToAPIFormat,formatToolResultForModel, andtoFunctionCallOutputValue(the HITLonResponseReceivedpath, where a hook returningundefinedfor az.void()output schema hit the same error). Adds unit tests and a patch changeset for@openrouter/agent.Why
A tool whose
executereturns nothing gaveJSON.stringify(undefined), which isundefined, so thefunction_call_outputitem hadoutput: undefined. The SDK's request schema requires a string or content array, so the follow-up request failed withSDKValidationErrorafter the tool had already run, andcallModelnever got its next turn. The TypeScript types accept a voidexecute. Fixes #167.How tested
cd packages/agent && npx vitest run tests/unit/void-tool-output.test.ts --coverage.enabled=false: fails on main (3/3), passes with this change.cd packages/agent && npx vitest run tests/unit/hitl-void-output.test.ts --coverage.enabled=false: fails on main (3/3), passes with this change. The test uses the real SDK request path (OpenRouterCorewith a mockedHTTPClient), so it exercises the schema that rejects the request; mockingbetaResponsesSendinstead would not catch this.pnpm run lint,pnpm run typecheck: clean.pnpm run test:@openrouter/agent1295/1295 (114 files),@openrouter/mcp12/12, coverage thresholds pass.Risks
"null"(same asJSON.stringify(null)). Maintainers may prefer""or a short message; it's one line in the helper.JSON.stringifymaps toundefined(a function, a symbol) also become"null"instead of failing validation.