You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tool result serialization: handle_tool_call should return JSON string, not dict #254
The agentmemory plugin's handle_tool_call returns raw Python dicts instead of JSON strings. When Hermes is configured with an Anthropic-protocol backend, these dicts get stored as-is in the tool result message content field within the session history. On the next LLM request, the Anthropic API's message validation rejects them:
Failed to deserialize the JSON body into the target type:
messages[N]: content should be a string or a list at line 1 column XXXXX
Once triggered, every subsequent request in that session fails until the session JSON is manually cleaned.
To Reproduce
Connect Hermes Agent to agentmemory via the plugin
Use an Anthropic-protocol LLM provider (provider: anthropic, proxies included)
Call memory_recall / memory_save / memory_search during a conversation
The tool result is stored as a raw dict in session messages
Continue the conversation → 400 bombs
Expected behavior
handle_tool_call should return a JSON string, matching the behavior of native MCP tool handlers. The tool result's content field must be a valid string type.
Root cause
All 4 return statements in plugins/agentmemory/__init__.py → handle_tool_call are raw dicts:
The following method signatures in the same file are incompatible with the Hermes MemoryProvider base class (missing session_id parameter), causing TypeError in gateway multi-session contexts:
Verified the root cause matches your analysis exactly:
All four return paths in handle_tool_call return raw Python dicts.
Hermes' tool-result handling stores the return value as the message content field verbatim — when the LLM provider is Anthropic-protocol (or any Anthropic-compatible proxy), the API enforces content is str | list, so a dict 400s on the next request.
This is invisible on OpenAI-protocol backends because they coerce more loosely, which is why this only surfaces under your specific stack. Good repro — that's the kind of bug that hides for a while.
The fix wraps every return in json.dumps(...) and tightens the return-type annotation Any → str on both the abstract base and the concrete class so mypy / type checkers will catch a future regression.
Cross-checked against agentmemory's own MCP server contract in src/mcp/standalone.ts:
The Hermes plugin was the outlier — every other agentmemory tool surface (REST, MCP, OpenClaw plugin) already returns JSON strings. After #255 the Hermes plugin matches.
Re: your secondary note about session_id in hook signatures
prefetch / queue_prefetch / sync_turn missing the kwarg parameter is already fixed by #252 (merged earlier today). That one went broader — added **kwargs: Any to all seven hooks (prefetch, queue_prefetch, sync_turn, on_session_end, on_pre_compress, on_memory_write, shutdown). **kwargs is a strict superset of *, session_id: str = "" — accepts that exact key plus any future Hermes-passed context kwargs without further patches. Where Hermes passes session_id, the patch also prefers it over the cached self._session_id so multi-session gateway contexts route to the right session.
Activity
rohitg00 commentedon May 9, 2026
Confirmed and fixed — PR #255.
Verified the root cause matches your analysis exactly:
handle_tool_callreturn raw Python dicts.contentfield verbatim — when the LLM provider is Anthropic-protocol (or any Anthropic-compatible proxy), the API enforcescontentisstr | list, so adict400s on the next request.The fix wraps every return in
json.dumps(...)and tightens the return-type annotationAny → stron both the abstract base and the concrete class so mypy / type checkers will catch a future regression.Cross-checked against agentmemory's own MCP server contract in
src/mcp/standalone.ts:The Hermes plugin was the outlier — every other agentmemory tool surface (REST, MCP, OpenClaw plugin) already returns JSON strings. After #255 the Hermes plugin matches.
Re: your secondary note about
session_idin hook signaturesprefetch/queue_prefetch/sync_turnmissing the kwarg parameter is already fixed by #252 (merged earlier today). That one went broader — added**kwargs: Anyto all seven hooks (prefetch,queue_prefetch,sync_turn,on_session_end,on_pre_compress,on_memory_write,shutdown).**kwargsis a strict superset of*, session_id: str = ""— accepts that exact key plus any future Hermes-passed context kwargs without further patches. Where Hermes passessession_id, the patch also prefers it over the cachedself._session_idso multi-session gateway contexts route to the right session.Closing this on #255 merge.
fix(hermes): serialize handle_tool_call returns to JSON string (closes …
chore(release): v0.9.5 — search recall + plugin compatibility
chore(release): v0.9.5 — search recall + plugin compatibility
chore(release): v0.9.5 — search recall + plugin compatibility (#261)
fix(hermes): serialize handle_tool_call returns to JSON string (closes …
fix(hermes): serialize handle_tool_call returns to JSON string (closes …