fix: coerce nested agent params to prevent spawn_agents validation failures#652
Closed
1337Xcode wants to merge 2 commits into
Closed
fix: coerce nested agent params to prevent spawn_agents validation failures#6521337Xcode wants to merge 2 commits into
1337Xcode wants to merge 2 commits into
Conversation
…ple Agents Routinely Fails CodebuffAI#635
There was a problem hiding this comment.
Pull request overview
This PR fixes validation failures when spawning agents in batches by coercing nested agent.params values that the LLM sometimes emits as a JSON string. It adds a narrow JSON-object coercion step and wires it into the Zod input schemas for both spawn_agents and spawn_agent_inline, with accompanying tests.
Changes:
- Added
coerceToObjectto JSON-parse stringified object inputs (while leaving malformed values to fail validation). - Updated
spawn_agentsandspawn_agent_inlineZod schemas to preprocessparamsviacoerceToObject. - Added/updated tests to cover
coerceToObjectandspawn_agentsstringifiedparamshandling.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/agent-runtime/src/tests/tool-validation-error.test.ts | Adds a regression test for spawn_agents stringified params and refactors message-content extraction logic. |
| common/src/tools/params/utils.ts | Introduces coerceToObject for narrowly parsing stringified JSON objects. |
| common/src/tools/params/tool/spawn-agents.ts | Applies coerceToObject preprocessing to each agent entry’s params schema. |
| common/src/tools/params/tool/spawn-agent-inline.ts | Applies coerceToObject preprocessing to inline spawn params. |
| common/src/tools/params/tests/coerce-to-array.test.ts | Adds unit tests for coerceToObject behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+159
to
+163
| { | ||
| agent_type: 'basher', | ||
| prompt: 'Run tests', | ||
| params: '{"command":"bun test"}', | ||
| }, |
Contributor
|
Thank you! Forking this with some tweaks here: #658 |
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 it fixes:
spawn_agentswas rejecting valid inputs when the LLM emitted nestedagent.paramsas a JSON string during batched spawns.How it works: Adds a
coerceToObjectz.preprocessstep that JSON-parses stringified objects before validation, mirroring the existing array coercion. Wired into the Zod input schemas for bothspawn_agentsand the inline spawn tool.Files changed:
utils.ts,spawn-agents.ts,spawn-agent-inline.ts,coerce-to-array.test.ts,tool-validation-error.test.tsFixes #635