# digibhatia/tracing-debugging architecture

> Architecture diagram of the GitHub repository digibhatia/tracing-debugging, 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/digibhatia/tracing-debugging
- Repository: https://github.com/digibhatia/tracing-debugging

## Overview

Nidan is a trace-driven debugging lab for a document-grounded financial agent. Users submit questions or session chats through the API, which runs an agent turn and returns an answer and trace; additional endpoints delegate a fraud check, replay or diff runs, grade outcome and tool trajectory, and seed or reveal blind incidents. Document ingestion and retrieval support policy answers, while OpenTelemetry exports traces for diagnosis. Several connections rely on README descriptions or module references rather than a complete app excerpt; those uncertain runtime links are dashed.

Main entry points: [`app.py`](https://github.com/digibhatia/tracing-debugging/blob/main/app.py) (HTTP API), [`tools.py`](https://github.com/digibhatia/tracing-debugging/blob/main/tools.py) (Agent tools), [`vectorstore.py`](https://github.com/digibhatia/tracing-debugging/blob/main/vectorstore.py) (Vector retrieval), [`llm_provider.py`](https://github.com/digibhatia/tracing-debugging/blob/main/llm_provider.py) (LLM provider)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and orchestration"]
  node_api["HTTP API<br/>[app.py]"]
  node_session[("Session memory<br/>[memory_store.py]")]
end

subgraph group_agent["Agent execution"]
  node_agent_turn["Agent turn<br/>[app.py]"]
  node_model["LLM provider<br/>[llm_provider.py]"]
  node_tools["Agent tools<br/>[tools.py]"]
  node_delegate["Fraud sub-agent<br/>[delegation.py]"]
end

subgraph group_knowledge["Policy knowledge"]
  node_documents["Policy documents"]
  node_loaders["Format loaders<br/>[loaders.py]"]
  node_chunking["Document chunking<br/>[chunking.py]"]
  node_vectorstore[("Vector retrieval<br/>[vectorstore.py]")]
  node_context["Context packing<br/>[context.py]"]
  node_build_index["Index builder"]
end

subgraph group_diagnosis["Debugging workflows"]
  node_replay["Replay and diff<br/>[replay.py]"]
  node_grading["Trajectory grading<br/>[trajectory_eval.py]"]
  node_incidents["Blind incidents<br/>[incidents.py]"]
end

subgraph group_telemetry["Trace instrumentation"]
  node_otel["Trace setup<br/>[otel_setup.py]"]
  node_conventions["GenAI conventions"]
  node_pii["PII redaction<br/>[pii.py]"]
end

node_user(("Engineer or user"))
node_openai{{"OpenAI API"}}
node_collector{{"OTel Collector"}}
node_jaeger{{"Jaeger"}}

node_user -->|"submits requests"| node_api
node_api -->|"runs turns"| node_agent_turn
node_api -->|"reads and updates"| node_session
node_api -->|"routes delegation"| node_delegate
node_api -->|"runs replay and diff"| node_replay
node_api -->|"grades runs"| node_grading
node_api -->|"manages incidents"| node_incidents
node_agent_turn -.->|"requests completions"| node_model
node_agent_turn -.->|"dispatches tools"| node_tools
node_delegate -->|"requests completions"| node_model
node_delegate -->|"executes tool calls"| node_tools
node_model -->|"calls chat API"| node_openai
node_tools -->|"queries policies"| node_vectorstore
node_tools -->|"packs retrieved text"| node_context
node_build_index -->|"builds collection"| node_vectorstore
node_vectorstore -->|"loads documents"| node_loaders
node_vectorstore -->|"chunks text"| node_chunking
node_vectorstore -->|"redacts text"| node_pii
node_documents -.->|"provides source files"| node_loaders
node_replay -->|"runs completions"| node_model
node_replay -->|"executes tool calls"| node_tools
node_api -->|"evaluates answer and tools"| node_grading
node_model -->|"creates spans"| node_otel
node_tools -->|"creates spans"| node_otel
node_conventions -->|"redacts span prompts"| node_pii
node_otel -->|"exports traces"| node_collector
node_collector -.->|"forwards traces"| node_jaeger

click node_api "https://github.com/digibhatia/tracing-debugging/blob/main/app.py"
click node_session "https://github.com/digibhatia/tracing-debugging/blob/main/memory_store.py"
click node_agent_turn "https://github.com/digibhatia/tracing-debugging/blob/main/app.py"
click node_model "https://github.com/digibhatia/tracing-debugging/blob/main/llm_provider.py"
click node_tools "https://github.com/digibhatia/tracing-debugging/blob/main/tools.py"
click node_delegate "https://github.com/digibhatia/tracing-debugging/blob/main/delegation.py"
click node_documents "https://github.com/digibhatia/tracing-debugging/tree/main/documents"
click node_loaders "https://github.com/digibhatia/tracing-debugging/blob/main/loaders.py"
click node_chunking "https://github.com/digibhatia/tracing-debugging/blob/main/chunking.py"
click node_vectorstore "https://github.com/digibhatia/tracing-debugging/blob/main/vectorstore.py"
click node_context "https://github.com/digibhatia/tracing-debugging/blob/main/context.py"
click node_build_index "https://github.com/digibhatia/tracing-debugging/blob/main/build_vectorstore.py"
click node_replay "https://github.com/digibhatia/tracing-debugging/blob/main/replay.py"
click node_grading "https://github.com/digibhatia/tracing-debugging/blob/main/trajectory_eval.py"
click node_incidents "https://github.com/digibhatia/tracing-debugging/blob/main/incidents.py"
click node_otel "https://github.com/digibhatia/tracing-debugging/blob/main/otel_setup.py"
click node_conventions "https://github.com/digibhatia/tracing-debugging/blob/main/genai_conventions.py"
click node_pii "https://github.com/digibhatia/tracing-debugging/blob/main/pii.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_api,node_session,node_user toneBlue
class node_agent_turn,node_model,node_tools,node_delegate toneAmber
class node_documents,node_loaders,node_chunking,node_vectorstore,node_context,node_build_index,node_openai toneMint
class node_replay,node_grading,node_incidents toneRose
class node_otel,node_conventions,node_pii,node_collector,node_jaeger toneIndigo
```

## Components

### API and orchestration

- [HTTP API](https://github.com/digibhatia/tracing-debugging/blob/main/app.py): `app.py`
- [Session memory](https://github.com/digibhatia/tracing-debugging/blob/main/memory_store.py): `memory_store.py`

### Agent execution

- [Agent turn](https://github.com/digibhatia/tracing-debugging/blob/main/app.py): `app.py`
- [LLM provider](https://github.com/digibhatia/tracing-debugging/blob/main/llm_provider.py): `llm_provider.py`
- [Agent tools](https://github.com/digibhatia/tracing-debugging/blob/main/tools.py): `tools.py`
- [Fraud sub-agent](https://github.com/digibhatia/tracing-debugging/blob/main/delegation.py): `delegation.py`

### Policy knowledge

- [Policy documents](https://github.com/digibhatia/tracing-debugging/tree/main/documents): `documents`
- [Format loaders](https://github.com/digibhatia/tracing-debugging/blob/main/loaders.py): `loaders.py`
- [Document chunking](https://github.com/digibhatia/tracing-debugging/blob/main/chunking.py): `chunking.py`
- [Vector retrieval](https://github.com/digibhatia/tracing-debugging/blob/main/vectorstore.py): `vectorstore.py`
- [Context packing](https://github.com/digibhatia/tracing-debugging/blob/main/context.py): `context.py`
- [Index builder](https://github.com/digibhatia/tracing-debugging/blob/main/build_vectorstore.py): `build_vectorstore.py`

### Debugging workflows

- [Replay and diff](https://github.com/digibhatia/tracing-debugging/blob/main/replay.py): `replay.py`
- [Trajectory grading](https://github.com/digibhatia/tracing-debugging/blob/main/trajectory_eval.py): `trajectory_eval.py`
- [Blind incidents](https://github.com/digibhatia/tracing-debugging/blob/main/incidents.py): `incidents.py`

### Trace instrumentation

- [Trace setup](https://github.com/digibhatia/tracing-debugging/blob/main/otel_setup.py): `otel_setup.py`
- [GenAI conventions](https://github.com/digibhatia/tracing-debugging/blob/main/genai_conventions.py): `genai_conventions.py`
- [PII redaction](https://github.com/digibhatia/tracing-debugging/blob/main/pii.py): `pii.py`

### Other components

- **Engineer or user**
- **OpenAI API**
- **OTel Collector**
- **Jaeger**

## Connections

- Engineer or user → HTTP API: submits requests (evidence: `README.md`)
- HTTP API → Agent turn: runs turns (evidence: `README.md`)
- HTTP API → Session memory: reads and updates (evidence: `app.py`)
- HTTP API → Fraud sub-agent: routes delegation (evidence: `app.py`)
- HTTP API → Replay and diff: runs replay and diff (evidence: `app.py`)
- HTTP API → Trajectory grading: grades runs (evidence: `app.py`)
- HTTP API → Blind incidents: manages incidents (evidence: `app.py`)
- Agent turn → LLM provider: requests completions (evidence: `app.py`)
- Agent turn → Agent tools: dispatches tools (evidence: `app.py`)
- Fraud sub-agent → LLM provider: requests completions (evidence: `delegation.py`)
- Fraud sub-agent → Agent tools: executes tool calls (evidence: `delegation.py`)
- LLM provider → OpenAI API: calls chat API (evidence: `llm_provider.py`)
- Agent tools → Vector retrieval: queries policies (evidence: `tools.py`)
- Agent tools → Context packing: packs retrieved text (evidence: `tools.py`)
- Index builder → Vector retrieval: builds collection (evidence: `build_vectorstore.py`)
- Vector retrieval → Format loaders: loads documents (evidence: `vectorstore.py`)
- Vector retrieval → Document chunking: chunks text (evidence: `vectorstore.py`)
- Vector retrieval → PII redaction: redacts text (evidence: `vectorstore.py`)
- Policy documents → Format loaders: provides source files
- Replay and diff → LLM provider: runs completions (evidence: `replay.py`)
- Replay and diff → Agent tools: executes tool calls (evidence: `replay.py`)
- HTTP API → Trajectory grading: evaluates answer and tools (evidence: `app.py`)
- LLM provider → Trace setup: creates spans (evidence: `llm_provider.py`)
- Agent tools → Trace setup: creates spans (evidence: `tools.py`)
- GenAI conventions → PII redaction: redacts span prompts (evidence: `genai_conventions.py`)
- Trace setup → OTel Collector: exports traces (evidence: `README.md`)
- OTel Collector → Jaeger: forwards traces (evidence: `README.md`)
