[BUGF] validate autoswarm max_loops before generating Python#1538
Open
shaun0927 wants to merge 2 commits into
Open
[BUGF] validate autoswarm max_loops before generating Python#1538shaun0927 wants to merge 2 commits into
shaun0927 wants to merge 2 commits into
Conversation
… expressions The autoswarm writer interpolated swarm_architecture.max_loops directly into generated Python source. This change validates/coerces the field before emission and adds a regression test that rejects non-integer expressions instead of writing executable code into the generated module. Constraint: Keep autoswarm writer behavior unchanged for valid integer inputs Rejected: Route max_loops through _format_value only | would silently pass invalid string values into SwarmRouter instead of failing fast Confidence: high Scope-risk: narrow Reversibility: clean Directive: Any future code-generated SwarmRouter field should be validated or literal-formatted before emission; do not interpolate raw config values into Python source Tested: PYTHONPATH=. python -m pytest tests/agents/test_autoswarm_writer.py -k 'swarm_max_loops' -q Not-tested: End-to-end autoswarm CLI execution against live model providers
…c YAML The initial fix blocked executable expressions, but it still skipped validation for falsey values and did not prove quoted numeric strings remained compatible. This follow-up validates any explicit max_loops field and adds regression coverage for both accepted quoted integers and rejected boolean values. Constraint: Preserve compatibility with common YAML/LLM output that serializes integers as strings Rejected: Leave validation gated on truthiness | would silently ignore explicit False/empty values instead of validating them Confidence: high Scope-risk: narrow Reversibility: clean Directive: Presence-based validation is safer than truthiness checks for generated config fields; keep this pattern for future autoswarm writer hardening Tested: PYTHONPATH=. python -m pytest tests/agents/test_autoswarm_writer.py -k 'swarm_max_loops' -q Not-tested: End-to-end autoswarm CLI execution against live model providers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a code-generation sink in
write_autoswarm_file(). The autoswarm writer previously interpolatedswarm_architecture.max_loopsdirectly into generated Python source. If that field contained a non-integer string expression, the generated module embedded executable code instead of a validated literal.This change keeps the PR intentionally narrow:
swarm_architecture.max_loopsto an integer-compatible value before emissionValueErrorfor unsafe / invalid valuesFiles Changed
swarms/agents/auto_generate_swarm_config.pytests/agents/test_autoswarm_writer.pyIssue
Closes #1535
Dependencies
No extra dependencies required.
Maintainer
@kyegomez
Test plan
PYTHONPATH=. python -m pytest tests/agents/test_autoswarm_writer.py -k 'swarm_max_loops' -qWhy this scope
Recent merged PRs in this repo tend to land when they stay tightly scoped, include a direct regression test, and avoid bundling adjacent cleanups. This PR only fixes the confirmed
max_loopsgeneration path and leaves the rest of autoswarm codegen unchanged.📚 Documentation preview 📚: https://swarms--1538.org.readthedocs.build/en/1538/