# Where Are the Core Files for the LangGraph Architecture Located in OpenMAIC?

> Discover where LangGraph architecture files reside in OpenMAIC. Find the main entry point director-graph.ts within the lib/orchestration/ directory and understand its role in state machine construction.

- Repository: [MAIC/OpenMAIC](https://github.com/THU-MAIC/OpenMAIC)
- Tags: internals
- Published: 2026-09-03

---

**The core LangGraph architecture files in OpenMAIC are located in the `lib/orchestration/` directory, with [`director-graph.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/director-graph.ts) serving as the main entry point that constructs and runs the state machine.**

OpenMAIC implements its multi-agent orchestration layer using the **LangGraph** library from LangChain. According to the THU-MAIC/OpenMAIC source code, all components that build, configure, and execute the LangGraph state machine reside within a single package. This guide maps out each core file, explains its role in the architecture, and provides runnable code examples showing how the pieces fit together.

## The `lib/orchestration/` Package Structure

Every file essential to OpenMAIC's LangGraph implementation lives under **`lib/orchestration/`**. This design centralizes the orchestration logic, making it straightforward to locate and modify the graph behavior.

| File | Role in the LangGraph Architecture |
|------|------------------------------------|
| [`director-graph.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/director-graph.ts) | Defines the **Director Graph**—a `StateGraph` that coordinates turn-taking between agents and drives the overall workflow |
| [`ai-sdk-adapter.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/ai-sdk-adapter.ts) | Wraps any AI SDK language model for use as a LangGraph node; implements the required `BaseChatModel` interface |
| [`stateless-generate.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/stateless-generate.ts) | Provides stateless generation with **custom streaming mode** for real-time content delivery |
| [`prompt-builder.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/prompt-builder.ts) | Assembles prompts passed to agents inside LangGraph nodes |
| [`director-prompt.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/director-prompt.ts) | Stores the system-level prompt template injected into each agent's context |
| [`types.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/types.ts) | Central TypeScript typings for state definitions, event shapes, and configuration objects |
| [`tool-schemas.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/tool-schemas.ts) | Defines JSON schemas for tools that agents invoke via LangGraph |

## Core File Deep Dive

### [`director-graph.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/director-graph.ts) — The LangGraph Entry Point

The **[`director-graph.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/director-graph.ts)** file is the heart of OpenMAIC's LangGraph architecture. It constructs a `StateGraph`, registers agent nodes, and compiles the runnable graph. In [`lib/orchestration/director-graph.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/lib/orchestration/director-graph.ts), the graph is built by:

- Instantiating `StateGraph` with a state schema (defined in [`types.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/types.ts))
- Adding nodes for each agent using `graph.addNode()`
- Configuring custom streaming via `setStreamMode()`
- Compiling the graph with `graph.compile()` for execution

This file is where the multi-agent orchestration logic lives—determining which agent runs when and how state flows between them.

### [`ai-sdk-adapter.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/ai-sdk-adapter.ts) — Model Integration Layer

The **`AISdkLangGraphAdapter`** class in [`lib/orchestration/ai-sdk-adapter.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/lib/orchestration/ai-sdk-adapter.ts) bridges any AI SDK language model into the LangGraph ecosystem. It implements the `BaseChatModel` interface expected by LangGraph nodes, allowing OpenMAIC to plug in diverse model providers without changing the graph structure.

### [`stateless-generate.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/stateless-generate.ts) — Streaming Implementation

For real-time response generation, [`stateless-generate.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/stateless-generate.ts) leverages LangGraph's **custom stream mode**. This file implements a stateless generation routine where each token or completion event streams directly to the client. The streaming mode is configured in [`director-graph.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/director-graph.ts) and executed here for on-the-fly content creation.

### [`types.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/types.ts) — Type Safety Foundation

All state definitions, event shapes, and configuration interfaces are centralized in [`lib/orchestration/types.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/lib/orchestration/types.ts). This ensures type safety across the entire LangGraph architecture, from state transitions in [`director-graph.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/director-graph.ts) to tool invocations in [`tool-schemas.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/tool-schemas.ts).

## Working with the LangGraph Files

### Creating a Director Graph

Below is a minimal example showing how [`director-graph.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/director-graph.ts) constructs a LangGraph state machine using components from the `lib/orchestration/` package:

```typescript
import { StateGraph } from '@langchain/langgraph';
import { AISdkLangGraphAdapter } from './ai-sdk-adapter';
import { buildPrompt } from './prompt-builder';
import { LangGraphRunnableConfig } from '@langchain/langgraph';

export async function createDirectorGraph(state: {
  languageModel: any;
  thinkingConfig?: any;
}) {
  const graph = new StateGraph({
    // State schema imported from lib/orchestration/types.ts
    schema: {/* ...state schema... */},
  });

  // Register an agent node with the AI SDK adapter
  graph.addNode('assistant', async (ctx, input) => {
    const adapter = new AISdkLangGraphAdapter(
      state.languageModel,
      state.thinkingConfig ?? undefined,
    );
    const prompt = buildPrompt(input);
    return adapter.invoke(prompt);
  });

  // Enable custom streaming as implemented in stateless-generate.ts
  graph.setStreamMode(async (node, event) => {
    // Push StatelessEvent to the client
    // Streaming logic here...
  });

  return graph.compile();
}

```

Key points from this implementation:

- **`StateGraph`** instantiation begins the graph definition
- **`AISdkLangGraphAdapter`** wraps the underlying language model
- **`buildPrompt()`** from [`prompt-builder.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/prompt-builder.ts) assembles agent inputs
- **`setStreamMode()`** enables the streaming behavior defined in [`stateless-generate.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/stateless-generate.ts)

### Running the Graph with Streaming

This example demonstrates the execution pattern used throughout OpenMAIC:

```typescript
import { createDirectorGraph } from './director-graph';

async function runOrchestration() {
  const graph = await createDirectorGraph({
    languageModel: myModel,
    thinkingConfig: { temperature: 0.7 },
  });

  const result = await graph.stream({
    input: { userMessage: 'Explain quantum entanglement in plain language.' },
  });

  for await (const event of result) {
    // Each event corresponds to a LangGraph StatelessEvent
    console.log(event); // Streamed to UI in real-time
  }
}

```

The streaming loop mirrors the implementation in [`stateless-generate.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/stateless-generate.ts), where events flow continuously to the front-end.

### Adding Tool Schemas for Agent Use

Tools are registered using schemas from [`tool-schemas.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/tool-schemas.ts):

```typescript
import { toolSchemas } from './tool-schemas';

graph.addTool({
  name: 'lookup_wikipedia',
  description: 'Search Wikipedia for a short summary.',
  schema: toolSchemas.lookupWikipedia, // Defined in tool-schemas.ts
  execute: async (args) => {
    const summary = await fetchWikipedia(args.query);
    return summary;
  },
});

```

The **[`tool-schemas.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/tool-schemas.ts)** file centralizes all JSON schemas, ensuring agents receive properly structured tool definitions.

## File Interdependencies

Understanding how the core files interact clarifies the LangGraph architecture:

1. **[`types.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/types.ts)** provides the foundation—state and event types used by all other files
2. **[`director-prompt.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/director-prompt.ts)** and **[`prompt-builder.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/prompt-builder.ts)** assemble the prompts fed into nodes
3. **[`ai-sdk-adapter.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/ai-sdk-adapter.ts)** enables any model to function as a LangGraph node
4. **[`director-graph.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/director-graph.ts)** orchestrates these components into a compiled `StateGraph`
5. **[`stateless-generate.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/stateless-generate.ts)** executes specialized streaming workflows using the same graph infrastructure
6. **[`tool-schemas.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/tool-schemas.ts)** extends agent capabilities with structured tool definitions

## Summary

- **Core location**: All LangGraph architecture files reside in **`lib/orchestration/`** in the OpenMAIC repository
- **Primary entry point**: [`director-graph.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/director-graph.ts) constructs and compiles the multi-agent `StateGraph`
- **Model integration**: [`ai-sdk-adapter.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/ai-sdk-adapter.ts) adapts any AI SDK model for LangGraph node usage
- **Streaming support**: [`stateless-generate.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/stateless-generate.ts) implements custom streaming mode for real-time responses
- **Type safety**: [`types.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/types.ts) centralizes all TypeScript definitions for the orchestration layer
- **Tool capabilities**: [`tool-schemas.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/tool-schemas.ts) defines agent-invokable tools with JSON schemas

## Frequently Asked Questions

### What is the main file for LangGraph orchestration in OpenMAIC?

The main file is **[`lib/orchestration/director-graph.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/lib/orchestration/director-graph.ts)**. It defines the Director Graph—a `StateGraph` that coordinates multiple agents, manages state transitions, and compiles the runnable workflow. This is the first file to examine when modifying multi-agent behavior.

### How does OpenMAIC connect different language models to LangGraph?

OpenMAIC uses **[`lib/orchestration/ai-sdk-adapter.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/lib/orchestration/ai-sdk-adapter.ts)**. The `AISdkLangGraphAdapter` class wraps any AI SDK language model, implementing the `BaseChatModel` interface that LangGraph nodes require. This abstraction allows models from different providers to plug into the same graph structure.

### Where are the TypeScript types for LangGraph state defined?

All type definitions live in **[`lib/orchestration/types.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/lib/orchestration/types.ts)**. This file exports interfaces for graph state, event shapes, configuration objects, and agent context. Centralizing types here ensures consistency across [`director-graph.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/director-graph.ts), [`stateless-generate.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/stateless-generate.ts), and other orchestration components.

### How does OpenMAIC implement streaming responses with LangGraph?

Streaming is implemented in **[`lib/orchestration/stateless-generate.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/lib/orchestration/stateless-generate.ts)** using LangGraph's custom stream mode. The graph's `setStreamMode()` method (configured in [`director-graph.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/director-graph.ts)) enables each node to push `StatelessEvent` objects to the client in real-time, creating responsive user experiences.