[Bug] *args on the run/arun forwarders is unreachable: every splat after a keyword raises TypeError
## Summary
A number of public entry points across `swarms/` forward to an inner `run`/`_run` like this:
```python
self._run(
task=task,
img=img,
*args,
**kwargs,
)
```
Python evaluates that as `self._run(*args, task=task, img=img, **kwargs)`, so the first splatted positional is bound to the callee's first parameter — which is the one already supplied by keyword. Any non-empty `*args` therefore raises:
```
TypeError: _run() got multiple values for argument 'task'
```
The `*args` these methods advertise in their signatures and docstrings can never carry a value. It is not that it is rarely used — it cannot be used at all.
## Sites
| File | Line | Callee |
|---|---|---|
| `swarms/structs/agent.py` | 1892 | `autonomous_loop._run_autonomous_loop` |
| `swarms/structs/agent.py` | 2077 | `self.run` (from `receive_message`) |
| `swarms/structs/agent.py` | 2152 | `self.run` (from `run_concurrent_tasks`) |
| `swarms/structs/agent.py` | 3076 | `self._run_autonomous_loop` |
| `swarms/structs/agent_rearrange.py` | 856 | `self._run` |
| `swarms/structs/agent_rearrange.py` | 1040 | `self.run` (concurrent batch) |
| `swarms/structs/swarm_router.py` | 940 | `self._run` |
| `swarms/structs/hiearchical_swarm.py` | 1863 | `self.run` (via `asyncio.to_thread`) |
| `swarms/agents/consistency_agent.py` | 269 | `reasoning_agent.run` |
Reproduction against any of them, e.g. `AgentRearrange`:
```python
swarm.run("task", None, "extra")
# TypeError: _run() got multiple values for argument 'task'
```
## Why it is worth cleaning up
Right now this fails loudly, which is the tolerable version. It stops being tolerable the moment someone "fixes" a site by making the forward positional instead — the extras then bind to whatever named parameters sit between, and the call succeeds with the wrong values in the wrong slots. That is what happened to `Agent.arun` in #1871, and #1879 walks it back.
The two options per site are to drop the dead `*args` from the signature, or to forward positionally *and* keep the parameter lists aligned. Dropping it is smaller and does not create a signature that has to stay in sync — extras are already reachable by name through `**kwargs`.
Happy to send a PR for the remaining sites if that is the direction you want; I did not want to bundle nine call sites across five files into the `arun` fix.
1 条评论