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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user