Where Are the Core Files for the LangGraph Architecture Located in OpenMAIC?
The core LangGraph architecture files in OpenMAIC are located in the lib/orchestration/ directory, with 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 |
Defines the Director Graph—a StateGraph that coordinates turn-taking between agents and drives the overall workflow |
ai-sdk-adapter.ts |
Wraps any AI SDK language model for use as a LangGraph node; implements the required BaseChatModel interface |
stateless-generate.ts |
Provides stateless generation with custom streaming mode for real-time content delivery |
prompt-builder.ts |
Assembles prompts passed to agents inside LangGraph nodes |
director-prompt.ts |
Stores the system-level prompt template injected into each agent's context |
types.ts |
Central TypeScript typings for state definitions, event shapes, and configuration objects |
tool-schemas.ts |
Defines JSON schemas for tools that agents invoke via LangGraph |
Core File Deep Dive
director-graph.ts — The LangGraph Entry Point
The 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, the graph is built by:
- Instantiating
StateGraphwith a state schema (defined intypes.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 — Model Integration Layer
The AISdkLangGraphAdapter class in 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 — Streaming Implementation
For real-time response generation, 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 and executed here for on-the-fly content creation.
types.ts — Type Safety Foundation
All state definitions, event shapes, and configuration interfaces are centralized in lib/orchestration/types.ts. This ensures type safety across the entire LangGraph architecture, from state transitions in director-graph.ts to tool invocations in tool-schemas.ts.
Working with the LangGraph Files
Creating a Director Graph
Below is a minimal example showing how director-graph.ts constructs a LangGraph state machine using components from the lib/orchestration/ package:
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:
StateGraphinstantiation begins the graph definitionAISdkLangGraphAdapterwraps the underlying language modelbuildPrompt()fromprompt-builder.tsassembles agent inputssetStreamMode()enables the streaming behavior defined instateless-generate.ts
Running the Graph with Streaming
This example demonstrates the execution pattern used throughout OpenMAIC:
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, where events flow continuously to the front-end.
Adding Tool Schemas for Agent Use
Tools are registered using schemas from tool-schemas.ts:
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 file centralizes all JSON schemas, ensuring agents receive properly structured tool definitions.
File Interdependencies
Understanding how the core files interact clarifies the LangGraph architecture:
types.tsprovides the foundation—state and event types used by all other filesdirector-prompt.tsandprompt-builder.tsassemble the prompts fed into nodesai-sdk-adapter.tsenables any model to function as a LangGraph nodedirector-graph.tsorchestrates these components into a compiledStateGraphstateless-generate.tsexecutes specialized streaming workflows using the same graph infrastructuretool-schemas.tsextends 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.tsconstructs and compiles the multi-agentStateGraph - Model integration:
ai-sdk-adapter.tsadapts any AI SDK model for LangGraph node usage - Streaming support:
stateless-generate.tsimplements custom streaming mode for real-time responses - Type safety:
types.tscentralizes all TypeScript definitions for the orchestration layer - Tool capabilities:
tool-schemas.tsdefines 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. 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. 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. This file exports interfaces for graph state, event shapes, configuration objects, and agent context. Centralizing types here ensures consistency across director-graph.ts, stateless-generate.ts, and other orchestration components.
How does OpenMAIC implement streaming responses with LangGraph?
Streaming is implemented in lib/orchestration/stateless-generate.ts using LangGraph's custom stream mode. The graph's setStreamMode() method (configured in director-graph.ts) enables each node to push StatelessEvent objects to the client in real-time, creating responsive user experiences.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →