# frenzymath/rethlas architecture

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

- Interactive diagram: https://gitdiagram.com/frenzymath/rethlas
- Repository: https://github.com/frenzymath/rethlas

## Overview

1. **Overall system shape**
   - Rethlas is a two-agent math reasoning pipeline.
   - The **generation agent** creates an informal proof blueprint from a Markdown problem statement.
   - The **verification agent** independently checks that blueprint and returns a structured verdict.
   - The architecture is intentionally looped: generation produces a draft, verification evaluates it, and generation can repair based on verifier feedback.

2. **Primary runtime boundary**
   - The two agents are separated into distinct directories and execution environments under `agents/generation` and `agents/verification`.
   - The verifier is designed to run as a **local HTTP service**, while the generator is run through the **Codex CLI**.
   - This separation is the main architectural boundary: one service exposes verification, the other orchestrates reasoning and file production.

3. **Generation agent responsibilities**
   - The generation side reads a problem from `agents/generation/data/*.md`.
   - It produces a draft proof blueprint in `agents/generation/results/<problem-id>/blueprint.md`.
   - It also records execution logs and memory artifacts, which suggests an iterative reasoning process with persistent intermediate state.

4. **Generation-side tooling**
   - `agents/generation/mcp/server.py` and `mcp/requirements.txt` indicate a Python-based **MCP server** used by the generation agent as its tool layer.
   - The `.agents/skills/` directory contains modular reasoning behaviors such as direct proving, recursive proving, toy examples, counterexamples, subgoal decomposition, memory querying, and proof verification.
   - These skills are the reasoning primitives the generator uses to decompose and repair proofs rather than a single monolithic prompt.

5. **Verification agent responsibilities**
   - The verification side ingests proof text and checks claims against referenced statements.
   - It emits a structured verification output defined by `agents/verification/schemas/verification_output.schema.json`.
   - The verifier’s role is not to generate the proof itself, but to validate logical consistency and summarize failures or success.

6. **Verification-side service layout**
   - `agents/verification/api/server.py` exposes the verification functionality as an HTTP API.
   - `agents/verification/mcp/server.py` suggests a second tool-facing entrypoint, likely for agent integration via MCP.
   - The presence of both API and MCP layers means verification can be consumed either as a web service or as an agent tool.

7. **Data flow through the system**
   - Input starts as a Markdown math problem in the generation data directory.
   - Generation creates a draft blueprint, then submits it to the verification service.
   - Verification returns structured feedback, which can drive another generation pass.
   - Final artifacts are split into draft and verified outputs, preserving the evolution of the reasoning process.

8. **Persistence and artifact model**
   - The generator writes three main artifact classes: logs, memory, and results.
   - Logs capture the run trace, memory captures reusable reasoning state, and results capture the proof output itself.
   - The `blueprint_verified.md` file is only produced when verification succeeds, making verified outputs a distinct terminal artifact.

9. **Schemas and contracts**
   - The verification output schema is a key contract boundary in the repo.
   - It anchors the structure of verdicts so the generation agent can consume verification results reliably.
   - This makes the verifier’s output machine-actionable rather than freeform text.

10. **Operational orchestration**
   - The repository expects a specific execution order: start verification first, then run generation.
   - The included `tests/run_example.sh` script is the practical integration harness for the whole system.
   - `agents/verification/scripts/test_verify_endpoint.py` suggests there is also an endpoint-level smoke test for the verifier.

11. **Configuration and agent definitions**
   - Both subprojects contain `.codex` configuration and `.agents` skill definitions.
   - These directories indicate the system is built around Codex-managed agent execution with explicit skill routing.
   - The architecture is therefore agent-centric, not service-centric: behavior is composed from skills and configs rather than a single application framework.

12. **Repository-level mental model for a diagram**
   - Draw two major boxes: **Generation** and **Verification**.
   - Put the Markdown problem files, logs, memory, and result blueprints inside the Generation box.
   - Put the HTTP API, MCP server, and output schema inside the Verification box.
   - Show a one-way verification call from Generation to Verification, with a feedback loop back into Generation for proof repair.

Main entry points: [`agents/generation/mcp/server.py`](https://github.com/frenzymath/rethlas/blob/main/agents/generation/mcp/server.py) (MCP Server), [`agents/verification/api/server.py`](https://github.com/frenzymath/rethlas/blob/main/agents/verification/api/server.py) (HTTP API), [`agents/generation/tests/run_example.sh`](https://github.com/frenzymath/rethlas/blob/main/agents/generation/tests/run_example.sh) (Example Run), [`agents/verification/mcp/server.py`](https://github.com/frenzymath/rethlas/blob/main/agents/verification/mcp/server.py) (MCP Server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_generation["Generation"]
  node_gen_input["Problem Markdown<br/>input data<br/>[example.md]"]
  node_gen_codex["Codex Config<br/>agent config<br/>[config.toml]"]
  node_gen_mcp["MCP Server<br/>tool server<br/>[server.py]"]
  node_gen_skills{{"Reasoning Skills<br/>skill set<br/>[skills]"}}
  node_gen_results[("Proof Artifacts<br/>artifact output")]
  node_gen_blueprint["Draft Blueprint<br/>proof artifact"]
  node_gen_verified["Verified Blueprint<br/>proof artifact"]
  node_gen_logs["Run Logs<br/>execution log"]
  node_gen_memory[("Memory Store<br/>state artifact")]
end

subgraph group_verification["Verification"]
  node_ver_api["HTTP API<br/>service api<br/>[server.py]"]
  node_ver_mcp["MCP Server<br/>tool server<br/>[server.py]"]
  node_ver_schema["Verdict Schema<br/>contract schema"]
  node_ver_skills{{"Check Skills<br/>skill set<br/>[skills]"}}
  node_ver_output["Verification Result<br/>structured verdict"]
end

node_run_harness["Example Run<br/>integration script<br/>[run_example.sh]"]

node_gen_input -->|"read problem"| node_gen_mcp
node_gen_codex -->|"configure"| node_gen_mcp
node_gen_skills -->|"guide reasoning"| node_gen_mcp
node_gen_mcp -->|"draft proof"| node_gen_blueprint
node_gen_mcp -->|"record run"| node_gen_logs
node_gen_mcp -->|"persist memory"| node_gen_memory
node_gen_blueprint -->|"submit for check"| node_ver_api
node_gen_blueprint -.->|"tool check"| node_ver_mcp
node_ver_skills -->|"drive checks"| node_ver_api
node_ver_schema -->|"shape verdict"| node_ver_api
node_ver_api -->|"return result"| node_ver_output
node_ver_mcp -->|"return result"| node_ver_output
node_ver_output -->|"feedback"| node_gen_mcp
node_gen_mcp -->|"repair draft"| node_gen_blueprint
node_gen_blueprint -->|"accept if valid"| node_gen_verified
node_gen_blueprint -->|"store artifact"| node_gen_results
node_gen_verified -->|"store artifact"| node_gen_results
node_gen_logs -->|"store artifact"| node_gen_results
node_gen_memory -->|"store artifact"| node_gen_results
node_run_harness -.->|"orchestrate"| node_gen_blueprint
node_run_harness -.->|"smoke test"| node_ver_api

click node_gen_input "https://github.com/frenzymath/rethlas/blob/main/agents/generation/data/example.md"
click node_gen_codex "https://github.com/frenzymath/rethlas/blob/main/agents/generation/.codex/config.toml"
click node_gen_mcp "https://github.com/frenzymath/rethlas/blob/main/agents/generation/mcp/server.py"
click node_gen_skills "https://github.com/frenzymath/rethlas/blob/main/agents/generation/.agents/skills"
click node_ver_api "https://github.com/frenzymath/rethlas/blob/main/agents/verification/api/server.py"
click node_ver_mcp "https://github.com/frenzymath/rethlas/blob/main/agents/verification/mcp/server.py"
click node_ver_schema "https://github.com/frenzymath/rethlas/blob/main/agents/verification/schemas/verification_output.schema.json"
click node_ver_skills "https://github.com/frenzymath/rethlas/blob/main/agents/verification/.agents/skills"
click node_run_harness "https://github.com/frenzymath/rethlas/blob/main/agents/generation/tests/run_example.sh"

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_gen_input,node_gen_codex,node_gen_mcp,node_gen_skills,node_gen_results,node_gen_blueprint,node_gen_verified,node_gen_logs,node_gen_memory toneBlue
class node_ver_api,node_ver_mcp,node_ver_schema,node_ver_skills,node_ver_output toneAmber
class node_run_harness toneNeutral
```

## Components

### Generation

Draft proof creation, memory, and repair loop

- [Problem Markdown](https://github.com/frenzymath/rethlas/blob/main/agents/generation/data/example.md): input data · Markdown math problems consumed by generation · `agents/generation/data/example.md`
- [Codex Config](https://github.com/frenzymath/rethlas/blob/main/agents/generation/.codex/config.toml): agent config · Codex-managed generation runtime configuration · `agents/generation/.codex/config.toml`
- [MCP Server](https://github.com/frenzymath/rethlas/blob/main/agents/generation/mcp/server.py): tool server · Python tool layer for the generation agent · `agents/generation/mcp/server.py`
- [Reasoning Skills](https://github.com/frenzymath/rethlas/blob/main/agents/generation/.agents/skills): skill set · Modular proving and repair behaviors used by generation · `agents/generation/.agents/skills`
- **Proof Artifacts**: artifact output · Generated drafts, logs, memory, and verified outputs
- **Draft Blueprint**: proof artifact · Informal proof blueprint produced by generation
- **Verified Blueprint**: proof artifact · Terminal blueprint emitted after successful verification
- **Run Logs**: execution log · Trace of generation and repair attempts
- **Memory Store**: state artifact · Persistent reasoning state and reusable observations

### Verification

Structured proof checking and verdict service

- [HTTP API](https://github.com/frenzymath/rethlas/blob/main/agents/verification/api/server.py): service api · Local verification endpoint · `agents/verification/api/server.py`
- [MCP Server](https://github.com/frenzymath/rethlas/blob/main/agents/verification/mcp/server.py): tool server · Tool-facing verification entrypoint · `agents/verification/mcp/server.py`
- [Verdict Schema](https://github.com/frenzymath/rethlas/blob/main/agents/verification/schemas/verification_output.schema.json): contract schema · Structured output contract for verification results · `agents/verification/schemas/verification_output.schema.json`
- [Check Skills](https://github.com/frenzymath/rethlas/blob/main/agents/verification/.agents/skills): skill set · Verification behaviors for statement checking and reporting · `agents/verification/.agents/skills`
- **Verification Result**: structured verdict · Machine-actionable pass/fail and failure summary

### Other components

- [Example Run](https://github.com/frenzymath/rethlas/blob/main/agents/generation/tests/run_example.sh): integration script · End-to-end smoke test for the repository flow · `agents/generation/tests/run_example.sh`

## Connections

- Problem Markdown → MCP Server: read problem · Generation consumes the Markdown problem through its tool/runtime boundary
- Codex Config → MCP Server: configure · Codex configuration steers the generation runtime
- Reasoning Skills → MCP Server: guide reasoning · Skills provide the proving and repair behaviors used during generation
- MCP Server → Draft Blueprint: draft proof · Generation writes an informal proof blueprint
- MCP Server → Run Logs: record run · Execution traces are persisted for iterative reasoning
- MCP Server → Memory Store: persist memory · Reusable state is stored for later proof attempts
- Draft Blueprint → HTTP API: submit for check · Draft blueprint is sent to the verification service
- Draft Blueprint → MCP Server: tool check · Verification can also be consumed through MCP
- Check Skills → HTTP API: drive checks · Verification skills implement statement checking and synthesis
- Verdict Schema → HTTP API: shape verdict · The schema constrains the structure of verification output
- HTTP API → Verification Result: return result · HTTP API emits a structured verification verdict
- MCP Server → Verification Result: return result · MCP entrypoint exposes the same structured verdict
- Verification Result → MCP Server: feedback · Verification feedback returns to generation for repair
- MCP Server → Draft Blueprint: repair draft · Generation revises the blueprint based on verifier feedback
- Draft Blueprint → Verified Blueprint: accept if valid · A successful verification promotes the blueprint to verified output
- Draft Blueprint → Proof Artifacts: store artifact · Draft outputs are organized under the generation results area
- Verified Blueprint → Proof Artifacts: store artifact · Verified outputs are organized under the generation results area
- Run Logs → Proof Artifacts: store artifact · Run logs are persisted alongside other generation artifacts
- Memory Store → Proof Artifacts: store artifact · Persistent reasoning state is retained with run artifacts
- Example Run → Draft Blueprint: orchestrate · Integration harness exercises the full generation-to-verification loop
- Example Run → HTTP API: smoke test · Harness also checks the verification endpoint
