Skip to content

Commit 76bb4d4

Browse files
authored
Update prompts.py
1 parent 5e5cb37 commit 76bb4d4

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

‎python_agent_harness/prompts.py‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from typing import Any
2222

2323
from . import config
24-
from .models import Message
24+
from .models import ImagePart, Message
2525

2626
PROMPTS_DIR = Path(__file__).parent / "prompts"
2727
AGENTS_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+
536561
def compact_summary(
537562
client: Any,
538563
conversation: str,

0 commit comments

Comments
 (0)