Skip to content

Commit 21c2b78

Browse files
authored
[Bug] SequentialWorkflow.run accepts imgs and then drops it (#1822)
* [Bug] SequentialWorkflow.run accepts imgs and then drops it run() takes an imgs parameter and documents it as "Optional list of images for the agents", but only task and img ever make it into the kwargs handed to AgentRearrange: run_kwargs = {"task": task} if img is not None: run_kwargs["img"] = img So a multi-image run silently degrades to a text-only run. No error, no warning -- the agents just answer a question about images they were never shown. AgentRearrange forwards **kwargs down to Agent.run, which does accept imgs, so passing it through is all that's needed. * Annotate run_kwargs as Dict[str, Any] so Pyre accepts the imgs list Pyre inferred Dict[str, str] from the task entry alone, so assigning the imgs list tripped 'Incompatible parameter type [6]' in code scanning.
1 parent fd9c2e0 commit 21c2b78

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

swarms/structs/sequential_workflow.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import json
33
import os
44
from concurrent.futures import as_completed
5-
from typing import Callable, List, Optional, Union
5+
from typing import Any, Callable, Dict, List, Optional, Union
66

77
from loguru import logger as loguru_logger
88
from swarms.prompts.multi_agent_collab_prompt import (
@@ -326,9 +326,13 @@ def run(
326326
"""
327327
try:
328328
# prompt = f"{MULTI_AGENT_COLLAB_PROMPT}\n\n{task}"
329-
run_kwargs = {"task": task}
329+
# Annotated because imgs is a list: without it the dict is
330+
# inferred as Dict[str, str] from the task entry alone.
331+
run_kwargs: Dict[str, Any] = {"task": task}
330332
if img is not None:
331333
run_kwargs["img"] = img
334+
if imgs is not None:
335+
run_kwargs["imgs"] = imgs
332336
result = self.agent_rearrange.run(**run_kwargs)
333337

334338
# Run drift detection if configured

tests/structs/test_sequential_workflow.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,3 +612,30 @@ def test_workflow_drift_max_retries_zero_never_reruns():
612612
def test_negative_drift_max_retries_is_rejected():
613613
with pytest.raises(ValueError, match="drift_max_retries"):
614614
_make_workflow(drift_detection=True, drift_max_retries=-1)
615+
616+
617+
def test_run_forwards_imgs_to_the_pipeline():
618+
"""run(imgs=[...]) must reach the agents, not be dropped.
619+
620+
imgs is an accepted, documented parameter, but it was never put
621+
into the kwargs handed to AgentRearrange, so multi-image runs
622+
silently became text-only runs.
623+
"""
624+
wf = _make_workflow()
625+
with patch.object(
626+
wf.agent_rearrange, "run", return_value="out"
627+
) as pipeline:
628+
wf.run("describe these", imgs=["a.png", "b.png"])
629+
630+
assert pipeline.call_args.kwargs["imgs"] == ["a.png", "b.png"]
631+
632+
633+
def test_run_omits_imgs_when_not_supplied():
634+
"""No imgs key when the caller didn't pass one."""
635+
wf = _make_workflow()
636+
with patch.object(
637+
wf.agent_rearrange, "run", return_value="out"
638+
) as pipeline:
639+
wf.run("plain task")
640+
641+
assert "imgs" not in pipeline.call_args.kwargs

0 commit comments

Comments
 (0)