Skip to content

[BUG] Tool result images from earlier tool results bleed into subsequent ones (Ollama) #845

Description

@edelauna

Problem

When a user message includes multiple tool results in the same turn, images from an earlier tool result are incorrectly included in subsequent tool result messages sent to Ollama.

Context (who is affected and when)

Affects any Ollama conversation where the model uses tools and returns multiple tool results in a single turn, and at least one of those results contains an image (e.g. a screenshot tool result).

Reproduction steps

  1. Configure Zoo Code with the Ollama provider (any vision-capable model, e.g. llava)
  2. Run a task that causes multiple tool calls to fire in the same turn
  3. Ensure at least one tool result contains an image
  4. Inspect the outgoing Ollama API request payload (or observe model confusion/hallucinations referencing the wrong image)

Expected result

Each tool result message is sent to Ollama with only its own images attached.

Actual result

The second (and any subsequent) tool result messages include images from all previous tool results in the same turn, leading to redundant context, higher token consumption, and potential model confusion.

Root cause

src/api/providers/native-ollama.ts:53toolResultImages: string[] is declared outside the toolMessages.forEach loop, so images accumulate across iterations. Each subsequent ollamaMessages.push inherits all images pushed by earlier iterations.

Fix: Move the declaration inside the loop so each tool result message gets its own isolated image array.

App Version

Post-#832 (current HEAD)

API Provider

Ollama

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions