fix(memory): flatten multimodal content before provider sync

Multimodal turns carry message content as a list of typed parts
({type: "text"|"image_url", ...}). _sync_external_memory_for_turn
passed that list straight into MemoryManager.sync_all, and providers
feed it to regexes — Honcho's sync_turn calls sanitize_context, where
re.sub raised 'expected string or bytes-like object, got list'. Every
turn with an attached image silently never synced.

Flatten to plain text at the boundary: text parts joined, images noted
as an [N image(s)] marker so the attachment isn't erased from recall.
Fixing here covers all providers instead of patching each plugin.
This commit is contained in:
Erosika
2026-06-11 18:53:26 -04:00
parent 2ee69d0579
commit 705bdb6ffe
4 changed files with 161 additions and 4 deletions
+10 -4
View File
@@ -132,7 +132,7 @@ from tools.browser_tool import cleanup_browser
# Agent internals extracted to agent/ package for modularity
from agent.memory_manager import sanitize_context
from agent.memory_manager import flatten_message_content, sanitize_context
from agent.error_classifier import FailoverReason
from agent.redact import redact_sensitive_text
from agent.model_metadata import (
@@ -2990,17 +2990,23 @@ class AIAgent:
return
if not (self._memory_manager and final_response and original_user_message):
return
# Multimodal turns carry content as a list of typed parts; providers
# expect plain strings (see flatten_message_content).
user_text = flatten_message_content(original_user_message)
response_text = flatten_message_content(final_response)
if not (user_text and response_text):
return
try:
sync_kwargs = {"session_id": self.session_id or ""}
if messages is not None:
sync_kwargs["messages"] = messages
self._memory_manager.sync_all(
original_user_message,
final_response,
user_text,
response_text,
**sync_kwargs,
)
self._memory_manager.queue_prefetch_all(
original_user_message,
user_text,
session_id=self.session_id or "",
)
except Exception: