|
9 | 9 | from unittest import mock |
10 | 10 |
|
11 | 11 | from python_agent_harness import config |
12 | | -from python_agent_harness.models import Message |
| 12 | +from python_agent_harness.models import ImagePart, Message, TextPart |
13 | 13 | from python_agent_harness.prompts import ( |
14 | 14 | _SKILLS_FALLBACK, |
15 | 15 | _parse_skill_frontmatter, |
@@ -442,6 +442,37 @@ def test_list_content_joined(self): |
442 | 442 | ] |
443 | 443 | self.assertEqual(user_prompt_texts(msgs), ["hello world"]) |
444 | 444 |
|
| 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 | + |
445 | 476 |
|
446 | 477 | class TestAssembleToolInstructions(unittest.TestCase): |
447 | 478 | """Tests for assemble_tool_instructions and load_agent_prompt's |
|
0 commit comments