Skip to content

Commit 2f93919

Browse files
authored
Update test_prompts.py
1 parent e46352e commit 2f93919

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

‎tests/test_prompts.py‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from unittest import mock
1010

1111
from python_agent_harness import config
12-
from python_agent_harness.models import Message
12+
from python_agent_harness.models import ImagePart, Message, TextPart
1313
from python_agent_harness.prompts import (
1414
_SKILLS_FALLBACK,
1515
_parse_skill_frontmatter,
@@ -442,6 +442,37 @@ def test_list_content_joined(self):
442442
]
443443
self.assertEqual(user_prompt_texts(msgs), ["hello world"])
444444

445+
def test_image_part_gets_placeholder_note(self):
446+
"""A multimodal user message must survive compaction with a note
447+
that an image was attached — otherwise the model loses all
448+
indication the image ever existed."""
449+
msgs = [
450+
Message(
451+
role="user",
452+
content=[
453+
TextPart(text="what is this?"),
454+
ImagePart(data=b"\x89PNG", media_type="image/png", path="/tmp/shot.png"),
455+
],
456+
),
457+
]
458+
self.assertEqual(
459+
user_prompt_texts(msgs),
460+
["what is this?\n[image was attached: /tmp/shot.png]"],
461+
)
462+
463+
def test_image_only_message_dropped(self):
464+
"""An image-only prompt has no text; the image's content is
465+
already captured in the summary, so the prompt is dropped (the
466+
existing empty-text guard) rather than kept as a bare note."""
467+
msgs = [
468+
Message(role="user", content=[ImagePart(data=b"\x89PNG", media_type="image/png")]),
469+
]
470+
self.assertEqual(user_prompt_texts(msgs), [])
471+
472+
def test_no_image_part_no_note(self):
473+
msgs = [Message(role="user", content=[TextPart(text="plain text")])]
474+
self.assertEqual(user_prompt_texts(msgs), ["plain text"])
475+
445476

446477
class TestAssembleToolInstructions(unittest.TestCase):
447478
"""Tests for assemble_tool_instructions and load_agent_prompt's

0 commit comments

Comments
 (0)