@@ -656,6 +656,51 @@ func BenchmarkBuildSummaryPrompt(b *testing.B) {
659+func TestPreparePrompt_FiltersImageAttachments(t *testing.T) {
661+ sa := testSessionAgent(env, nil, nil, "test prompt")
662+ agent := sa.(*sessionAgent)
665+ sess, err := env.sessions.Create(ctx, "test")
666+ require.NoError(t, err)
668+ // User message with text, a text attachment, and an image attachment.
669+ _, err = env.messages.Create(ctx, sess.ID, message.CreateMessageParams{
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")},
677+ require.NoError(t, err)
679+ msgs, err := env.messages.List(ctx, sess.ID)
680+ require.NoError(t, err)
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])
689+ require.Contains(t, text.Text, "hello world")
690+ require.Contains(t, text.Text, "important notes")
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])
698+ require.Contains(t, text.Text, "hello world")
699+ file, ok := fantasy.AsMessagePart[fantasy.FilePart](history[1].Content[1])
701+ require.Equal(t, "image.png", file.Filename)
659func TestPreparePrompt_OrphanedToolUse(t *testing.T) {
704func TestPreparePrompt_OrphanedToolUse(t *testing.T) {
660 env := testEnv(t)
705 env := testEnv(t)
661 sa := testSessionAgent(env, nil, nil, "test prompt")
706 sa := testSessionAgent(env, nil, nil, "test prompt")
@@ -702,7 +747,7 @@ func TestPreparePrompt_OrphanedToolUse(t *testing.T) {
702 msgs, err := env.messages.List(ctx, sess.ID)
747 msgs, err := env.messages.List(ctx, sess.ID)
703 require.NoError(t, err)
748 require.NoError(t, err)
705− history, _ := agent.preparePrompt(msgs)
750+ history, _ := agent.preparePrompt(msgs, true)
707 // The history must contain a synthetic tool result for the orphaned call.
752 // The history must contain a synthetic tool result for the orphaned call.
708 found := false
753 found := false
@@ -776,7 +821,7 @@ func TestPreparePrompt_OrphanedToolUseMixed(t *testing.T) {
776 msgs, err := env.messages.List(ctx, sess.ID)
821 msgs, err := env.messages.List(ctx, sess.ID)
777 require.NoError(t, err)
822 require.NoError(t, err)
779− history, _ := agent.preparePrompt(msgs)
824+ history, _ := agent.preparePrompt(msgs, true)
781 // Should have a synthetic result only for the orphaned call.
826 // Should have a synthetic result only for the orphaned call.
782 var syntheticCount int
827 var syntheticCount int