Fix: handle non-string tool call arguments in memory consolidation

Fixes #1042. When the LLM returns tool call arguments as a dict or
JSON string instead of parsed values, memory consolidation would fail
with "TypeError: data must be str, not dict".

Changes:
- Add type guard in MemoryStore.consolidate() to parse string arguments
  and reject unexpected types gracefully
- Add regression tests covering dict args, string args, and edge cases
This commit is contained in:
alairjt
2026-02-23 13:59:49 -03:00
parent 25f0a236fd
commit 3eeac4e8f8
2 changed files with 154 additions and 0 deletions

View File

@@ -125,6 +125,13 @@ class MemoryStore:
return False
args = response.tool_calls[0].arguments
# Some providers return arguments as a JSON string instead of dict
if isinstance(args, str):
args = json.loads(args)
if not isinstance(args, dict):
logger.warning("Memory consolidation: unexpected arguments type %s", type(args).__name__)
return False
if entry := args.get("history_entry"):
if not isinstance(entry, str):
entry = json.dumps(entry, ensure_ascii=False)