get_memories errors on new memories#1827
Merged
derekmisler merged 1 commit intodocker:mainfrom Feb 23, 2026
Merged
Conversation
When a model calls a tool with no parameters (e.g. get_memories), the streaming API may deliver an empty string for Function.Arguments. NewHandler passed this directly to json.Unmarshal, which fails with "unexpected end of JSON input". This was previously fixed for script_shell tools in docker#585 by guarding with `if Arguments != ""`, but NewHandler (used by memory, think, and any typed handler) was missed. Default empty arguments to "{}" before unmarshaling. Fixes the same root cause as docker#585.
There was a problem hiding this comment.
Review Summary
✅ APPROVED — This PR correctly fixes the panic when NewHandler receives empty string arguments from the streaming API.
The fix follows the established pattern from #585 (script_shell tools) and properly handles the case where tools with no parameters receive empty strings. The test coverage is comprehensive, covering normal arguments, empty arguments, empty object arguments, and invalid JSON.
All potential concerns were verified and dismissed:
- Whitespace handling:
json.Unmarshalcorrectly handles whitespace per JSON RFC standards - Struct validation: Required field validation should happen in tool handlers, not in the generic wrapper
- Protocol masking: The empty string → "{}" conversion is expected behavior for the streaming API, not a bug
Great fix with solid test coverage! 🚀
rumpl
approved these changes
Feb 23, 2026
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.
I noticed this a bunch when testing the PR reviewer locally:

The agent seems to work just fine, but never seems to be able to save memories if the initial get memories fails.
NewHandlerpanic when a model calls a tool with no parameters (e.g.get_memories) and the streaming API delivers an empty string forFunction.Argumentsjson.Unmarshal, matching the existing guard inscript_shelltools (If a shell script tool has no arguments, cagent cannot call it #585)Details
When a model invokes a tool that takes no parameters, the streaming API may deliver an empty string for
Function.Arguments. The genericNewHandler[T]function passed this directly tojson.Unmarshal, which fails with "unexpected end of JSON input".This was previously fixed for script_shell tools in #585 by guarding with
if Arguments != "", butNewHandler(used by memory, think, and any typed handler) was missed.Test plan
TestNewHandler_EmptyArguments— verifies empty string arguments no longer cause an errorTestNewHandler_WithArguments— verifies normal JSON arguments still parse correctlyTestNewHandler_EmptyObjectArguments— verifies "{}" arguments workTestNewHandler_InvalidArguments— verifies malformed JSON still returns an error