#2326·swarms

[BUG][Agent.run][n > 1 drops img, imgs, streaming_callback and kwargs, so every sample runs without the image]

Author: ayaangazaliCreated Sep 22, 2026Updated Sep 22, 2026

Summary

Agent.run(..., n=2) drops every input except task. Each sample runs without the image, without the streaming callback and without any extra kwargs. For a vision call this means the model is asked to describe a chart it never received, and it answers anyway. The answer looks normal, nothing raises, and nothing is logged.

n is documented on run() as "How many outputs to generate (number of runs)". It is not documented as "runs without the other arguments".

Reproduction

Offline, with call_llm stubbed so it records what each sample actually receives:

python
from swarms import Agent

calls = []
def fake(self, task, img=None, imgs=None, current_loop=0, streaming_callback=None, *a, **k):
    calls.append({"img": img, "callback": streaming_callback is not None})
    return "A bar chart."
Agent.call_llm = fake

agent = Agent(agent_name="Vision", model_name="gpt-5.4", max_loops=1, print_on=False)
img = "https://example.com/chart.png"
cb = lambda tok: None

agent.run("Describe the chart.", img=img, streaming_callback=cb)
print("n=1:", calls); calls.clear()
agent.run("Describe the chart.", img=img, streaming_callback=cb, n=2)
print("n=2:", calls)

On master (04c8e97d):

n=1: [{'img': 'https://example.com/chart.png', 'callback': True}]
n=2: [{'img': None, 'callback': False}, {'img': None, 'callback': False}]

Expected:

n=2: [{'img': 'https://example.com/chart.png', 'callback': True}, {'img': 'https://example.com/chart.png', 'callback': True}]

Root cause

swarms/structs/agent.py:3403-3404:

python
elif n > 1:
    output = [self.run(task=task) for _ in range(n)]

The n == 1 branch right below passes img, imgs, streaming_callback, messages, *args and **kwargs to self._run. The n > 1 branch re-enters run() with task only, so img, imgs and streaming_callback fall back to None, and caller kwargs such as tool_choice or a per-call temperature are silently discarded.

Expected fix

Make each sample the same call the single-sample branch makes:

python
elif n > 1:
    output = [
        self._run(task=task, img=img, imgs=imgs, streaming_callback=streaming_callback, messages=messages, *args, **kwargs)
        for _ in range(n)
    ]

The change is confined to this one branch.

A related point I am deliberately leaving out of this fix: when no messages are passed, the samples still share short_memory, so sample 2 reads sample 1. That is the independence question #2319 fixed for SelfConsistencyAgent, and it needs its own decision about what n should mean.