# zhk-lab/ebg architecture

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

- Interactive diagram: https://gitdiagram.com/zhk-lab/ebg
- Repository: https://github.com/zhk-lab/ebg

## Overview

EBG is a training-free evidence-grounded oversight method: it turns repository or trace evidence into behavior, scope, and relation structures, then supports task-oriented review and benchmark prediction. The interactive Repo workflow is driven by AgentLoop; FeedbackTrace also has a one-shot TraceReview path. The repository additionally contains an independent Codex review harness. The graph preserves these major product branches; edges for unsampled implementations are included only when documented, and marked dashed when their wiring is not evidenced in the excerpts or index.

Main entry points: [`src/agentloop/runner.py`](https://github.com/zhk-lab/ebg/blob/main/src/agentloop/runner.py) (Interactive Agent), [`src/tracereview/runner.py`](https://github.com/zhk-lab/ebg/blob/main/src/tracereview/runner.py) (TraceReview), [`harness/src/codex_harness/application/service.py`](https://github.com/zhk-lab/ebg/blob/main/harness/src/codex_harness/application/service.py) (Evidence Service), [`src/ebg/behavior_atomization.py`](https://github.com/zhk-lab/ebg/blob/main/src/ebg/behavior_atomization.py) (Behavior Atomization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ebg["Evidence Graph"]
  node_evidence_intake["Evidence Intake<br/>[evidence_intake.py]"]
  node_atomization["Behavior Atomization"]
  node_directory["Behavior Directory"]
  node_relations["Relation Linking"]
  node_retrieval["Graph Retrieval"]
  node_graph_model["Graph Model<br/>[model.py]"]
  node_repo_graph["RepoGraph Construction<br/>[construction.py]"]
end

subgraph group_agent["AgentLoop"]
  node_agent_config["Benchmark Config<br/>[model.py]"]
  node_agent_runner["Interactive Agent<br/>[runner.py]"]
  node_agent_context["Context Builder<br/>[context.py]"]
  node_provider["Model Provider<br/>[provider.py]"]
  node_run_store[("Run Persistence<br/>[storage.py]")]
end

subgraph group_review["Review And Evaluation"]
  node_contracts["Prediction Contracts<br/>[contracts.py]"]
  node_trace_review["TraceReview<br/>[runner.py]"]
  node_source_review["SilentSwap Source Review"]
  node_judges["Benchmark Judges"]
end

subgraph group_harness["Codex Harness"]
  node_harness_service["Evidence Service<br/>[service.py]"]
  node_harness_repository["Repository Capture<br/>[repository.py]"]
  node_harness_matching["Requirement Matching<br/>[matching.py]"]
  node_harness_storage[("Task Storage<br/>[storage.py]")]
  node_harness_ebg["Harness EBG"]
end

node_user(("Monitor"))

node_user -.->|"requests audit"| node_agent_runner
node_agent_runner -->|"loads config"| node_agent_config
node_agent_runner -->|"builds context"| node_agent_context
node_agent_runner -->|"calls model"| node_provider
node_agent_runner -->|"persists runs"| node_run_store
node_agent_runner -->|"validates output"| node_contracts
node_evidence_intake -->|"uses types"| node_graph_model
node_atomization -->|"consumes evidence"| node_evidence_intake
node_atomization -->|"uses types"| node_graph_model
node_atomization -.->|"feeds behaviors"| node_directory
node_directory -.->|"provides behavior context"| node_relations
node_relations -.->|"supplies relations"| node_retrieval
node_repo_graph -->|"uses graph types"| node_graph_model
node_trace_review -->|"uses context"| node_agent_context
node_trace_review -->|"calls model"| node_provider
node_trace_review -->|"persists runs"| node_run_store
node_trace_review -->|"validates prediction"| node_contracts
node_source_review -->|"uses provider"| node_provider
node_source_review -->|"reads history"| node_run_store
node_contracts -.->|"defines prediction contracts"| node_judges
node_harness_repository -->|"builds EBG stages"| node_harness_ebg
node_harness_matching -->|"uses behavior modules"| node_harness_ebg
node_harness_service -->|"matches requirements"| node_harness_matching
node_harness_service -->|"requests repository view"| node_harness_repository
node_harness_service -->|"reads task state"| node_harness_storage
node_user -.->|"requests review"| node_harness_service

click node_evidence_intake "https://github.com/zhk-lab/ebg/blob/main/src/ebg/evidence_intake.py"
click node_atomization "https://github.com/zhk-lab/ebg/blob/main/src/ebg/behavior_atomization.py"
click node_directory "https://github.com/zhk-lab/ebg/blob/main/src/ebg/behavior_directory.py"
click node_relations "https://github.com/zhk-lab/ebg/blob/main/src/ebg/relation_linking.py"
click node_retrieval "https://github.com/zhk-lab/ebg/blob/main/src/ebg/local_graph_retrieval.py"
click node_graph_model "https://github.com/zhk-lab/ebg/blob/main/src/ebg/core/model.py"
click node_repo_graph "https://github.com/zhk-lab/ebg/blob/main/src/repograph/construction.py"
click node_agent_config "https://github.com/zhk-lab/ebg/blob/main/src/agentloop/benchmark_configs/model.py"
click node_agent_runner "https://github.com/zhk-lab/ebg/blob/main/src/agentloop/runner.py"
click node_agent_context "https://github.com/zhk-lab/ebg/blob/main/src/agentloop/context.py"
click node_provider "https://github.com/zhk-lab/ebg/blob/main/src/agentloop/provider.py"
click node_run_store "https://github.com/zhk-lab/ebg/blob/main/src/agentloop/storage.py"
click node_contracts "https://github.com/zhk-lab/ebg/blob/main/src/evaluation_core/contracts.py"
click node_trace_review "https://github.com/zhk-lab/ebg/blob/main/src/tracereview/runner.py"
click node_source_review "https://github.com/zhk-lab/ebg/blob/main/src/agentloop/silentswap_source_review.py"
click node_judges "https://github.com/zhk-lab/ebg/tree/main/evaluation"
click node_harness_service "https://github.com/zhk-lab/ebg/blob/main/harness/src/codex_harness/application/service.py"
click node_harness_repository "https://github.com/zhk-lab/ebg/blob/main/harness/src/codex_harness/application/repository.py"
click node_harness_matching "https://github.com/zhk-lab/ebg/blob/main/harness/src/codex_harness/application/matching.py"
click node_harness_storage "https://github.com/zhk-lab/ebg/blob/main/harness/src/codex_harness/application/storage.py"
click node_harness_ebg "https://github.com/zhk-lab/ebg/tree/main/harness/src/codex_harness/ebg"

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_evidence_intake,node_atomization,node_directory,node_relations,node_retrieval,node_graph_model,node_repo_graph toneBlue
class node_agent_config,node_agent_runner,node_agent_context,node_provider,node_run_store toneAmber
class node_contracts,node_trace_review,node_source_review,node_judges toneMint
class node_harness_service,node_harness_repository,node_harness_matching,node_harness_storage,node_harness_ebg toneRose
class node_user toneIndigo
```

## Components

### Evidence Graph

- [Evidence Intake](https://github.com/zhk-lab/ebg/blob/main/src/ebg/evidence_intake.py): `src/ebg/evidence_intake.py`
- [Behavior Atomization](https://github.com/zhk-lab/ebg/blob/main/src/ebg/behavior_atomization.py): `src/ebg/behavior_atomization.py`
- [Behavior Directory](https://github.com/zhk-lab/ebg/blob/main/src/ebg/behavior_directory.py): `src/ebg/behavior_directory.py`
- [Relation Linking](https://github.com/zhk-lab/ebg/blob/main/src/ebg/relation_linking.py): `src/ebg/relation_linking.py`
- [Graph Retrieval](https://github.com/zhk-lab/ebg/blob/main/src/ebg/local_graph_retrieval.py): `src/ebg/local_graph_retrieval.py`
- [Graph Model](https://github.com/zhk-lab/ebg/blob/main/src/ebg/core/model.py): `src/ebg/core/model.py`
- [RepoGraph Construction](https://github.com/zhk-lab/ebg/blob/main/src/repograph/construction.py): `src/repograph/construction.py`

### AgentLoop

- [Benchmark Config](https://github.com/zhk-lab/ebg/blob/main/src/agentloop/benchmark_configs/model.py): `src/agentloop/benchmark_configs/model.py`
- [Interactive Agent](https://github.com/zhk-lab/ebg/blob/main/src/agentloop/runner.py): `src/agentloop/runner.py`
- [Context Builder](https://github.com/zhk-lab/ebg/blob/main/src/agentloop/context.py): `src/agentloop/context.py`
- [Model Provider](https://github.com/zhk-lab/ebg/blob/main/src/agentloop/provider.py): `src/agentloop/provider.py`
- [Run Persistence](https://github.com/zhk-lab/ebg/blob/main/src/agentloop/storage.py): `src/agentloop/storage.py`

### Review And Evaluation

- [Prediction Contracts](https://github.com/zhk-lab/ebg/blob/main/src/evaluation_core/contracts.py): `src/evaluation_core/contracts.py`
- [TraceReview](https://github.com/zhk-lab/ebg/blob/main/src/tracereview/runner.py): `src/tracereview/runner.py`
- [SilentSwap Source Review](https://github.com/zhk-lab/ebg/blob/main/src/agentloop/silentswap_source_review.py): `src/agentloop/silentswap_source_review.py`
- [Benchmark Judges](https://github.com/zhk-lab/ebg/tree/main/evaluation): `evaluation`

### Codex Harness

- [Evidence Service](https://github.com/zhk-lab/ebg/blob/main/harness/src/codex_harness/application/service.py): `harness/src/codex_harness/application/service.py`
- [Repository Capture](https://github.com/zhk-lab/ebg/blob/main/harness/src/codex_harness/application/repository.py): `harness/src/codex_harness/application/repository.py`
- [Requirement Matching](https://github.com/zhk-lab/ebg/blob/main/harness/src/codex_harness/application/matching.py): `harness/src/codex_harness/application/matching.py`
- [Task Storage](https://github.com/zhk-lab/ebg/blob/main/harness/src/codex_harness/application/storage.py): `harness/src/codex_harness/application/storage.py`
- [Harness EBG](https://github.com/zhk-lab/ebg/tree/main/harness/src/codex_harness/ebg): `harness/src/codex_harness/ebg`

### Other components

- **Monitor**

## Connections

- Monitor → Interactive Agent: requests audit
- Interactive Agent → Benchmark Config: loads config (evidence: `src/agentloop/benchmark_configs/model.py`)
- Interactive Agent → Context Builder: builds context
- Interactive Agent → Model Provider: calls model
- Interactive Agent → Run Persistence: persists runs
- Interactive Agent → Prediction Contracts: validates output
- Evidence Intake → Graph Model: uses types (evidence: `src/ebg/evidence_intake.py`)
- Behavior Atomization → Evidence Intake: consumes evidence (evidence: `src/ebg/behavior_atomization.py`)
- Behavior Atomization → Graph Model: uses types (evidence: `src/ebg/behavior_atomization.py`)
- Behavior Atomization → Behavior Directory: feeds behaviors
- Behavior Directory → Relation Linking: provides behavior context
- Relation Linking → Graph Retrieval: supplies relations
- RepoGraph Construction → Graph Model: uses graph types (evidence: `src/repograph/construction.py`)
- TraceReview → Context Builder: uses context (evidence: `src/tracereview/runner.py`)
- TraceReview → Model Provider: calls model (evidence: `src/tracereview/runner.py`)
- TraceReview → Run Persistence: persists runs (evidence: `src/tracereview/runner.py`)
- TraceReview → Prediction Contracts: validates prediction (evidence: `src/tracereview/runner.py`)
- SilentSwap Source Review → Model Provider: uses provider (evidence: `src/agentloop/silentswap_source_review.py`)
- SilentSwap Source Review → Run Persistence: reads history (evidence: `src/agentloop/silentswap_source_review.py`)
- Prediction Contracts → Benchmark Judges: defines prediction contracts
- Repository Capture → Harness EBG: builds EBG stages (evidence: `harness/src/codex_harness/application/repository.py`)
- Requirement Matching → Harness EBG: uses behavior modules (evidence: `harness/src/codex_harness/application/matching.py`)
- Evidence Service → Requirement Matching: matches requirements (evidence: `harness/src/codex_harness/application/service.py`)
- Evidence Service → Repository Capture: requests repository view (evidence: `harness/src/codex_harness/application/service.py`)
- Evidence Service → Task Storage: reads task state (evidence: `harness/src/codex_harness/application/service.py`)
- Monitor → Evidence Service: requests review
