# How the Egonex-AI Multi-Agent Pipeline Functions Internally

> Explore the Egonex-AI multi-agent pipeline's internal workings. Discover how it converts codebases into knowledge graphs using declarative agents and deterministic scanning for queryable insights.

- Repository: [Egonex/Understand-Anything](https://github.com/Egonex-AI/Understand-Anything)
- Tags: internals
- Published: 2026-06-22

---

**The Egonex-AI multi-agent pipeline is a deterministic, multi-stage system that transforms raw codebases into queryable knowledge graphs through declarative agents, deterministic scanning scripts, and strict graph validation.**

The *Understand Anything* repository implements a fully-deterministic pipeline that converts source code into a rich knowledge graph. This Egonex-AI multi-agent pipeline orchestrates specialized agents—implemented as markdown recipes—to scan, analyze, and validate codebases before serving them to LLM-driven chat interfaces and visual dashboards.

## Phase 1: Deterministic Project Scanning and Import Extraction

The pipeline begins with two pure scripts that never invoke LLM inference. First, `scan-project.mjs` walks the repository using `git ls-files` when available, applies `.understandignore` rules, and classifies files while estimating complexity. Second, `extract-import-map.mjs` parses every source file with *tree-sitter* (via the web-tree-sitter WASM parser) to produce a deterministic `importMap` that records file-to-file dependencies.

These steps are orchestrated by the [project-scanner agent](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/agents/project-scanner.md), ensuring reproducible file listings and import relationships.

## Phase 2: Knowledge Graph Construction

The core `GraphBuilder` class consumes the file list, import map, and optional LLM-generated per-file summaries to construct the graph. Located in [`understand-anything-plugin/packages/core/src/analyzer/graph-builder.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/packages/core/src/analyzer/graph-builder.ts), this module creates:

- **File nodes** for every tracked source file
- **Function** and **class nodes** with "contains" edges linking them to parent files
- **Import edges** representing dependencies between files
- **Non-code nodes** for configs, documents, and services

The builder maintains a strict schema supporting 16 node types and 29 edge types.

## Phase 3: Structural Analysis and Layer Assignment

The [architecture-analyzer agent](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/agents/architecture-analyzer.md) generates the [`ua-arch-analyze.js`](https://github.com/Egonex-AI/Understand-Anything/blob/main/ua-arch-analyze.js) script, which groups files by directory and computes architectural metrics including fan-in, fan-out, and intra-group density. It detects patterns like deployment configurations and data pipelines, returning a JSON structure of "directoryGroups", "nodeTypeGroups", and "interGroupImports".

Using this analysis, the pipeline assigns every node to one of 3-10 logical layers (e.g., API, Service, Data, Infrastructure). Layer IDs are deterministic, following the pattern `layer:<kebab-case>`.

## Phase 4: Graph Validation and Final Assembly

Before output, the [graph-reviewer agent](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/agents/graph-reviewer.md) generates [`ua-graph-validate.js`](https://github.com/Egonex-AI/Understand-Anything/blob/main/ua-graph-validate.js) to enforce schema compliance. The validation script checks:

- Referential integrity between nodes and edges
- Layer coverage (every file-level node must belong to exactly one layer)
- Uniqueness constraints
- Quality warnings and critical errors

Critical issues abort the pipeline, while warnings are tolerated. Upon passing validation, the [assemble-reviewer agent](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/agents/assemble-reviewer.md) writes the final [`knowledge-graph.json`](https://github.com/Egonex-AI/Understand-Anything/blob/main/knowledge-graph.json) to `.understand-anything/intermediate/`.

## Phase 5: Chat Integration and Dashboard Rendering

At runtime, the `buildChatPrompt` function in [`understand-anything-plugin/src/understand-chat.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/src/understand-chat.ts) stitches together system instructions, formatted graph context from `formatContextForPrompt` (in [`context-builder.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/context-builder.ts)), and the user query. This produces a prompt ready for any LLM.

The browser-side dashboard consumes the graph via [`/file-content.json`](https://github.com/Egonex-AI/Understand-Anything/blob/main//file-content.json) endpoints, rendering a graph-first UI that overlays a code viewer when users click on nodes. The layout logic resides in [`packages/dashboard/src/utils/layout.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/packages/dashboard/src/utils/layout.ts).

## Key Architectural Principles

Several design decisions ensure reliability and reproducibility:

- **Determinism First**: Steps 1-2 rely solely on scripts, never LLM inference, guaranteeing identical outputs for identical inputs.
- **LLM Only for Narrative**: The only non-deterministic work involves reading manifests and READMEs to generate human-friendly project descriptions.
- **Separation of Concerns**: Each agent is a self-contained markdown "skill" declaring inputs, outputs, and execution scripts. The orchestrator passes filesystem paths via `.understand-anything/tmp`.
- **Extensible Language Support**: The `LanguageRegistry` in [`packages/core/src/languages/language-registry.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/packages/core/src/languages/language-registry.ts) maps file extensions to languages, enabling new language support by extending the registry.

## Running the Pipeline

To execute the full analysis on a repository:

```bash

# Install dependencies

pnpm install

# Build core and skill packages

pnpm --filter @understand-anything/core build
pnpm --filter @understand-anything/skill build

# Run full analysis

pnpm --filter @understand-anything/skill run /understand --full

```

To generate a chat prompt programmatically:

```typescript
import { buildChatPrompt } from "./understand-anything-plugin/src/understand-chat.js";
import type { KnowledgeGraph } from "@understand-anything/core";

const userQuestion = "How does the authentication flow work?";
const prompt = buildChatPrompt(graph, userQuestion);
// Send prompt to your LLM provider

```

To extend language support:

```typescript
import { LanguageRegistry } from "./understand-anything-plugin/packages/core/src/languages/language-registry.js";

LanguageRegistry.register({
  id: "haskell",
  extensions: [".hs", ".lhs"]
});

```

## Summary

- The Egonex-AI multi-agent pipeline uses deterministic scripts for scanning and import extraction, ensuring reproducible knowledge graphs.
- The `GraphBuilder` class in [`graph-builder.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/graph-builder.ts) constructs the graph with 16 node types and 29 edge types, while the architecture-analyzer assigns logical layers.
- Strict validation via the graph-reviewer agent enforces schema compliance and layer coverage before final assembly.
- Runtime chat functionality uses `buildChatPrompt` and `formatContextForPrompt` to contextualize the graph for LLM queries.
- The system is modular and extensible, with language support managed through the `LanguageRegistry`.

## Frequently Asked Questions

### What makes the Egonex-AI multi-agent pipeline deterministic?

The pipeline guarantees determinism by using pure scripts (`scan-project.mjs`, `extract-import-map.mjs`) for the initial scanning phases. These scripts never invoke LLM inference, relying instead on filesystem operations and tree-sitter parsing. Only the narrative generation steps (project descriptions from READMEs) use LLMs, ensuring that the core file structure and import relationships remain identical across runs.

### How does the pipeline handle different programming languages?

Language support is managed through the `LanguageRegistry` located in [`understand-anything-plugin/packages/core/src/languages/language-registry.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/packages/core/src/languages/language-registry.ts). This registry maps file extensions to language identifiers, which the `GraphBuilder` uses during node creation. Adding support for a new language requires registering its extensions in this registry, enabling the tree-sitter parser and graph builder to process the new file types immediately.

### What happens if the graph validation fails?

The graph-reviewer agent generates a validation script ([`ua-graph-validate.js`](https://github.com/Egonex-AI/Understand-Anything/blob/main/ua-graph-validate.js)) that checks schema compliance, referential integrity, and layer coverage. Critical validation errors abort the pipeline immediately, preventing corrupted graphs from reaching downstream consumers. Warnings are logged but do not stop execution, allowing the pipeline to complete with noted quality issues.

### How is the knowledge graph used at runtime?

At runtime, the `buildChatPrompt` function in [`understand-chat.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-chat.ts) retrieves the stored knowledge graph and formats it via `formatContextForPrompt` in [`context-builder.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/context-builder.ts). This combines the graph structure with the user's specific question to create a contextualized prompt for the LLM. Simultaneously, the dashboard frontend loads the graph via API endpoints to render an interactive visualization of the codebase architecture.