agentleFS
LangChainKnown publisherlangchain-ai/langchainjs/AGENTS.md

langchainjs

AGENTS.md18k starsChanged 3 months agoMITView on GitHub

This document provides guidance for AI coding agents working with the LangChain.js codebase. When Corridor's analyzePlan tool is available, create a plan and use the tool to analyze it before generating or modifying code. Apply the resulting security guidance before writing code. LangChain.js is a TypeScript framework for building LLM-powered applications. It provides standard interfaces for agents, models, embeddings, vector stores, and more, enabling developers to chain together interoperable components and third-party integrations. This is a monorepo managed with pnpm…

  • Reads credentials
  • Installs packages

Trending

More talk lately.about the whole repository

Dec 2025: 1 mentionJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 4 mentionsApr 2026: 7 mentionsMay 2026: 5 mentionsJun 2026: 2 mentionsJul 2026: 2 mentionsAug 2026: 2 mentionsSep 2026: 5 mentionsOct 2026: 7 mentionsNov 2026: 1 mention
Dec 2025Jun 2026Nov 2026
Mentions a month of the langchain-ai/langchainjs repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about langchain-ai/langchainjs

The biggest 5 of 53 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 53

Talked about on GitHub and Bluesky (53 times).

On GitHub · 50

45 more on GitHub
  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

13 rules. About 0 are common, 6 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When Corridor's analyzePlan tool is available, create a plan and use the tool to analyze it before generating or modifying code.

    line 9
  2. Very specific:

    All commands can be run from the project root using pnpm --filter <package> to target specific workspaces.

    line 69
  3. Very specific:

    No explicit any: - Use proper types (typescript/no-explicit-any: error)

    line 127
  4. Very specific:

    Use expectTypeOf from vitest for type assertions:

    line 257
  5. Distinctive:

    Use the CLI tool to create new integration packages:

    line 334
  6. Very specific:

    Before creating new classes, check if @langchain/core already provides what you need:

    line 344
  7. Distinctive:

    All LLM-related components should support streaming when possible:

    line 355
  8. Distinctive:

    Use the callback manager for tracing and observability:

    line 369
  9. Distinctive:

    Use typed errors with proper error codes:

    line 387
  10. Very specific:

    Add them as regular dependencies in standalone provider packages

    line 397
  11. Very specific:

    Always use caret (^) for version ranges

    line 398
  12. Distinctive:

    Ensure dependencies are MIT or permissively licensed

    line 399
  13. Distinctive:

    Before submitting a PR:

    line 403

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md - AI Agent Guidelines for LangChain.js

This document provides guidance for AI coding agents working with the LangChain.js codebase.

<corridor>

Corridor security analysis

When Corridor's analyzePlan tool is available, create a plan and use the tool to analyze it before generating or modifying code. Apply the resulting security guidance before writing code.

</corridor>

Project Overview

LangChain.js is a TypeScript framework for building LLM-powered applications. It provides standard interfaces for agents, models, embeddings, vector stores, and more, enabling developers to chain together interoperable components and third-party integrations.

Supported Environments

  • Node.js (ESM and CommonJS) - 20.x, 22.x, 24.x
  • Cloudflare Workers
  • Vercel / Next.js (Browser, Serverless and Edge functions)
  • Supabase Edge Functions
  • Browser
  • Deno
  • Bun

Repository Structure

This is a monorepo managed with pnpm workspaces (v10.14.0) and Turborepo.

Key Packages

PackagePathDescription
langchainlibs/langchain/Main LangChain package with agents, prompts, and orchestration
@langchain/corelibs/langchain-core/Core abstractions and interfaces (base classes, runnables, etc.)
@langchain/textsplitterslibs/langchain-textsplitters/Text splitting utilities
@langchain/openailibs/providers/langchain-openai/OpenAI integration
@langchain/anthropiclibs/providers/langchain-anthropic/Anthropic integration
Other providerslibs/providers/langchain-*/First-party provider integrations

Internal Packages

PackagePathDescription
@langchain/buildinternal/build/Build utilities
@langchain/tsconfiginternal/tsconfig/Shared TypeScript configuration
@langchain/standard-testslibs/langchain-standard-tests/Standard test suite for integrations

Development Setup

Prerequisites

  • Node.js v24.x (check with node -v)
  • pnpm v10.14.0 (package manager)

Initial Setup

# Install dependencies from root
pnpm install

# Build the core package first (required before other packages)
pnpm --filter @langchain/core build

Common Commands

All commands can be run from the project root using pnpm --filter <package> to target specific workspaces.

Package Filters

  • --filter langchain - the main langchain package
  • --filter @langchain/core - the core package
  • --filter @langchain/openai - OpenAI integration (and similarly for other providers)

Building

pnpm --filter langchain build
pnpm --filter @langchain/core build

Linting

pnpm lint

Formatting

pnpm format        # Fix formatting
pnpm format:check  # Check only

Testing

# Unit tests
pnpm --filter langchain test
pnpm --filter @langchain/core test

# Integration tests (requires API keys)
pnpm --filter langchain test:integration

# Single test file
pnpm --filter <package> test:single <path-to-test>

Coding Standards

TypeScript Configuration

The project uses a shared TypeScript configuration from internal/tsconfig/base.json:

  • Target: ES2022
  • Module: ESNext with bundler resolution
  • Strict mode enabled
  • Source maps and declaration maps enabled

Lint Rules

Lint rules are defined in .oxlintrc.json. Key rules to follow:

  1. No process.env - Except in test files (node/no-process-env: error)
  2. No explicit any - Use proper types (typescript/no-explicit-any: error)
  3. Prefer template literals - Over string concatenation (prefer-template: error)
  4. File extensions required - In imports (import/extensions: error)

Import Conventions

// Always include .js extension for local imports (ESM)
import { Something } from "./something.js";

// Use named exports, not default exports
export { MyClass, myFunction };

Zod Schema Support

The codebase supports both Zod v3 and v4:

import { z } from "zod/v3";
import { z as z4 } from "zod/v4";

File Naming Conventions

Source Files

  • Regular modules: my_module.ts (snake_case)
  • Index files: index.ts
  • Type definitions: types.ts

Test Files

  • Unit tests: *.test.ts - Tests that don't require external APIs
  • Integration tests: *.int.test.ts - Tests that call external APIs
  • Type tests: *.test-d.ts - TypeScript type checking tests
  • Standard tests: *.standard.test.ts / *.standard.int.test.ts - Standard test suite

Tests should be placed in a tests/ folder alongside the module being tested.

Core Abstractions

Runnables

The Runnable interface (@langchain/core/runnables) is the foundation of LangChain. All major components extend Runnable:

import {
  Runnable,
  RunnableConfig,
  RunnableLike,
} from "@langchain/core/runnables";

Key methods:

  • invoke(input, config?) - Single invocation
  • stream(input, config?) - Streaming invocation
  • batch(inputs, config?) - Batch invocation

Messages

Messages are in @langchain/core/messages:

import {
  HumanMessage,
  AIMessage,
  SystemMessage,
  ToolMessage,
  BaseMessage,
} from "@langchain/core/messages";

Tools

Tools extend StructuredTool from @langchain/core/tools:

import { StructuredTool, DynamicTool, tool } from "@langchain/core/tools";

Chat Models

Chat models extend BaseChatModel from @langchain/core/language_models/chat_models:

import {
  BaseChatModel,
  BaseChatModelParams,
} from "@langchain/core/language_models/chat_models";

Writing Tests

Unit Tests

import { test, expect, describe } from "vitest";
import { FakeChatModel } from "@langchain/core/utils/testing";

test("should do something", async () => {
  const model = new FakeChatModel({});
  const result = await model.invoke([["human", "Hello!"]]);
  expect(result.content).toBe("Hello!");
});

Integration Tests

Integration tests require actual API credentials:

import { describe, test, expect } from "vitest";
import { ChatOpenAI } from "../index.js";
import { HumanMessage } from "@langchain/core/messages";

test("Test ChatOpenAI Generate", async () => {
  const chat = new ChatOpenAI({
    model: "gpt-4o-mini",
    maxTokens: 10,
  });
  const message = new HumanMessage("Hello!");
  const result = await chat.invoke([message]);
  expect(typeof result.content).toBe("string");
});

Type Tests

Use expectTypeOf from vitest for type assertions:

import { expectTypeOf } from "vitest";

expectTypeOf(someFunction).returns.toMatchTypeOf<ExpectedType>();

Standard Tests

For provider integrations, extend the standard test classes:

import { ChatModelUnitTests } from "@langchain/standard-tests";

class MyChatModelStandardUnitTests extends ChatModelUnitTests<
  MyChatModelCallOptions,
  AIMessageChunk
> {
  constructor() {
    super({
      Cls: MyChatModel,
      chatModelHasToolCalling: true,
      chatModelHasStructuredOutput: true,
      constructorArgs: {},
    });
  }
}

Creating New Integrations

Provider Package Structure

New provider packages should follow this structure:

libs/providers/langchain-{provider}/
├── package.json
├── tsconfig.json
├── tsdown.config.ts
├── vitest.config.ts
├── turbo.json
├── README.md
├── LICENSE
└── src/
    ├── index.ts
    ├── chat_models/
    │   ├── index.ts
    │   └── tests/
    │       ├── index.test.ts
    │       ├── index.int.test.ts
    │       ├── index.standard.test.ts
    │       └── index.standard.int.test.ts
    └── embeddings.ts (if applicable)

Package.json Requirements

{
  "name": "@langchain/provider-name",
  "type": "module",
  "engines": { "node": ">=20" },
  "peerDependencies": {
    "@langchain/core": "^1.0.0"
  },
  "devDependencies": {
    "@langchain/core": "workspace:^",
    "@langchain/standard-tests": "workspace:*",
    "@langchain/tsconfig": "workspace:*"
  }
}

Scaffolding

Use the CLI tool to create new integration packages:

npx create-langchain-integration

Best Practices

1. Use Existing Abstractions

Before creating new classes, check if @langchain/core already provides what you need:

  • Runnable and its variants
  • StructuredTool for tools
  • BaseChatModel for chat models
  • Embeddings for embedding models
  • BaseRetriever for retrievers
  • VectorStore for vector stores

2. Support Streaming

All LLM-related components should support streaming when possible:

async *_streamResponseChunks(
  messages: BaseMessage[],
  options: this["ParsedCallOptions"],
  runManager?: CallbackManagerForLLMRun
): AsyncGenerator<ChatGenerationChunk> {
  // Yield chunks as they arrive
}

3. Handle Callbacks Properly

Use the callback manager for tracing and observability:

await runManager?.handleLLMNewToken(token);

4. Environment Variables

Access environment variables using the utility:

import { getEnvironmentVariable } from "@langchain/core/utils/env";

const apiKey = getEnvironmentVariable("MY_API_KEY");

5. Error Handling

Use typed errors with proper error codes:

throw new Error("Model authentication failed", {
  cause: { lc_error_code: "MODEL_AUTHENTICATION" },
});

6. Third-Party Dependencies

  • Add them as regular dependencies in standalone provider packages
  • Always use caret (^) for version ranges
  • Ensure dependencies are MIT or permissively licensed

Pull Request Checklist

Before submitting a PR:

  1. Run pnpm lint and fix any issues
  2. Run pnpm format to format code
  3. Add/update unit tests (*.test.ts)
  4. Add/update integration tests if applicable (*.int.test.ts)
  5. Add/update type tests if changing public APIs (*.test-d.ts)
  6. Update documentation if changing public APIs
  7. Keep changes focused - one feature/fix per PR
  8. Ensure no circular dependencies (checked by lint:dpdm)

Debugging Tips

Running Specific Tests

# Run a single test file
pnpm --filter @langchain/core test src/messages/tests/utils.test.ts

# Run tests matching a pattern
pnpm --filter @langchain/core test --grep "should handle"

# Watch mode
pnpm --filter @langchain/core test:watch

Building in Watch Mode

pnpm watch

Checking for Circular Dependencies

pnpm --filter @langchain/core lint:dpdm

Resources

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.