@@ -656,6 +656,51 @@ func BenchmarkBuildSummaryPrompt(b *testing.B) {
656656 }
657657}
658658
659+func TestPreparePrompt_FiltersImageAttachments(t *testing.T) {
660+ env := testEnv(t)
661+ sa := testSessionAgent(env, nil, nil, "test prompt")
662+ agent := sa.(*sessionAgent)
663+
664+ ctx := t.Context()
665+ sess, err := env.sessions.Create(ctx, "test")
666+ require.NoError(t, err)
667+
668+ // User message with text, a text attachment, and an image attachment.
669+ _, err = env.messages.Create(ctx, sess.ID, message.CreateMessageParams{
670+ Role: message.User,
671+ Parts: []message.ContentPart{
672+ message.TextContent{Text: "hello world"},
673+ message.BinaryContent{Path: "notes.txt", MIMEType: "text/plain", Data: []byte("important notes")},
674+ message.BinaryContent{Path: "image.png", MIMEType: "image/png", Data: []byte("fake-image-data")},
675+ },
676+ })
677+ require.NoError(t, err)
678+
679+ msgs, err := env.messages.List(ctx, sess.ID)
680+ require.NoError(t, err)
681+
682+ // When supportsImages is false, image attachments should be stripped.
683+ history, _ := agent.preparePrompt(msgs, false)
684+ // First message is the system reminder, second is the user message.
685+ require.Len(t, history, 2)
686+ require.Len(t, history[1].Content, 1)
687+ text, ok := fantasy.AsMessagePart[fantasy.TextPart](history[1].Content[0])
688+ require.True(t, ok)
689+ require.Contains(t, text.Text, "hello world")
690+ require.Contains(t, text.Text, "important notes")
691+
692+ // When supportsImages is true, image attachments should remain.
693+ history, _ = agent.preparePrompt(msgs, true)
694+ require.Len(t, history, 2)
695+ require.Len(t, history[1].Content, 2)
696+ text, ok = fantasy.AsMessagePart[fantasy.TextPart](history[1].Content[0])
697+ require.True(t, ok)
698+ require.Contains(t, text.Text, "hello world")
699+ file, ok := fantasy.AsMessagePart[fantasy.FilePart](history[1].Content[1])
700+ require.True(t, ok)
701+ require.Equal(t, "image.png", file.Filename)
702+}
703+
659704func TestPreparePrompt_OrphanedToolUse(t *testing.T) {
660705 env := testEnv(t)
661706 sa := testSessionAgent(env, nil, nil, "test prompt")
@@ -702,7 +747,7 @@ func TestPreparePrompt_OrphanedToolUse(t *testing.T) {
702747 msgs, err := env.messages.List(ctx, sess.ID)
703748 require.NoError(t, err)
704749
705โ history, _ := agent.preparePrompt(msgs)
750+ history, _ := agent.preparePrompt(msgs, true)
706751
707752 // The history must contain a synthetic tool result for the orphaned call.
708753 found := false
@@ -776,7 +821,7 @@ func TestPreparePrompt_OrphanedToolUseMixed(t *testing.T) {
776821 msgs, err := env.messages.List(ctx, sess.ID)
777822 require.NoError(t, err)
778823
779โ history, _ := agent.preparePrompt(msgs)
824+ history, _ := agent.preparePrompt(msgs, true)
780825
781826 // Should have a synthetic result only for the orphaned call.
782827 var syntheticCount int