agentleFS
LangChainKnown publisherlangchain-ai/langchain/AGENTS.md

langchain

AGENTS.md150k starsChanged 2 months agoMITView on GitHub

This document provides context to understand the LangChain Python project and assist with development. 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. This is a Python monorepo with multiple independently versioned packages that use uv. This monorepo uses uv for dependency management. Local development uses editable installs declared under each package's [tool.uv.sources] table in pyproject.toml, so path dependencies resolve…

  • Reads credentials

Trending

Quiet since August.about the whole repository

Dec 2025: 0 mentionsJan 2026: 2 mentionsFeb 2026: 0 mentionsMar 2026: 1 mentionApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 1 mentionSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the langchain-ai/langchain repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about langchain-ai/langchain

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

See all 29

Talked about on Bluesky, GitHub and Hacker News (29 times).

On Bluesky · 14

9 more on Bluesky

On GitHub · 11

6 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

36 rules. About 0 are common, 27 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈27

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    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. Distinctive:

    Before running your tests, set up all packages by running:

    line 56
  3. Very specific:

    Use uv for all environment and dependency operations in this monorepo.

    line 87
  4. Distinctive:

    Don't mix environments within a session, and don't add new dependencies unless strictly required — when you do, justify them (recent …

    line 92
  5. Very specific:

    Follow Conventional Commits.

    line 106
  6. Very specific:

    Start the text after type(scope): with a lowercase letter, unless the first word is a proper noun (e.g.

    line 108
  7. Distinctive:

    Keep titles short and descriptive — save detail for the body.

    line 110
  8. Distinctive:

    When the PR closes an issue, lead with the closing keyword on its own line at the very top, followed by a horizontal rule and then the body:

    line 142
  9. Very specific:

    Only Closes, Fixes, and Resolves auto-close the referenced issue on merge.

    line 152
  10. Distinctive:

    Write for readers who may be unfamiliar with this area of the codebase.

    line 155
  11. Distinctive:

    Do not cite line numbers; they go stale as soon as the file changes.

    line 156
  12. Distinctive:

    Call out areas of the change that require careful review.

    line 161
  13. Distinctive:

    Add a brief disclaimer noting AI-agent involvement in the contribution.

    line 162
  14. Very specific:

    Check if the function/class is exported in __init__.py

    line 173
  15. Distinctive:

    Look for existing usage patterns in tests and examples

    line 174
  16. Very specific:

    Use keyword-only arguments for new parameters: *, new_param: str = "default"

    line 175
  17. Distinctive:

    Ask: "Would this change break someone's code if they used it last week?"

    line 178
  18. Distinctive:

    All Python code MUST include type hints and return types.

    line 182
  19. Distinctive:

    Use descriptive, self-explanatory variable names.

    line 199
  20. Distinctive:

    Follow existing patterns in the codebase you're modifying

    line 200
  21. Distinctive:

    Every new feature or bugfix MUST be covered by unit tests.

    line 205
  22. Distinctive:

    Remove unreachable/commented code before committing

    line 225
  23. Distinctive:

    Ensure proper resource cleanup (file handles, connections)

    line 227
  24. Distinctive:

    Use Google-style docstrings with Args section for all public functions.

    line 231
  25. Distinctive:

    If a default is present, DO NOT repeat it in the docstring unless there is post-processing or it is set conditionally.

    line 254
  26. Distinctive:

    Document all parameters, return values, and exceptions

    line 256
  27. Distinctive:

    Keep descriptions concise but clear

    line 257
  28. Distinctive:

    Ensure American English spelling (e.g., "behavior", not "behaviour")

    line 258
  29. Very specific:

    Do NOT use Sphinx-style double backtick formatting ( code ).

    line 259
  30. Distinctive:

    Always use the latest generally available (GA) models when referencing LLMs in docstrings and illustrative code snippets.

    line 263
  31. Distinctive:

    Before writing or updating model references, verify current model IDs against the provider's official docs.

    line 265
  32. Distinctive:

    Version bump PR: Create a PR that bumps three files by one line each:

    line 300
  33. Very specific:

    Trigger the release workflow: Run gh workflow run against the "🚀 Package Release" workflow (_release.yml, file ID 63880841):

    line 311
  34. Distinctive:

    When adding a new partner package, update these files:

    line 359
  35. Distinctive:

    Treat source code and tests as authoritative.

    line 385
  36. Distinctive:

    Prefer the narrowest quiet validation that proves the changed behavior.

    line 386

≈ “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

Global development guidelines for the LangChain monorepo

This document provides context to understand the LangChain Python project and assist with development.

<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 architecture and context

Monorepo structure

This is a Python monorepo with multiple independently versioned packages that use uv.

langchain/
├── libs/
│   ├── core/             # `langchain-core` primitives and base abstractions
│   ├── langchain/        # `langchain-classic` (legacy, no new features)
│   ├── langchain_v1/     # Actively maintained `langchain` package
│   ├── partners/         # Third-party integrations
│   │   ├── openai/       # OpenAI models and embeddings
│   │   ├── anthropic/    # Anthropic (Claude) integration
│   │   ├── ollama/       # Local model support
│   │   └── ... (other integrations maintained by the LangChain team)
│   ├── text-splitters/   # Document chunking utilities
│   ├── standard-tests/   # Shared test suite for integrations
│   └── model-profiles/   # Model configuration profiles
├── .github/              # CI/CD workflows and templates
├── .vscode/              # VSCode IDE standard settings and recommended extensions
├── openwiki/             # Generated just-in-time evidence index (optional reading)
└── README.md             # Information about LangChain
  • Core layer (langchain-core): Base abstractions, interfaces, and protocols. Users should not need to know about this layer directly.
  • Implementation layer (langchain): Concrete implementations and high-level public utilities
  • Integration layer (partners/): Third-party service integrations. Note that this monorepo is not exhaustive of all LangChain integrations; some are maintained in separate repos, such as langchain-ai/langchain-google and langchain-ai/langchain-aws. Usually these repos are cloned at the same level as this monorepo, so if needed, you can refer to their code directly by navigating to ../langchain-google/ from this monorepo.
  • Testing layer (standard-tests/): Standardized integration tests for partner integrations

Development tools & commands

  • uv – Fast Python package installer and resolver (replaces pip/poetry)
  • make – Task runner for common development commands. Each package under libs/ has its own Makefile; feel free to look at it for available commands and usage patterns.
  • ruff – Fast Python linter and formatter
  • mypy – Static type checking
  • pytest – Testing framework

This monorepo uses uv for dependency management. Local development uses editable installs declared under each package's [tool.uv.sources] table in pyproject.toml, so path dependencies resolve to your working tree instead of PyPI.

Each package in libs/ has its own pyproject.toml, uv.lock, and Makefile. There is no workspace-level pyproject.toml or Makefile at the repo root — always cd into the package you are working on before running the commands below (for example cd libs/langchain_v1 or cd libs/core).

Before running your tests, set up all packages by running:

# For all groups
uv sync --all-groups

# or, to install a specific group only:
uv sync --group test
# Run unit tests (no network)
make test

# Run specific test file
uv run --group test pytest tests/unit_tests/test_specific.py
# Lint code
make lint

# Format code
make format

# Type checking
uv run --group lint mypy .

Environment and dependency management

Use uv for all environment and dependency operations in this monorepo. Do not invoke pip, poetry, or conda directly.

  • Let uv manage the interpreter and virtual environments — uv sync and uv run operate without manual source .venv/bin/activate. Do not create ad-hoc virtual environments outside the package directory.
  • Each package targets its own supported Python range via its pyproject.toml; do not pin a global Python version. If you need an interpreter explicitly, defer to the package's requires-python rather than assuming system Python.
  • Install dependencies explicitly through uv sync (optionally --group <name> / --all-groups); never let them install implicitly.
  • Don't mix environments within a session, and don't add new dependencies unless strictly required — when you do, justify them (recent releases/commits, adoption).

Key config files

There is no single workspace config at the repository root. Configuration lives per package:

  • libs/<package>/pyproject.toml: Package metadata and dependency groups (test, lint, typing, dev, …)
  • libs/<package>/uv.lock: Locked dependencies for reproducible builds
  • libs/<package>/Makefile: Development tasks for that package (test, lint, format, type, …)
  • libs/Makefile: Cross-package lock / check-lock only
  • .pre-commit-config.yaml (repo root): Git hooks that run per-package format/lint

PR and commit titles

Follow Conventional Commits. See .github/workflows/pr_lint.yml for allowed types and scopes. All titles must include a scope with no exceptions — even for the main langchain package.

  • Start the text after type(scope): with a lowercase letter, unless the first word is a proper noun (e.g. Azure, GitHub, OpenAI) or a named entity (class, function, method, parameter, or variable name).
  • Wrap named entities in backticks so they render as code. Proper nouns are left unadorned.
  • Keep titles short and descriptive — save detail for the body.

Examples:

feat(langchain): add new chat completion feature
fix(core): resolve type hinting issue in vector store
chore(anthropic): update infrastructure dependencies
feat(langchain): `ls_agent_type` tag on `create_agent` calls
fix(openai): infer Azure chat profiles from model name

Branch naming

Branches should be prefixed <github-username>/<scope>/<short-description>:

  • <github-username> — the author's GitHub login (e.g. mdrxy).
  • <scope> — the same scope used in the Conventional Commit title (core, langchain, partner name, infra, docs, etc.).
  • <short-description> — kebab-case, brief, no trailing slash.

Examples:

mdrxy/anthropic/normalize-tool-call-ids
mdrxy/core/vector-store-type-hints
mdrxy/infra/agents-md-branch

PR descriptions

The description is the summary — do not add a # Summary header.

  • When the PR closes an issue, lead with the closing keyword on its own line at the very top, followed by a horizontal rule and then the body:

    Closes #123
    
    ---
    
    <rest of description>

    Only Closes, Fixes, and Resolves auto-close the referenced issue on merge. Related: or similar labels are informational and do not close anything.

  • Explain the why: who benefits, what problem they had, and how this solves it. Prefer a simple user story over a long summary.
  • Write for readers who may be unfamiliar with this area of the codebase. Avoid insider shorthand and prefer language that is friendly to public viewers — this aids interpretability.
  • Do not cite line numbers; they go stale as soon as the file changes.
  • Rarely include full file paths or filenames. Reference the affected symbol, class, or subsystem by name instead.
  • Wrap class, function, method, parameter, and variable names in backticks.
  • For net new features or behavior-changing bugfixes, PR descriptions should include a ## Release note section that states the user-visible change in release-note-ready language.
  • Skip dedicated "Test plan" or "Testing" sections in most cases. Mention tests only when coverage is non-obvious, risky, or otherwise notable.
  • Call out areas of the change that require careful review.
  • Add a brief disclaimer noting AI-agent involvement in the contribution.

Core development principles

Maintain stable public interfaces

CRITICAL: Always attempt to preserve function signatures, argument positions, and names for exported/public methods. Do not make breaking changes. You should warn the developer for any function signature changes, regardless of whether they look breaking or not.

Before making ANY changes to public APIs:

  • Check if the function/class is exported in __init__.py
  • Look for existing usage patterns in tests and examples
  • Use keyword-only arguments for new parameters: *, new_param: str = "default"
  • Mark experimental features clearly with docstring warnings (using MkDocs Material admonitions, like !!! warning)

Ask: "Would this change break someone's code if they used it last week?"

Code quality standards

All Python code MUST include type hints and return types.

def filter_unknown_users(users: list[str], known_users: set[str]) -> list[str]:
    """Single line description of the function.

    Any additional context about the function can go here.

    Args:
        users: List of user identifiers to filter.
        known_users: Set of known/valid user identifiers.

    Returns:
        List of users that are not in the `known_users` set.
    """
  • Use descriptive, self-explanatory variable names.
  • Follow existing patterns in the codebase you're modifying
  • Attempt to break up complex functions (>20 lines) into smaller, focused functions where it makes sense

Testing requirements

Every new feature or bugfix MUST be covered by unit tests.

  • Unit tests: tests/unit_tests/ (no network calls allowed)
  • Integration tests: tests/integration_tests/ (network calls permitted)
  • We use pytest as the testing framework; if in doubt, check other existing tests for examples.
  • The testing file structure should mirror the source code structure.

Checklist:

  • Tests fail when your new logic is broken
  • Happy path is covered
  • Edge cases and error conditions are tested
  • Use fixtures/mocks for external dependencies
  • Tests are deterministic (no flaky tests)
  • Does the test suite fail if your new logic is broken?

Security and risk assessment

  • No eval(), exec(), or pickle on user-controlled input
  • Proper exception handling (no bare except:) and use a msg variable for error messages
  • Remove unreachable/commented code before committing
  • Race conditions or resource leaks (file handles, sockets, threads).
  • Ensure proper resource cleanup (file handles, connections)

Documentation standards

Use Google-style docstrings with Args section for all public functions.

def send_email(to: str, msg: str, *, priority: str = "normal") -> bool:
    """Send an email to a recipient with specified priority.

    Any additional context about the function can go here.

    Args:
        to: The email address of the recipient.
        msg: The message body to send.
        priority: Email priority level.

    Returns:
        `True` if email was sent successfully, `False` otherwise.

    Raises:
        InvalidEmailError: If the email address format is invalid.
        SMTPConnectionError: If unable to connect to email server.
    """
  • Types go in function signatures, NOT in docstrings
    • If a default is present, DO NOT repeat it in the docstring unless there is post-processing or it is set conditionally.
  • Focus on "why" rather than "what" in descriptions
  • Document all parameters, return values, and exceptions
  • Keep descriptions concise but clear
  • Ensure American English spelling (e.g., "behavior", not "behaviour")
  • Do NOT use Sphinx-style double backtick formatting (``code``). Use single backticks (`code`) for inline code references in docstrings and comments.

Model references in docs and examples

Always use the latest generally available (GA) models when referencing LLMs in docstrings and illustrative code snippets. Avoid preview or beta identifiers unless the model has no GA equivalent. Outdated model names signal stale code and confuse users.

Before writing or updating model references, verify current model IDs against the provider's official docs. Do not rely on memorized or cached model names — they go stale quickly.

Changing shipped default parameter values in code (e.g., a model= kwarg default in a class constructor) may constitute a breaking change — see "Maintain stable public interfaces" above. This guidance applies to documentation and examples, not code defaults.

For model profile data (capability flags, context windows), use the langchain-profiles CLI described below.

Model profiles

Model profiles are generated using the langchain-profiles CLI in libs/model-profiles. The --data-dir must point to the directory containing profile_augmentations.toml, not the top-level package directory.

# Run from libs/model-profiles
cd libs/model-profiles

# Refresh profiles for a partner in this repo
uv run langchain-profiles refresh --provider openai --data-dir ../partners/openai/langchain_openai/data

# Refresh profiles for a partner in an external repo (requires echo y to confirm)
echo y | uv run langchain-profiles refresh --provider google --data-dir /path/to/langchain-google/libs/genai/langchain_google_genai/data

Example partners with profiles in this repo:

  • libs/partners/openai/langchain_openai/data/ (provider: openai)
  • libs/partners/anthropic/langchain_anthropic/data/ (provider: anthropic)
  • libs/partners/perplexity/langchain_perplexity/data/ (provider: perplexity)

The echo y | pipe is required when --data-dir is outside the libs/model-profiles working directory.

CI/CD infrastructure

Release process

Each partner package is released independently. The full flow is:

  1. Version bump PR. Create a PR that bumps three files by one line each:

    • langchain_<partner>/_version.py — __version__
    • pyproject.toml — version
    • uv.lock — run uv lock from the package directory. If the diff includes unrelated changes (e.g. environment-dependent marker lines from a different local Python version), revert them and keep only the version = "..." line for the package being released

    Title follows Conventional Commits: release(<partner>): <version> (e.g. release(openrouter): 0.2.6). Use the branch name release/<partner>-<version>.

    Patch vs. minor bump follows in-repo precedent: within a 0.x series, fixes and additive features get a patch bump (e.g. session_id field → 0.2.1→0.2.2, parallel_tool_calls → 0.2.3→0.2.4).

  2. Merge the PR to master.
  3. Trigger the release workflow. Run gh workflow run against the "🚀 Package Release" workflow (_release.yml, file ID 63880841):

    gh workflow run 63880841 --repo langchain-ai/langchain \
      -f working-directory=<partner> -f release-version=<version>

    working-directory is the short partner name from the workflow's dropdown (e.g. openrouter, not libs/partners/openrouter).

  4. The workflow handles everything else automatically — do not create a GitHub release or tag manually. The mark-release job (using ncipollo/release-action) creates the GitHub release, tag, and release notes after PyPI publish succeeds. The release notes body is auto-generated from commit history between the previous tag and HEAD.

    Monitor the run:

    gh run view <run-id> --repo langchain-ai/langchain

    The full job chain is: build → release-notes → pre-release-checks → TestPyPI publish → PyPI publish → tag GitHub release.

PR labeling and linting

Title linting (.github/workflows/pr_lint.yml)

Auto-labeling:

  • .github/workflows/pr_labeler.yml – Unified PR labeler (size, file, title, external/internal, contributor tier)
  • .github/workflows/pr_labeler_backfill.yml – Manual backfill of PR labels on open PRs
  • .github/workflows/auto-label-by-package.yml – Issue labeling by package
  • .github/workflows/tag-external-issues.yml – Issue external/internal classification

Integration test tracing (LangSmith)

Scheduled and manually dispatched integration tests (integration_tests.yml) trace every run to LangSmith so failures link back to the originating Actions run. (_release.yml runs integration tests too, but does not currently configure LangSmith tracing.)

Env vars set by CI:

  • LANGSMITH_API_KEY — authenticates to LangSmith (repo secret, scoped to the "Scheduled testing" GitHub environment in integration_tests.yml).
  • LANGSMITH_TRACING: "true" — enables tracing for the test process.
  • LANGSMITH_PROJECT — the project traces are sent to. Defaults to scheduled-testing-py via a repo variable override: ${{ vars.LANGSMITH_PROJECT || 'scheduled-testing-py' }}. To change the project, set the LANGSMITH_PROJECT repository variable in GitHub settings — do not hardcode it in the workflow.
  • LANGSMITH_TAGS — comma-separated tags identifying the run: github-actions, the matrix working directory (e.g. libs/partners/openai), the Python version, and the commit SHA.
  • LANGSMITH_METADATA — a JSON object built by the "Build LangSmith Metadata" step, containing github_sha, github_run_id, github_run_attempt, github_run_url, github_workflow, github_event, github_ref, working_directory, and python_version.

The tracing bridge plugin: The LangSmith SDK does not natively read LANGSMITH_TAGS or LANGSMITH_METADATA from the environment. The pytest plugin at libs/standard-tests/langchain_tests/_langsmith_plugin.py bridges that gap by entering langsmith.run_helpers.tracing_context for the duration of the test session. It only activates when GITHUB_ACTIONS=true, so local development is unaffected. Auto-discovered via the pytest11 entry point in any package that depends on langchain-tests.

Unit test isolation: Unit tests must never make network calls or send traces. The make test target in the libs/core Makefile uses env -u to unset the tracing vars (LANGCHAIN_TRACING_V2, LANGCHAIN_API_KEY, LANGSMITH_API_KEY, LANGSMITH_TRACING, LANGCHAIN_PROJECT) before running pytest. Additionally, libs/core/tests/unit_tests/runnables/conftest.py has a session-scoped autouse fixture that explicitly disables tracing for runnable unit tests, restoring the original environment afterward.

Adding a new partner to CI

When adding a new partner package, update these files:

  • .github/ISSUE_TEMPLATE/*.yml – Add to package dropdown
  • .github/dependabot.yml – Add dependency update entry
  • .github/scripts/pr-labeler-config.json – Add file rule and scope-to-label mapping
  • .github/workflows/_release.yml – Add API key secrets if needed
  • .github/workflows/auto-label-by-package.yml – Add package label
  • .github/workflows/check_diffs.yml – Add to change detection
  • .github/workflows/integration_tests.yml – Add integration test config
  • .github/workflows/pr_lint.yml – Add to allowed scopes

GitHub Actions & Workflows

This repository requires actions to be pinned to a full-length commit SHA. Attempting to use a tag will fail. Use the gh cli to query. Verify tags are not annotated tag objects (which would need dereferencing).

Additional resources

<!-- OPENWIKI:START -->

OpenWiki

This repository has a generated openwiki/ evidence index. It is optional just-in-time context, not required startup reading.

  • Treat source code and tests as authoritative. A brief's unknowns and review items are verification gaps, not automatic requirements.
  • Prefer the narrowest quiet validation that proves the changed behavior. Preserve complete failure output.

The scheduled OpenWiki GitHub Actions workflow refreshes the repository wiki. Do not hand-edit generated OpenWiki pages unless explicitly asked; prefer updating source code/docs and letting OpenWiki regenerate.

<!-- OPENWIKI:END -->

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.