Skip to content

[BUG] autoswarm writer emits raw swarm_architecture.max_loops into generated Python #1535

@shaun0927

Description

@shaun0927

Describe the bug
write_autoswarm_file() interpolates swarm_architecture.max_loops directly into generated Python source instead of validating or literal-formatting it first.

That means a non-integer string value is emitted as executable Python code inside the generated module.

To Reproduce

  1. Call write_autoswarm_file() with a config whose swarm_architecture.max_loops is a string expression instead of an integer.
  2. Write the generated file.
  3. Import or execute the generated module.

Minimal example:

config = {
    "agents": [{"agent_name": "Agent A", "system_prompt": "x"}],
    "swarm_architecture": {
        "name": "Research Pipeline",
        "swarm_type": "SequentialWorkflow",
        "max_loops": "(__import__('builtins').globals().__setitem__('INJECTED_FLAG', True) or 1)",
    },
}

At HEAD, the generated file contains:

max_loops=(__import__('builtins').globals().__setitem__('INJECTED_FLAG', True) or 1),

Locally I verified that the side effect runs when the generated module is imported.

Expected behavior
max_loops should be validated/coerced to an integer-compatible value before code generation, or rejected with a ValueError.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions