Skip to content

Commit 074da7f

Browse files
feat(create-langgraph): allow user to generate a langgraph config file (#1833)
1 parent 97e7210 commit 074da7f

File tree

12 files changed

+1665
-42
lines changed

12 files changed

+1665
-42
lines changed

.changeset/afraid-ants-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-langgraph": minor
3+
---
4+
5+
feat(create-langgraph): allow user to generate a langgraph config file

libs/create-langgraph/README.md

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
# create-langgraph
2+
3+
[![npm version](https://img.shields.io/npm/v/create-langgraph.svg)](https://www.npmjs.com/package/create-langgraph)
4+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5+
6+
The official scaffolding tool for [LangGraph.js](https://langchain-ai.github.io/langgraphjs/) projects. Quickly bootstrap new LangGraph applications from curated templates or generate configuration files for existing projects.
7+
8+
## Quick Start
9+
10+
Create a new LangGraph project with a single command:
11+
12+
```bash
13+
# Using npm
14+
npm init langgraph@latest
15+
16+
# Using yarn
17+
yarn create langgraph
18+
19+
# Using pnpm
20+
pnpm create langgraph
21+
22+
# Using bun
23+
bunx create-langgraph
24+
```
25+
26+
Follow the interactive prompts to select a template and configure your project.
27+
28+
## Templates
29+
30+
Choose from a variety of production-ready templates:
31+
32+
| Template | Description |
33+
| ------------------------------------------------------------------------------------ | --------------------------------------------------------------- |
34+
| [**New LangGraph Project**](https://github.com/langchain-ai/new-langgraphjs-project) | A simple, minimal chatbot with memory |
35+
| [**ReAct Agent**](https://github.com/langchain-ai/react-agent-js) | A flexible agent that can be extended with many tools |
36+
| [**Memory Agent**](https://github.com/langchain-ai/memory-agent-js) | A ReAct-style agent with persistent memory across conversations |
37+
| [**Retrieval Agent**](https://github.com/langchain-ai/retrieval-agent-template-js) | An agent with retrieval-based question-answering |
38+
| [**Data-enrichment Agent**](https://github.com/langchain-ai/data-enrichment-js) | An agent that performs web searches and organizes findings |
39+
40+
### Using a Specific Template
41+
42+
Skip the interactive prompt by specifying a template directly:
43+
44+
```bash
45+
npx create-langgraph@latest my-project --template react-agent-js
46+
```
47+
48+
Available template IDs:
49+
50+
- `new-langgraph-project-js`
51+
- `react-agent-js`
52+
- `memory-agent-js`
53+
- `retrieval-agent-js`
54+
- `data-enrichment-js`
55+
56+
## Commands
57+
58+
### `create-langgraph [path]`
59+
60+
Creates a new LangGraph project at the specified path.
61+
62+
```bash
63+
npx create-langgraph@latest my-awesome-agent
64+
```
65+
66+
**Options:**
67+
68+
- `-t, --template <template>` — Use a specific template (skips interactive selection)
69+
70+
**What it does:**
71+
72+
1. Downloads the selected template from GitHub
73+
2. Extracts it to your target directory
74+
3. Optionally initializes a Git repository
75+
4. Provides next steps for getting started
76+
77+
### `create-langgraph config [path]`
78+
79+
Scans your project for LangGraph agents and generates a `langgraph.json` configuration file.
80+
81+
```bash
82+
# In your project directory
83+
npx create-langgraph@latest config
84+
85+
# Or specify a path
86+
npx create-langgraph@latest config ./my-project
87+
```
88+
89+
This command is useful when:
90+
91+
- You have an existing project and want to add LangGraph Platform support
92+
- You've added new agents and need to update your configuration
93+
- You want to automatically detect all agents in your codebase
94+
95+
## Agent Detection
96+
97+
The `config` command automatically detects LangGraph agents defined using these patterns:
98+
99+
### ESM (ES Modules)
100+
101+
```typescript
102+
// Using createAgent
103+
export const agent = createAgent({ model, tools });
104+
105+
// Using StateGraph
106+
export const graph = new StateGraph(annotation).compile();
107+
108+
// Using workflow builder pattern
109+
export const app = workflow.compile();
110+
```
111+
112+
### CommonJS
113+
114+
```javascript
115+
// Using module.exports
116+
module.exports.agent = createAgent({ model, tools });
117+
module.exports.graph = workflow.compile();
118+
119+
// Using exports shorthand
120+
exports.myAgent = createAgent({ model, tools });
121+
```
122+
123+
### What Gets Detected
124+
125+
The scanner looks for:
126+
127+
- `createAgent()` function calls
128+
- `new StateGraph(...).compile()` patterns
129+
- `workflow.compile()` or `builder.compile()` patterns
130+
131+
**Important:** Only **exported** agents are included in the generated configuration. Unexported agents will be listed as warnings so you can add the `export` keyword if needed.
132+
133+
## Generated Configuration
134+
135+
The `config` command generates a `langgraph.json` file like this:
136+
137+
```json
138+
{
139+
"node_version": "20",
140+
"graphs": {
141+
"agent": "./src/agent.ts:agent",
142+
"searchAgent": "./src/search.ts:searchAgent"
143+
},
144+
"env": ".env"
145+
}
146+
```
147+
148+
The configuration includes:
149+
150+
- **node_version** — Detected from your current Node.js version
151+
- **graphs** — Map of agent names to their file paths and export names
152+
- **env** — Path to `.env` file (if one exists)
153+
154+
## Project Structure
155+
156+
After scaffolding, your project will have this structure:
157+
158+
```txt
159+
my-project/
160+
├── src/
161+
│ └── agent.ts # Your LangGraph agent
162+
├── langgraph.json # LangGraph configuration
163+
├── package.json
164+
├── tsconfig.json
165+
└── .env.example # Environment variables template
166+
```
167+
168+
## Next Steps After Creating a Project
169+
170+
```bash
171+
# Navigate to your project
172+
cd my-project
173+
174+
# Install dependencies
175+
npm install # or yarn, pnpm, bun
176+
177+
# Start the LangGraph development server
178+
npx @langchain/langgraph-cli@latest dev
179+
```
180+
181+
The development server provides:
182+
183+
- A local API server for your agents
184+
- Hot reloading during development
185+
- Built-in debugging tools
186+
187+
## Analytics
188+
189+
This CLI collects anonymous usage analytics to help improve the tool. The following information is collected:
190+
191+
- Operating system and version
192+
- Node.js version
193+
- CLI version
194+
- Command executed
195+
196+
**No personal information, project details, or code is ever collected.**
197+
198+
To opt out of analytics, set the environment variable:
199+
200+
```bash
201+
export LANGGRAPH_CLI_NO_ANALYTICS=1
202+
```
203+
204+
## Requirements
205+
206+
- Node.js 18 or later
207+
- npm, yarn, pnpm, or bun
208+
209+
## Related Packages
210+
211+
- [@langchain/langgraph](https://www.npmjs.com/package/@langchain/langgraph) — The core LangGraph library
212+
- [@langchain/langgraph-cli](https://www.npmjs.com/package/@langchain/langgraph-cli) — CLI tools for running LangGraph projects
213+
214+
## License
215+
216+
MIT © [LangChain](https://langchain.com)

libs/create-langgraph/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"version": "1.0.0",
44
"description": "Create a new LangGraph project",
55
"license": "MIT",
6-
"main": "dist/index.mjs",
7-
"bin": "dist/cli.mjs",
6+
"main": "dist/index.js",
7+
"bin": "dist/cli.js",
8+
"type": "module",
89
"files": [
910
"dist"
1011
],
@@ -20,6 +21,8 @@
2021
"build": "yarn turbo:command build:internal --filter=create-langgraph",
2122
"build:internal": "yarn clean && yarn tsc --outDir dist",
2223
"prepublish": "yarn build",
24+
"test": "vitest run",
25+
"test:watch": "vitest",
2326
"format": "prettier --write .",
2427
"format:check": "prettier --check ."
2528
},
@@ -36,12 +39,12 @@
3639
"prettier": "^2.8.3",
3740
"tsx": "^4.19.3",
3841
"typescript": "^4.9.5 || ^5.4.5",
39-
"vitest": "^3.2.4"
42+
"vitest": "^4.0.16"
4043
},
4144
"exports": {
4245
".": {
43-
"types": "./dist/index.d.mts",
44-
"default": "./dist/index.mjs"
46+
"types": "./dist/index.d.ts",
47+
"default": "./dist/index.js"
4548
}
4649
},
4750
"keywords": []

libs/create-langgraph/src/cli.mts

Lines changed: 0 additions & 21 deletions
This file was deleted.

libs/create-langgraph/src/cli.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env node
2+
import { Command } from "@commander-js/extra-typings";
3+
4+
import { version } from "./utils/version.js";
5+
import { withAnalytics } from "./utils/analytics.js";
6+
import { createNew } from "./index.js";
7+
import { generateConfig } from "./config.js";
8+
9+
const program = new Command()
10+
.name("create-langgraph")
11+
.version(version)
12+
.description("Create a new LangGraph project");
13+
14+
// Default command: create a new project
15+
program
16+
.argument("[path]", "Path to create the project")
17+
.option("-t, --template <template>", "Template to use", "")
18+
.hook("preAction", withAnalytics())
19+
.action((path, options) => {
20+
createNew(path, options.template).catch((error) => {
21+
console.error("Error:", error.message);
22+
process.exit(1);
23+
});
24+
});
25+
26+
// Config subcommand: generate langgraph.json
27+
program
28+
.command("config")
29+
.description(
30+
"Generate a langgraph.json configuration file by scanning for agents"
31+
)
32+
.argument(
33+
"[path]",
34+
"Path to the project to scan (defaults to current directory)"
35+
)
36+
.hook("preAction", withAnalytics())
37+
.action((path) => {
38+
generateConfig(path).catch((error) => {
39+
console.error("Error:", error.message);
40+
process.exit(1);
41+
});
42+
});
43+
44+
program.parse();

0 commit comments

Comments
 (0)