Skip to content

feat: add constraint validation to evolve workflow - #1067

Open
abhi1092 wants to merge 18 commits into
akashgit:mainfrom
abhi1092:factory/run-26a17d09
Open

feat: add constraint validation to evolve workflow#1067
abhi1092 wants to merge 18 commits into
akashgit:mainfrom
abhi1092:factory/run-26a17d09

Conversation

@abhi1092

Copy link
Copy Markdown
Collaborator

Summary

  • Add constraint validation to the evolve workflow's researcher prompt — reads constraints from eval.json, filters optimization techniques, requires Constraint Compliance section in output
  • Harden the strategy gate with MANDATORY constraint check (first gate item) and NON-NEGOTIABLE stuck detection (3 consecutive reverts → forced reloop to researcher)
  • Update strategist and research gate for constraint awareness — strategist validates hypotheses against constraints, research gate verifies constraint coverage

Changes

4 node updates in factory/workflow/definitions.py (evolve_workflow function):

  • researcher — prompt_template adds constraint reading/filtering
  • gate_research — gate_prompt adds CONSTRAINT COVERAGE verification
  • strategist — prompt_template + reads set add eval.json constraint validation
  • gate_strategy — gate_prompt reordered: constraints first, then mandatory stuck detection, then quality checks; reads set adds eval.json

No topology changes (14 nodes, 17 edges unchanged). SKILL.md and annotations regenerated.

Test plan

  • factory workflow validate evolve passes (14 nodes, 17 edges)
  • factory workflow export-skills --verify — all 25 skills valid
  • ruff check factory/workflow/definitions.py — clean
  • pytest tests/test_evolve_workflow.py -v — 20/20 pass
  • 247 workflow-related tests pass (definitions, registry, skill export, lint)
  • SKILL.md contains constraint text in all 4 updated sections
  • Adversarial QA: all 9 acceptance criteria verified with evidence

🤖 Generated with Claude Code

abhi1092 and others added 18 commits July 24, 2026 07:41
…e effectiveness

Adds W₁₂ optimize mode — a meta-mode that analyzes how well an existing
factory mode performs, identifies weaknesses (high redirect rates, agent
timeouts, low keep rates), generates a targeted change specification, and
delegates implementation to create mode. Interactive-only with user
approval gate before modifying workflows.

Changes:
- Add optimize_workflow() to factory/workflow/definitions.py (8 nodes, 9 edges)
- Register in register_all() and __all__
- Add WORKFLOW_META entry in skill_export.py
- Wire --mode optimize in CLI (_helpers.py, _main.py, ceo.py)
- Add optimize to CycleState.mode Literal in models.py
- Add 12 tests in tests/test_optimize_workflow.py

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: add optimize workflow mode for factory mode effectiveness tuning
Signed-off-by: Abhishek Bhandwaldar <abhi1092@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…evaluation

Implements W₁₄: Evolve Mode — a tight evaluate-mutate-select loop that
optimizes a single scalar metric by evolving code within EVOLVE-BLOCK
boundaries, evaluated externally via MCP server tools (get_benchmark_info,
evaluate_solution).

Key design decisions:
- No deep-QA pipeline (single health_checker with MCP eval replaces the
  3-specialist QA pipeline — tighter loops produce better results)
- Elitist keep/revert: score must strictly improve
- FEEC stuck detection: 3 consecutive reverts → re-research
- Convergence: target score, max cycles, or diminishing returns

Changes:
- factory/workflow/definitions.py: evolve_workflow() + register_all()
- factory/workflow/skill_export.py: WORKFLOW_META entry
- factory/cli/_helpers.py: CEO_MODES list
- factory/cli/ceo.py: validation, ceo_mode routing, _build_ceo_task
- tests/test_evolve_workflow.py: 20 tests (5 classes)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The evolve workflow was added in 7a14aee but its generated SKILL.md
and annotations were not committed, so the CEO cannot load the evolve
mode playbook at runtime.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: add evolve workflow mode and research queue baseline
Reads .factory/ artifacts (events.jsonl, results.tsv, experiment dirs)
and produces structured CycleRecord objects that any outer-loop optimizer
can consume. Mode-agnostic — works with evolve, improve, research, refine.

Tiered data assembly:
- Tier 1: events.jsonl for agent steps, costs, durations
- Tier 2: results.tsv for experiment scores, verdicts, hypotheses
- Tier 3: experiment dirs for eval artifact discovery
- Tier 4: workflow definition for DAG node mapping

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: add CycleAnalyzer for outer-loop optimizer observability
…ation

InnerLoop wraps a factory mode + evaluator into a model.forward()-like
interface that any outer-loop optimizer can call. CycleAnalyzer reads
.factory/ artifacts and produces structured CycleRecord objects.

Includes CirclePackingEvaluator as the first concrete evaluator
implementation, tested against skydiscover's circle packing benchmark.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Evaluator now reads output artifacts that the inner loop already produced,
rather than calling the evaluator binary directly. CirclePackingEvaluator
parses {sum_radii, validity, eval_time, combined_score} JSON files.

CycleAnalyzer: execution tracing (agents, costs, verdicts)
Evaluator: score interpretation (evaluator-specific artifact parsing)
InnerLoop: composes both

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: add InnerLoop and CycleAnalyzer for outer-loop optimizer integration
…prompts

Replace domain-specific prompt hints with domain-agnostic instructions
that direct agents to discover the benchmark domain at runtime from
eval.json, making the evolve workflow work correctly across all
benchmark types.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The SKILL.md was stale after the prompt_template changes in
definitions.py (commit 2cabd28). Regenerated via
`factory workflow export-skills` to reflect the domain-agnostic
researcher and health_checker prompts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
fix: make evolve workflow prompts domain-agnostic
Allow evolve mode to accept --focus to specify a benchmark name.
The focus is injected as a ## Benchmark Target section in the CEO
task, and the Baseline FnNode notes reference it for
get_benchmark_info() calls.

Changes:
- cli/ceo.py: add 'evolve' to allowed focus modes in both cmd_ceo
  and cmd_run gates
- cli/ceo.py: add evolve-specific Benchmark Target task section
  before the generic Focus Directive block
- workflow/definitions.py: update Baseline FnNode notes to read
  benchmark name from the CEO task
- Regenerate workflow-evolve/SKILL.md

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
feat: wire up --focus support for evolve mode
…e workflow

Update 4 nodes in the evolve workflow for constraint awareness:
- researcher: reads constraints from eval.json, filters techniques, requires
  Constraint Compliance section in research output
- gate_research: verifies researcher documented constraints, REDIRECTs if
  constraints exist but were ignored
- strategist: reads eval.json constraints, validates hypothesis compliance,
  adds Constraint Compliance field to output
- gate_strategy: MANDATORY constraint check as first gate item, NON-NEGOTIABLE
  stuck detection (3 consecutive reverts → forced reloop to researcher)

No topology changes — same 14 nodes, 17 edges. Only prompt_template,
gate_prompt, and reads sets modified.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant