How astrasv/master-worker-evolab-llm works
Purpose and Entry Point
This repository is a Python 3.11 multi-agent code-generation pipeline for producing verified evolutionary-algorithm code. It decomposes a problem statement, generates code modules in parallel, verifies them, assembles a fixed 12-cell output, and writes the result to output_code.py.
Execution starts at main.py; pipeline behavior and model/provider assignment are configured in config.yaml.
Graph-Orchestrated Workflow
The control plane is a LangGraph state graph built in workflow/engine.py. It coordinates agent nodes, conditional retry loops, and fan-out/fan-in worker execution. Shared typed graph state is defined in workflow/state.py, with execution support in workflow/worker_executor.py and batching logic in workflow/batch.py.
Primary flow:
genome generation → problem decomposition → parallel worker generation → unit verification/retry → orchestration → integration verification/retry → final code output.
Typed Domain Contracts
Pydantic models define the structured inputs and outputs exchanged among agents and workflow stages. Key contracts include problem definition, generated individuals/genomes, subtask plans, orchestrator output, and verifier responses.
Core paths:
• models/problem.py
• models/subtasks.py
• models/individual.py
• models/orchestrator.py
• models/verifiers.py
These schemas are an important boundary: language-model output is constrained and parsed into typed objects before downstream stages consume it.
Generation and Decomposition Agents
The initial generation stages establish the target EA structure and work plan:
• agents/genome_generator.py creates the base genome/individual representation.
• agents/master.py breaks the requested EA into modular subtasks.
• agents/worker.py implements assigned subtasks.
• agents/orchestrator.py composes verified work into the required 12-cell representation.
The worker stage is map-reduce-like: the graph fans tasks out to workers, then collects their structured outputs for validation and assembly.
Verification and Recovery Loops
Two validation boundaries prevent unverified code from reaching the final artifact:
• agents/unit_verifier.py evaluates individual worker outputs; failures route work back to generation.
• agents/integration_verifier.py checks cross-cell/system logic after assembly; failures route back to orchestration.
This separates local correctness from whole-system consistency and makes retries graph-level control flow rather than ad hoc agent behavior.
Model Provider Layer and Prompts
Agents use configurable SLM backends behind provider adapters:
• slm/chatgroq.py for Groq-hosted models
• slm/openrouter.py for OpenRouter
• slm/ollama.py for a local Ollama server
Provider selection is per agent in config.yaml. External dependencies are Groq (GROQ_API_KEY), OpenRouter (OPENROUTER_API_KEY), or local Ollama at http://localhost:11434. Prompt contracts are centralized in system_prompts/, including system_prompts/master_prompt.py, system_prompts/worker_prompt.py, and verifier-specific prompts.
Output Boundary
After integration passes, the assembled code is persisted as the repository-root artifact output_code.py. Configuration loading, structured-model conversion, and logging are centralized under utils/load_config.py, utils/json_to_model.py, and utils/logging.py, keeping infrastructure concerns outside agent and graph logic.
Main entry points: orchestrator.py 12-cell assembler · unit_verifier.py Unit verifier · integration_verifier.py Integration verifier · master.py Problem decomposer
Components 20
Graph control plane
Stateful LangGraph execution and worker coordination.
- LangGraph engine · Coordinates stages, fan-out/fan-in, and conditional retries.
workflow/engine.py - Shared graph state
workflow/state.py - Task batching
workflow/batch.py - Worker executor
workflow/worker_executor.py
Agent pipeline
Generation, assembly, and verification stages.
- Genome generator · Creates the base individual representation.
agents/genome_generator.py - Problem decomposer · Breaks the requested EA into modular subtasks.
agents/master.py - Parallel workers · Implements assigned subtasks.
agents/worker.py - Unit verifier · Validates individual worker outputs before assembly.
agents/unit_verifier.py - 12-cell assembler · Composes verified work into the fixed output representation.
agents/orchestrator.py - Integration verifier · Checks cross-cell and system consistency.
agents/integration_verifier.py
Typed contracts
Structured boundaries for model outputs and workflow data.
- Problem contract
models/problem.py - Subtask contracts
models/subtasks.py - Genome contract
models/individual.py - Assembly contract
models/orchestrator.py - Verifier contracts
models/verifiers.py
Model integration
Configurable providers and centralized prompts.
- Pipeline config · Assigns providers and models per agent.
config.yaml - Prompt contracts · Centralized agent and verifier prompt definitions.
system_prompts/master_prompt.py - SLM provider adapters · Routes agent calls to Groq, OpenRouter, or local Ollama.
Other components
- Pipeline entry
main.py - Generated EA code · Persisted only after integration verification passes.
output_code.py
Connections 26
- Pipeline entry → Pipeline config: loads
- Pipeline entry → LangGraph engine: starts
- LangGraph engine → Shared graph state: reads and updates
- LangGraph engine → Genome generator: runs first
- Genome generator → Genome contract: produces
- Genome contract → Problem decomposer: informs
- Problem contract → Problem decomposer: defines request
- Problem decomposer → Subtask contracts: creates
- Subtask contracts → Task batching: groups
- Task batching → Worker executor: dispatches
- Worker executor → Parallel workers: fans out
- Parallel workers → Unit verifier: submits modules
- Unit verifier → Parallel workers: retry on failure
- Unit verifier → 12-cell assembler: verified work
- Assembly contract → 12-cell assembler: constrains output
- 12-cell assembler → Integration verifier: assembles 12 cells
- Integration verifier → 12-cell assembler: retry on failure
- Verifier contracts → Unit verifier: structures results
- Verifier contracts → Integration verifier: structures results
- Integration verifier → Generated EA code: passes
- Pipeline config → SLM provider adapters: selects
- Prompt contracts → SLM provider adapters: supplies prompts
- SLM provider adapters → Genome generator: serves model calls
- SLM provider adapters → Problem decomposer: serves model calls
- SLM provider adapters → Parallel workers: serves model calls
- SLM provider adapters → 12-cell assembler: serves model calls