|
1 | 1 | # langchain |
2 | 2 |
|
| 3 | +## 1.0.0 |
| 4 | + |
| 5 | +🎉 **LangChain v1.0** is here! This release provides a focused, production-ready foundation for building agents. We've streamlined the framework around three core improvements: **`createAgent`**, **standard content blocks**, and a **simplified package structure**. See the [release notes](https://docs.langchain.com/oss/javascript/releases/langchain-v1) for complete details. |
| 6 | + |
| 7 | +### ✨ Major Features |
| 8 | + |
| 9 | +#### `createAgent` - A new standard for building agents |
| 10 | + |
| 11 | +`createAgent` is the new standard way to build agents in LangChain 1.0. It provides a simpler interface than `createReactAgent` from LangGraph while offering greater customization potential through middleware. |
| 12 | + |
| 13 | +**Key features:** |
| 14 | + |
| 15 | +- **Clean, intuitive API**: Build agents with minimal boilerplate |
| 16 | +- **Built on LangGraph**: Get persistence, streaming, human-in-the-loop, and time travel out of the box |
| 17 | +- **Middleware-first design**: Highly customizable through composable middleware |
| 18 | +- **Improved structured output**: Generate structured outputs in the main agent loop without additional LLM calls |
| 19 | + |
| 20 | +Example: |
| 21 | + |
| 22 | +```typescript |
| 23 | +import { createAgent } from "langchain"; |
| 24 | + |
| 25 | +const agent = createAgent({ |
| 26 | + model: "anthropic:claude-sonnet-4-5-20250929", |
| 27 | + tools: [getWeather], |
| 28 | + systemPrompt: "You are a helpful assistant.", |
| 29 | +}); |
| 30 | + |
| 31 | +const result = await agent.invoke({ |
| 32 | + messages: [{ role: "user", content: "What is the weather in Tokyo?" }], |
| 33 | +}); |
| 34 | + |
| 35 | +console.log(result.content); |
| 36 | +``` |
| 37 | + |
| 38 | +Under the hood, `createAgent` is built on the basic agent loop—calling a model using LangGraph, letting it choose tools to execute, and then finishing when it calls no more tools. |
| 39 | + |
| 40 | +**Built on LangGraph features (work out of the box):** |
| 41 | + |
| 42 | +- **Persistence**: Conversations automatically persist across sessions with built-in checkpointing |
| 43 | +- **Streaming**: Stream tokens, tool calls, and reasoning traces in real-time |
| 44 | +- **Human-in-the-loop**: Pause agent execution for human approval before sensitive actions |
| 45 | +- **Time travel**: Rewind conversations to any point and explore alternate paths |
| 46 | + |
| 47 | +**Structured output improvements:** |
| 48 | + |
| 49 | +- Generate structured outputs in the main loop instead of requiring an additional LLM call |
| 50 | +- Models can choose between calling tools or using provider-side structured output generation |
| 51 | +- Significant cost reduction by eliminating extra LLM calls |
| 52 | + |
| 53 | +Example: |
| 54 | + |
| 55 | +```typescript |
| 56 | +import { createAgent } from "langchain"; |
| 57 | +import * as z from "zod"; |
| 58 | + |
| 59 | +const weatherSchema = z.object({ |
| 60 | + temperature: z.number(), |
| 61 | + condition: z.string(), |
| 62 | +}); |
| 63 | + |
| 64 | +const agent = createAgent({ |
| 65 | + model: "openai:gpt-4o-mini", |
| 66 | + tools: [getWeather], |
| 67 | + responseFormat: weatherSchema, |
| 68 | +}); |
| 69 | + |
| 70 | +const result = await agent.invoke({ |
| 71 | + messages: [{ role: "user", content: "What is the weather in Tokyo?" }], |
| 72 | +}); |
| 73 | + |
| 74 | +console.log(result.structuredResponse); |
| 75 | +``` |
| 76 | + |
| 77 | +For more information, see [Agents documentation](https://docs.langchain.com/oss/javascript/langchain/agents). |
| 78 | + |
| 79 | +#### Middleware |
| 80 | + |
| 81 | +Middleware is what makes `createAgent` highly customizable, raising the ceiling for what you can build. Great agents require **context engineering**—getting the right information to the model at the right time. Middleware helps you control dynamic prompts, conversation summarization, selective tool access, state management, and guardrails through a composable abstraction. |
| 82 | + |
| 83 | +**Prebuilt middleware** for common patterns: |
| 84 | + |
| 85 | +```typescript |
| 86 | +import { |
| 87 | + createAgent, |
| 88 | + summarizationMiddleware, |
| 89 | + humanInTheLoopMiddleware, |
| 90 | + piiRedactionMiddleware, |
| 91 | +} from "langchain"; |
| 92 | + |
| 93 | +const agent = createAgent({ |
| 94 | + model: "anthropic:claude-sonnet-4-5-20250929", |
| 95 | + tools: [readEmail, sendEmail], |
| 96 | + middleware: [ |
| 97 | + piiRedactionMiddleware({ patterns: ["email", "phone", "ssn"] }), |
| 98 | + summarizationMiddleware({ |
| 99 | + model: "anthropic:claude-sonnet-4-5-20250929", |
| 100 | + maxTokensBeforeSummary: 500, |
| 101 | + }), |
| 102 | + humanInTheLoopMiddleware({ |
| 103 | + interruptOn: { |
| 104 | + sendEmail: { |
| 105 | + allowedDecisions: ["approve", "edit", "reject"], |
| 106 | + }, |
| 107 | + }, |
| 108 | + }), |
| 109 | + ] as const, |
| 110 | +}); |
| 111 | +``` |
| 112 | + |
| 113 | +**Custom middleware** with lifecycle hooks: |
| 114 | + |
| 115 | +| Hook | When it runs | Use cases | |
| 116 | +| --------------- | ------------------------ | --------------------------------------- | |
| 117 | +| `beforeAgent` | Before calling the agent | Load memory, validate input | |
| 118 | +| `beforeModel` | Before each LLM call | Update prompts, trim messages | |
| 119 | +| `wrapModelCall` | Around each LLM call | Intercept and modify requests/responses | |
| 120 | +| `wrapToolCall` | Around each tool call | Intercept and modify tool execution | |
| 121 | +| `afterModel` | After each LLM response | Validate output, apply guardrails | |
| 122 | +| `afterAgent` | After agent completes | Save results, cleanup | |
| 123 | + |
| 124 | +Example custom middleware: |
| 125 | + |
| 126 | +```typescript |
| 127 | +import { createMiddleware } from "langchain"; |
| 128 | + |
| 129 | +const contextSchema = z.object({ |
| 130 | + userExpertise: z.enum(["beginner", "expert"]).default("beginner"), |
| 131 | +}); |
| 132 | + |
| 133 | +const expertiseBasedToolMiddleware = createMiddleware({ |
| 134 | + wrapModelCall: async (request, handler) => { |
| 135 | + const userLevel = request.runtime.context.userExpertise; |
| 136 | + if (userLevel === "expert") { |
| 137 | + const tools = [advancedSearch, dataAnalysis]; |
| 138 | + return handler(request.replace("openai:gpt-5", tools)); |
| 139 | + } |
| 140 | + const tools = [simpleSearch, basicCalculator]; |
| 141 | + return handler(request.replace("openai:gpt-5-nano", tools)); |
| 142 | + }, |
| 143 | +}); |
| 144 | + |
| 145 | +const agent = createAgent({ |
| 146 | + model: "anthropic:claude-sonnet-4-5-20250929", |
| 147 | + tools: [simpleSearch, advancedSearch, basicCalculator, dataAnalysis], |
| 148 | + middleware: [expertiseBasedToolMiddleware], |
| 149 | + contextSchema, |
| 150 | +}); |
| 151 | +``` |
| 152 | + |
| 153 | +For more information, see the [complete middleware guide](https://docs.langchain.com/oss/javascript/langchain/middleware). |
| 154 | + |
| 155 | +#### Simplified Package |
| 156 | + |
| 157 | +LangChain v1 streamlines the `langchain` package namespace to focus on essential building blocks for agents. The package exposes only the most useful and relevant functionality (most re-exported from `@langchain/core` for convenience). |
| 158 | + |
| 159 | +**What's in the core `langchain` package:** |
| 160 | + |
| 161 | +- `createAgent` and agent-related utilities |
| 162 | +- Core message types and content blocks |
| 163 | +- Middleware infrastructure |
| 164 | +- Tool definitions and schemas |
| 165 | +- Prompt templates |
| 166 | +- Output parsers |
| 167 | +- Base runnable abstractions |
| 168 | + |
| 169 | +### 🔄 Migration Notes |
| 170 | + |
| 171 | +#### `@langchain/classic` for Legacy Functionality |
| 172 | + |
| 173 | +Legacy functionality has moved to [`@langchain/classic`](https://www.npmjs.com/package/@langchain/classic) to keep the core package lean and focused. |
| 174 | + |
| 175 | +**What's in `@langchain/classic`:** |
| 176 | + |
| 177 | +- Legacy chains and chain implementations |
| 178 | +- The indexing API |
| 179 | +- [`@langchain/community`](https://www.npmjs.com/package/@langchain/community) exports |
| 180 | +- Other deprecated functionality |
| 181 | + |
| 182 | +**To migrate legacy code:** |
| 183 | + |
| 184 | +1. Install `@langchain/classic`: |
| 185 | + |
| 186 | + ```bash |
| 187 | + npm install @langchain/classic |
| 188 | + ``` |
| 189 | + |
| 190 | +2. Update your imports: |
| 191 | + |
| 192 | + ```typescript |
| 193 | + import { ... } from "langchain"; // [!code --] |
| 194 | + import { ... } from "@langchain/classic"; // [!code ++] |
| 195 | + |
| 196 | + import { ... } from "langchain/chains"; // [!code --] |
| 197 | + import { ... } from "@langchain/classic/chains"; // [!code ++] |
| 198 | + ``` |
| 199 | + |
| 200 | +#### Upgrading to v1 |
| 201 | + |
| 202 | +Install the v1 packages: |
| 203 | + |
| 204 | +```bash |
| 205 | + |
| 206 | +``` |
| 207 | + |
| 208 | +### 📚 Additional Resources |
| 209 | + |
| 210 | +- [LangChain 1.0 Announcement](https://blog.langchain.com/langchain-langchain-1-0-alpha-releases/) |
| 211 | +- [Migration Guide](https://docs.langchain.com/oss/javascript/migrate/langchain-v1) |
| 212 | +- [Agents Documentation](https://docs.langchain.com/oss/javascript/langchain/agents) |
| 213 | +- [Middleware Guide](https://blog.langchain.com/agent-middleware/) |
| 214 | + |
| 215 | +--- |
| 216 | + |
3 | 217 | ## 0.3.36 |
4 | 218 |
|
5 | 219 | ### Patch Changes |
|
0 commit comments