# Multi-Agent Pipeline Architecture in Understand Anything: How Distributed Agents Analyze Code

> Explore Understand Anything's multi-agent pipeline architecture. Discover how specialized agents collaborate to transform code into a knowledge graph for efficient analysis.

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

---

**Understand Anything uses a pipeline of specialized agents—including the Project Scanner, Language Detector, LLM Analyzer, and Graph Builder—that incrementally transform source code into a knowledge graph, with each agent writing intermediate results to enable modular, parallel processing.**

The Egonex-AI/Understand-Anything repository implements a sophisticated multi-agent pipeline architecture that breaks complex code analysis into discrete, specialized stages. Unlike monolithic static analysis tools, this system distributes work across multiple agents that operate on different data representations, enabling scalable, parallel processing of large codebases while maintaining clear separation of concerns.

## The Nine Specialized Agents

The multi-agent pipeline architecture in Understand Anything consists of nine sequential stages, each handled by a dedicated agent. Each agent performs a focused analysis step and persists its output to `.understand-anything/intermediate/`, allowing downstream agents to consume previous results without recomputation.

### 1. Project Scanner

Located in [`packages/core/src/ignore-filter.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/packages/core/src/ignore-filter.ts), the **Project Scanner** walks the file system and respects `.understandignore` patterns to produce a curated list of candidate files for analysis. This agent acts as the entry point, seeding the pipeline with absolute file paths.

### 2. Language Detector

The **Language Detector** in [`packages/core/src/languages/index.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/packages/core/src/languages/index.ts) identifies programming languages via file extensions and content heuristics. It registers the appropriate Tree-sitter parser for each file, ensuring language-specific analysis downstream.

### 3. Tree-Sitter Parser

Implemented in [`packages/core/src/plugins/tree-sitter-plugin.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/packages/core/src/plugins/tree-sitter-plugin.ts), this parser converts source code into concrete syntax trees (CSTs). It exposes language-specific concepts like functions, classes, and imports that serve as the raw material for semantic analysis.

### 4. LLM Analyzer

The **LLM Analyzer** in [`packages/core/src/analyzer/llm-analyzer.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/packages/core/src/analyzer/llm-analyzer.ts) sends syntax tree snippets to a language model, extracting high-level semantic concepts such as "API client" or "state machine" and generating embeddings. This agent bridges the gap between syntactic structure and semantic meaning.

### 5. Graph Builder

Found in [`packages/core/src/analyzer/graph-builder.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/packages/core/src/analyzer/graph-builder.ts), the **Graph Builder** consumes LLM-generated concepts to construct a unified knowledge graph. It creates nodes representing code entities and edges representing relationships like calls, imports, and inheritance, linking entities across files.

### 6. Layer Detector

The **Layer Detector** in [`packages/core/src/analyzer/layer-detector.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/packages/core/src/analyzer/layer-detector.ts) analyzes the knowledge graph using clustering algorithms to discover logical architectural layers (UI, data, domain, infrastructure). It annotates nodes with layer identifiers for architectural visualization.

### 7. Language Lesson

In [`packages/core/src/analyzer/language-lesson.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/packages/core/src/analyzer/language-lesson.ts), the **Language Lesson** agent maps language-specific constructs to the higher-level concepts discovered by the LLM. This alignment enables the dashboard to render language-agnostic views while preserving implementation details.

### 8. Tour Generator

The **Tour Generator** in [`packages/core/src/analyzer/tour-generator.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/packages/core/src/analyzer/tour-generator.ts) creates guided step-by-step walkthroughs of the graph. It transforms raw nodes and edges into user-friendly narratives, such as "Explore the data-layer API."

### 9. Dashboard UI

Finally, the **Dashboard UI** in [`packages/dashboard/src/App.tsx`](https://github.com/Egonex-AI/Understand-Anything/blob/main/packages/dashboard/src/App.tsx) consumes the processed graph, layers, and tours to render interactive visualizations. It exposes node details, graph views, and side panels that let users follow the generated tours.

## How Agents Collaborate Through Intermediate Storage

The collaboration mechanism relies on a shared intermediate storage system. Each agent writes its results to `.understand-anything/intermediate/` in a standardized format, enabling the following workflow:

1. The **Project Scanner** seeds the pipeline with absolute file paths.
2. The **Language Detector** and **Tree-Sitter Parser** process these files and output parsed ASTs.
3. The **LLM Analyzer** reads these trees and outputs semantic tags and embeddings.
4. The **Graph Builder** stitches these tags into a unified knowledge graph stored as [`knowledge-graph.json`](https://github.com/Egonex-AI/Understand-Anything/blob/main/knowledge-graph.json).
5. The **Layer Detector**, **Language Lesson**, and **Tour Generator** read this graph to produce layered views and guided tours.

This architecture provides **modularity, parallelism, and extensibility**. New agents can be inserted or swapped without modifying existing pipeline stages, and agents can run in parallel when dependencies permit.

## Running the Pipeline

You can invoke the complete multi-agent pipeline from the command line:

```bash
understand --full

```

This triggers the entire agent chain sequentially.

To inspect the generated knowledge graph after a run:

```typescript
import { readGraph } from '@understand-anything/core';

const graph = await readGraph('.understand-anything/knowledge-graph.json');
console.log(graph.nodes.length, 'nodes', graph.edges.length, 'edges');

```

For targeted analysis, invoke individual agents directly. For example, to run only the LLM Analyzer on a specific code snippet:

```typescript
import { analyzeWithLLM } from '@understand-anything/core/analyzer/llm-analyzer';

const result = await analyzeWithLLM(`function foo() { return 42; }`);
console.log(result.concepts);   // → ["pure function", "numeric literal"]

```

## Summary

- The **multi-agent pipeline architecture** in Understand Anything processes code through nine specialized agents, from initial file scanning to final visualization.
- Each agent writes intermediate results to `.understand-anything/intermediate/`, enabling efficient, incremental processing and parallel execution.
- Key components include the **LLM Analyzer** ([`llm-analyzer.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/llm-analyzer.ts)), **Graph Builder** ([`graph-builder.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/graph-builder.ts)), and **Layer Detector** ([`layer-detector.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/layer-detector.ts)), which transform raw syntax into structured knowledge graphs.
- The system supports both full pipeline execution via `understand --full` and selective single-agent invocation for targeted analysis.

## Frequently Asked Questions

### What is the multi-agent pipeline architecture in Understand Anything?

The multi-agent pipeline architecture is a distributed system where specialized agents handle distinct stages of code analysis—from file scanning and language detection to LLM-powered semantic extraction and knowledge graph construction. Each agent operates independently, consuming inputs from and writing outputs to shared intermediate storage, enabling modular and scalable codebase analysis.

### How do agents share data between stages?

Agents communicate through the filesystem by writing structured intermediate data to `.understand-anything/intermediate/`. For example, the Tree-sitter Parser writes AST representations that the LLM Analyzer subsequently reads, while the Graph Builder persists the final knowledge graph as JSON for the Layer Detector and Tour Generator to consume.

### Can I run individual agents without executing the full pipeline?

Yes. While `understand --full` executes the complete chain, you can import and invoke individual agents programmatically. For instance, import `analyzeWithLLM` from `@understand-anything/core/analyzer/llm-analyzer` to run semantic analysis on isolated code snippets, or use `readGraph` to inspect previously generated knowledge graphs without re-running the entire pipeline.

### Which agent is responsible for creating the knowledge graph?

The **Graph Builder**, implemented in [`packages/core/src/analyzer/graph-builder.ts`](https://github.com/Egonex-AI/Understand-Anything/blob/main/packages/core/src/analyzer/graph-builder.ts), constructs the knowledge graph by consuming semantic concepts and embeddings generated by the LLM Analyzer. It creates nodes for code entities and edges for relationships like function calls and imports, producing the [`knowledge-graph.json`](https://github.com/Egonex-AI/Understand-Anything/blob/main/knowledge-graph.json) file that subsequent agents use for layer detection and tour generation.