# astrasv/master-worker-evolab-llm architecture

> Architecture diagram of the GitHub repository astrasv/master-worker-evolab-llm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/astrasv/master-worker-evolab-llm
- Repository: https://github.com/astrasv/master-worker-evolab-llm

## Overview

#### 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: [`agents/orchestrator.py`](https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/orchestrator.py) (12-cell assembler), [`agents/unit_verifier.py`](https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/unit_verifier.py) (Unit verifier), [`agents/integration_verifier.py`](https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/integration_verifier.py) (Integration verifier), [`agents/master.py`](https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/master.py) (Problem decomposer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Graph control plane"]
  node_engine{{"LangGraph engine<br/>workflow graph<br/>[engine.py]"}}
  node_state["Shared graph state<br/>typed workflow state<br/>[state.py]"]
  node_batch["Task batching<br/>batch planner<br/>[batch.py]"]
  node_executor["Worker executor<br/>parallel executor<br/>[worker_executor.py]"]
end

subgraph group_agents["Agent pipeline"]
  node_genome_generator["Genome generator<br/>generation agent"]
  node_master["Problem decomposer<br/>master agent<br/>[master.py]"]
  node_worker["Parallel workers<br/>worker agent<br/>[worker.py]"]
  node_unit_verifier["Unit verifier<br/>verification agent<br/>[unit_verifier.py]"]
  node_orchestrator["12-cell assembler<br/>orchestrator agent<br/>[orchestrator.py]"]
  node_integration_verifier["Integration verifier<br/>verification agent"]
end

subgraph group_contracts["Typed contracts"]
  node_problem["Problem contract<br/>Pydantic schema<br/>[problem.py]"]
  node_subtasks["Subtask contracts<br/>Pydantic schemas<br/>[subtasks.py]"]
  node_individual["Genome contract<br/>Pydantic schema<br/>[individual.py]"]
  node_orchestrator_contract["Assembly contract<br/>Pydantic schema<br/>[orchestrator.py]"]
  node_verifier_contracts["Verifier contracts<br/>Pydantic schemas<br/>[verifiers.py]"]
end

subgraph group_providers["Model integration"]
  node_config["Pipeline config<br/>YAML configuration<br/>[config.yaml]"]
  node_prompts["Prompt contracts<br/>system prompts<br/>[master_prompt.py]"]
  node_providers["SLM provider adapters<br/>model backends"]
end

node_entry["Pipeline entry<br/>Python entry point<br/>[main.py]"]
node_output["Generated EA code<br/>final artifact<br/>[output_code.py]"]

node_entry -->|"loads"| node_config
node_entry -->|"starts"| node_engine
node_engine -->|"reads and updates"| node_state
node_engine -->|"runs first"| node_genome_generator
node_genome_generator -->|"produces"| node_individual
node_individual -->|"informs"| node_master
node_problem -->|"defines request"| node_master
node_master -->|"creates"| node_subtasks
node_subtasks -->|"groups"| node_batch
node_batch -->|"dispatches"| node_executor
node_executor -->|"fans out"| node_worker
node_worker -->|"submits modules"| node_unit_verifier
node_unit_verifier -.->|"retry on failure"| node_worker
node_unit_verifier -->|"verified work"| node_orchestrator
node_orchestrator_contract -->|"constrains output"| node_orchestrator
node_orchestrator -->|"assembles 12 cells"| node_integration_verifier
node_integration_verifier -.->|"retry on failure"| node_orchestrator
node_verifier_contracts -->|"structures results"| node_unit_verifier
node_verifier_contracts -->|"structures results"| node_integration_verifier
node_integration_verifier -->|"passes"| node_output
node_config -->|"selects"| node_providers
node_prompts -->|"supplies prompts"| node_providers
node_providers -->|"serves model calls"| node_genome_generator
node_providers -->|"serves model calls"| node_master
node_providers -->|"serves model calls"| node_worker
node_providers -->|"serves model calls"| node_orchestrator

click node_entry "https://github.com/astrasv/master-worker-evolab-llm/blob/main/main.py"
click node_config "https://github.com/astrasv/master-worker-evolab-llm/blob/main/config.yaml"
click node_engine "https://github.com/astrasv/master-worker-evolab-llm/blob/main/workflow/engine.py"
click node_state "https://github.com/astrasv/master-worker-evolab-llm/blob/main/workflow/state.py"
click node_batch "https://github.com/astrasv/master-worker-evolab-llm/blob/main/workflow/batch.py"
click node_executor "https://github.com/astrasv/master-worker-evolab-llm/blob/main/workflow/worker_executor.py"
click node_problem "https://github.com/astrasv/master-worker-evolab-llm/blob/main/models/problem.py"
click node_subtasks "https://github.com/astrasv/master-worker-evolab-llm/blob/main/models/subtasks.py"
click node_individual "https://github.com/astrasv/master-worker-evolab-llm/blob/main/models/individual.py"
click node_orchestrator_contract "https://github.com/astrasv/master-worker-evolab-llm/blob/main/models/orchestrator.py"
click node_verifier_contracts "https://github.com/astrasv/master-worker-evolab-llm/blob/main/models/verifiers.py"
click node_genome_generator "https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/genome_generator.py"
click node_master "https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/master.py"
click node_worker "https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/worker.py"
click node_unit_verifier "https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/unit_verifier.py"
click node_orchestrator "https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/orchestrator.py"
click node_integration_verifier "https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/integration_verifier.py"
click node_prompts "https://github.com/astrasv/master-worker-evolab-llm/blob/main/system_prompts/master_prompt.py"
click node_output "https://github.com/astrasv/master-worker-evolab-llm/blob/main/output_code.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_engine,node_state,node_batch,node_executor toneBlue
class node_genome_generator,node_master,node_worker,node_unit_verifier,node_orchestrator,node_integration_verifier toneAmber
class node_problem,node_subtasks,node_individual,node_orchestrator_contract,node_verifier_contracts toneMint
class node_config,node_prompts,node_providers toneRose
class node_entry,node_output toneNeutral
```

## Components

### Graph control plane

Stateful LangGraph execution and worker coordination.

- [LangGraph engine](https://github.com/astrasv/master-worker-evolab-llm/blob/main/workflow/engine.py): workflow graph · Coordinates stages, fan-out/fan-in, and conditional retries. · `workflow/engine.py`
- [Shared graph state](https://github.com/astrasv/master-worker-evolab-llm/blob/main/workflow/state.py): typed workflow state · `workflow/state.py`
- [Task batching](https://github.com/astrasv/master-worker-evolab-llm/blob/main/workflow/batch.py): batch planner · `workflow/batch.py`
- [Worker executor](https://github.com/astrasv/master-worker-evolab-llm/blob/main/workflow/worker_executor.py): parallel executor · `workflow/worker_executor.py`

### Agent pipeline

Generation, assembly, and verification stages.

- [Genome generator](https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/genome_generator.py): generation agent · Creates the base individual representation. · `agents/genome_generator.py`
- [Problem decomposer](https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/master.py): master agent · Breaks the requested EA into modular subtasks. · `agents/master.py`
- [Parallel workers](https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/worker.py): worker agent · Implements assigned subtasks. · `agents/worker.py`
- [Unit verifier](https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/unit_verifier.py): verification agent · Validates individual worker outputs before assembly. · `agents/unit_verifier.py`
- [12-cell assembler](https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/orchestrator.py): orchestrator agent · Composes verified work into the fixed output representation. · `agents/orchestrator.py`
- [Integration verifier](https://github.com/astrasv/master-worker-evolab-llm/blob/main/agents/integration_verifier.py): verification agent · Checks cross-cell and system consistency. · `agents/integration_verifier.py`

### Typed contracts

Structured boundaries for model outputs and workflow data.

- [Problem contract](https://github.com/astrasv/master-worker-evolab-llm/blob/main/models/problem.py): Pydantic schema · `models/problem.py`
- [Subtask contracts](https://github.com/astrasv/master-worker-evolab-llm/blob/main/models/subtasks.py): Pydantic schemas · `models/subtasks.py`
- [Genome contract](https://github.com/astrasv/master-worker-evolab-llm/blob/main/models/individual.py): Pydantic schema · `models/individual.py`
- [Assembly contract](https://github.com/astrasv/master-worker-evolab-llm/blob/main/models/orchestrator.py): Pydantic schema · `models/orchestrator.py`
- [Verifier contracts](https://github.com/astrasv/master-worker-evolab-llm/blob/main/models/verifiers.py): Pydantic schemas · `models/verifiers.py`

### Model integration

Configurable providers and centralized prompts.

- [Pipeline config](https://github.com/astrasv/master-worker-evolab-llm/blob/main/config.yaml): YAML configuration · Assigns providers and models per agent. · `config.yaml`
- [Prompt contracts](https://github.com/astrasv/master-worker-evolab-llm/blob/main/system_prompts/master_prompt.py): system prompts · Centralized agent and verifier prompt definitions. · `system_prompts/master_prompt.py`
- **SLM provider adapters**: model backends · Routes agent calls to Groq, OpenRouter, or local Ollama.

### Other components

- [Pipeline entry](https://github.com/astrasv/master-worker-evolab-llm/blob/main/main.py): Python entry point · `main.py`
- [Generated EA code](https://github.com/astrasv/master-worker-evolab-llm/blob/main/output_code.py): final artifact · Persisted only after integration verification passes. · `output_code.py`

## Connections

- 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
