# duperbsg/loop-gen architecture

> Architecture diagram of the GitHub repository duperbsg/loop-gen, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/duperbsg/loop-gen
- Repository: https://github.com/duperbsg/loop-gen

## Overview

agent-loop is a command-line iterative agent for producing written deliverables and, optionally, local media. Its main workflow is coordinated by the CLI: plan, execute, optionally render media, critique, and generate guidance for another iteration until the result passes or the limit is reached. Agent stages share mutable run state and use a provider-adapting LLM layer. The README also documents Anthropic and OpenAI-compatible providers, ComfyUI image/video workflows, and saved run history. Runtime calls are evidenced by the excerpts; documented workflow-file links use README evidence.

Main entry points: [`src/main.py`](https://github.com/duperbsg/loop-gen/blob/main/src/main.py) (Loop runner), [`src/llm.py`](https://github.com/duperbsg/loop-gen/blob/main/src/llm.py) (LLM adapter), [`src/state.py`](https://github.com/duperbsg/loop-gen/blob/main/src/state.py) (Iteration state), [`src/comfy.py`](https://github.com/duperbsg/loop-gen/blob/main/src/comfy.py) (Workflow loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Iteration workflow"]
  node_orchestrator["Loop runner<br/>[main.py]"]
  node_planner["Planner<br/>[planner.py]"]
  node_executor["Executor<br/>[executor.py]"]
  node_critic["Critic<br/>[critic.py]"]
  node_improver["Improver<br/>[improver.py]"]
  node_state["Iteration state<br/>[state.py]"]
end

subgraph group_media["Media generation"]
  node_workflow_loader["Workflow loader<br/>[comfy.py]"]
  node_comfy["ComfyUI"]
  node_sdxl_workflow["SDXL workflow"]
  node_ltx_workflow["LTX video workflow"]
  node_media_outputs["Media files<br/>[comfy.py]"]
end

subgraph group_llm["LLM services"]
  node_llm_adapter["LLM adapter<br/>[llm.py]"]
  node_provider_config["Provider config<br/>[config.py]"]
  node_llm_provider["LLM provider"]
end

subgraph group_records["Run records"]
  node_run_history["Run history<br/>[main.py]"]
end

node_user(("CLI user"))

node_user -->|"starts run"| node_orchestrator
node_orchestrator -->|"invokes"| node_planner
node_orchestrator -->|"invokes"| node_executor
node_orchestrator -->|"invokes"| node_critic
node_orchestrator -->|"invokes on failure"| node_improver
node_orchestrator -->|"creates and updates"| node_state
node_planner -->|"reads run context"| node_state
node_executor -->|"reads plan"| node_state
node_critic -->|"reads output and artifacts"| node_state
node_improver -->|"reads critique"| node_state
node_planner -->|"requests completion"| node_llm_adapter
node_executor -->|"requests completion"| node_llm_adapter
node_critic -->|"requests critique"| node_llm_adapter
node_improver -->|"requests guidance"| node_llm_adapter
node_llm_adapter -->|"reads settings"| node_provider_config
node_llm_adapter -->|"sends completion request"| node_llm_provider
node_orchestrator -->|"loads and edits workflow"| node_workflow_loader
node_orchestrator -->|"queues and polls jobs"| node_comfy
node_workflow_loader -->|"requests media"| node_comfy
node_comfy -->|"returns generated media"| node_media_outputs
node_orchestrator -->|"adds artifact paths"| node_state
node_orchestrator -->|"names images"| node_llm_adapter
node_orchestrator -->|"writes run JSON"| node_run_history
node_sdxl_workflow -.->|"example input"| node_workflow_loader
node_ltx_workflow -.->|"example input"| node_workflow_loader

click node_orchestrator "https://github.com/duperbsg/loop-gen/blob/main/src/main.py"
click node_planner "https://github.com/duperbsg/loop-gen/blob/main/src/agents/planner.py"
click node_executor "https://github.com/duperbsg/loop-gen/blob/main/src/agents/executor.py"
click node_critic "https://github.com/duperbsg/loop-gen/blob/main/src/agents/critic.py"
click node_improver "https://github.com/duperbsg/loop-gen/blob/main/src/agents/improver.py"
click node_state "https://github.com/duperbsg/loop-gen/blob/main/src/state.py"
click node_workflow_loader "https://github.com/duperbsg/loop-gen/blob/main/src/comfy.py"
click node_sdxl_workflow "https://github.com/duperbsg/loop-gen/blob/main/comfy-workflow.json"
click node_ltx_workflow "https://github.com/duperbsg/loop-gen/blob/main/ltx-video-workflow.json"
click node_llm_adapter "https://github.com/duperbsg/loop-gen/blob/main/src/llm.py"
click node_provider_config "https://github.com/duperbsg/loop-gen/blob/main/src/config.py"
click node_run_history "https://github.com/duperbsg/loop-gen/blob/main/src/main.py"
click node_media_outputs "https://github.com/duperbsg/loop-gen/blob/main/src/comfy.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_orchestrator,node_planner,node_executor,node_critic,node_improver,node_state,node_user toneBlue
class node_workflow_loader,node_comfy,node_sdxl_workflow,node_ltx_workflow,node_media_outputs toneAmber
class node_llm_adapter,node_provider_config,node_llm_provider toneMint
class node_run_history toneRose
```

## Components

### Iteration workflow

- [Loop runner](https://github.com/duperbsg/loop-gen/blob/main/src/main.py): `src/main.py`
- [Planner](https://github.com/duperbsg/loop-gen/blob/main/src/agents/planner.py): `src/agents/planner.py`
- [Executor](https://github.com/duperbsg/loop-gen/blob/main/src/agents/executor.py): `src/agents/executor.py`
- [Critic](https://github.com/duperbsg/loop-gen/blob/main/src/agents/critic.py): `src/agents/critic.py`
- [Improver](https://github.com/duperbsg/loop-gen/blob/main/src/agents/improver.py): `src/agents/improver.py`
- [Iteration state](https://github.com/duperbsg/loop-gen/blob/main/src/state.py): `src/state.py`

### Media generation

- [Workflow loader](https://github.com/duperbsg/loop-gen/blob/main/src/comfy.py): `src/comfy.py`
- **ComfyUI**
- [SDXL workflow](https://github.com/duperbsg/loop-gen/blob/main/comfy-workflow.json): `comfy-workflow.json`
- [LTX video workflow](https://github.com/duperbsg/loop-gen/blob/main/ltx-video-workflow.json): `ltx-video-workflow.json`
- [Media files](https://github.com/duperbsg/loop-gen/blob/main/src/comfy.py): `src/comfy.py`

### LLM services

- [LLM adapter](https://github.com/duperbsg/loop-gen/blob/main/src/llm.py): `src/llm.py`
- [Provider config](https://github.com/duperbsg/loop-gen/blob/main/src/config.py): `src/config.py`
- **LLM provider**

### Run records

- [Run history](https://github.com/duperbsg/loop-gen/blob/main/src/main.py): `src/main.py`

### Other components

- **CLI user**

## Connections

- CLI user → Loop runner: starts run (evidence: `README.md`)
- Loop runner → Planner: invokes (evidence: `src/main.py`)
- Loop runner → Executor: invokes (evidence: `src/main.py`)
- Loop runner → Critic: invokes (evidence: `src/main.py`)
- Loop runner → Improver: invokes on failure (evidence: `src/main.py`)
- Loop runner → Iteration state: creates and updates (evidence: `src/main.py`)
- Planner → Iteration state: reads run context (evidence: `src/agents/planner.py`)
- Executor → Iteration state: reads plan (evidence: `src/agents/executor.py`)
- Critic → Iteration state: reads output and artifacts (evidence: `src/agents/critic.py`)
- Improver → Iteration state: reads critique (evidence: `src/agents/improver.py`)
- Planner → LLM adapter: requests completion (evidence: `src/agents/planner.py`)
- Executor → LLM adapter: requests completion (evidence: `src/agents/executor.py`)
- Critic → LLM adapter: requests critique (evidence: `src/agents/critic.py`)
- Improver → LLM adapter: requests guidance (evidence: `src/agents/improver.py`)
- LLM adapter → Provider config: reads settings (evidence: `src/llm.py`)
- LLM adapter → LLM provider: sends completion request (evidence: `src/llm.py`)
- Loop runner → Workflow loader: loads and edits workflow (evidence: `src/main.py`)
- Loop runner → ComfyUI: queues and polls jobs (evidence: `src/main.py`)
- Workflow loader → ComfyUI: requests media (evidence: `src/comfy.py`)
- ComfyUI → Media files: returns generated media (evidence: `src/comfy.py`)
- Loop runner → Iteration state: adds artifact paths (evidence: `src/main.py`)
- Loop runner → LLM adapter: names images (evidence: `src/main.py`)
- Loop runner → Run history: writes run JSON (evidence: `src/main.py`)
- SDXL workflow → Workflow loader: example input (evidence: `README.md`)
- LTX video workflow → Workflow loader: example input (evidence: `README.md`)
