File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121from typing import Any
2222
2323from . import config
24- from .models import Message
24+ from .models import ImagePart , Message
2525
2626PROMPTS_DIR = Path (__file__ ).parent / "prompts"
2727AGENTS_DIR = PROMPTS_DIR / "agents"
@@ -529,10 +529,35 @@ def user_prompt_texts(messages: list) -> list[str]:
529529 continue
530530 if is_reminder [i ] and not (batch_start <= i <= last_reminder ):
531531 continue
532+ image_note = _image_placeholder_text (msg )
533+ if image_note :
534+ text = f"{ text } \n { image_note } " if text else image_note
532535 prompts .append (text )
533536 return prompts
534537
535538
539+ def _image_placeholder_text (msg : object ) -> str :
540+ """Build a text note for any image parts in MSG.
541+
542+ Compaction flattens messages to plain text (``_message_text`` calls
543+ ``Message.text()``, which skips ``ImagePart``). Without this note
544+ the model would have no indication an image was ever present, so a
545+ follow-up like "what about the screenshot I sent?" would be
546+ unanswerable after compaction.
547+ """
548+ content = getattr (msg , "content" , None )
549+ if not isinstance (content , list ):
550+ return ""
551+ parts : list [str ] = []
552+ for p in content :
553+ if isinstance (p , ImagePart ):
554+ if p .path :
555+ parts .append (f"[image was attached: { p .path } ]" )
556+ else :
557+ parts .append ("[image was attached]" )
558+ return "\n " .join (parts )
559+
560+
536561def compact_summary (
537562 client : Any ,
538563 conversation : str ,
You can’t perform that action at this time.
0 commit comments