langchain-ai/langchain
langchain-anthropic
The Anthropic (Claude) integration. Source: libs/partners/anthropic/langchain_anthropic/. PyPI: langchain-anthropic. Current version: 1.4.2. ~17 source modules, ~5,800 lines.
What it ships
| Symbol | Purpose | File |
|---|---|---|
ChatAnthropic |
Claude chat client (Messages API, tool use, vision, computer use, streaming) | libs/partners/anthropic/langchain_anthropic/chat_models.py |
AnthropicLLM |
Legacy completions client | libs/partners/anthropic/langchain_anthropic/llms.py |
convert_to_anthropic_tool |
Helper to convert a LangChain BaseTool to Anthropic's tool schema |
libs/partners/anthropic/langchain_anthropic/chat_models.py |
experimental.py |
Experimental utilities (e.g. raw API access) | libs/partners/anthropic/langchain_anthropic/experimental.py |
Directory layout
libs/partners/anthropic/langchain_anthropic/
├── __init__.py
├── _client_utils.py # Retry/timeout helpers
├── _compat.py # Content-block translators
├── _version.py # __version__
├── chat_models.py # ChatAnthropic itself (~92 KB)
├── data/ # Model profiles
├── experimental.py # Experimental APIs (~4.5 KB)
├── llms.py # AnthropicLLM (~15 KB)
├── middleware/ # Claude-specific middleware (e.g. cache control)
├── output_parsers.py # Anthropic-specific parsers
└── tools/ # Anthropic-shaped toolsWhat ChatAnthropic covers
chat_models.py (~2,200 lines) implements the Anthropic Messages API surface:
- Tool use with
tools=.... Supports parallel tool calls, tool choice (auto,any, named), and JSON-mode schema validation. - Computer use — Anthropic's bash, text editor, and computer tools. The model emits structured tool calls; LangChain renders them as
ServerToolCallblocks when appropriate. - Vision via Anthropic's image content blocks, translated to LangChain's
ImageContentBlock. - Streaming with delta events for text, tool input, and
usageaccumulation. - Prompt caching via Anthropic's
cache_controlmarkers. Themiddleware/subdirectory has helpers for inserting them. - Reasoning from Claude's extended thinking models, mapped to
ReasoningContentBlock. - Citations mapped to LangChain's
Citationcontent block.
Model profiles
data/ ships one JSON file per Claude model family. Capability flags include:
context_window(typically 200K)max_output_tokenssupports_tool_choice,supports_parallel_tool_callssupports_visionsupports_extended_thinking(for reasoning-capable models)supports_prompt_caching
Refreshed via langchain-profiles refresh --provider anthropic --data-dir libs/partners/anthropic/langchain_anthropic/data.
Tests
- Unit tests under
tests/unit_tests/exercise message translation, cache-control insertion, tool conversion, and streaming chunk parsing. - Integration tests under
tests/integration_tests/run the fulllangchain_tests.integration_tests.ChatModelIntegrationTestssuite plus Anthropic-specific tests for prompt caching, computer use, and extended thinking. - VCR cassettes keep a deterministic replay of API interactions.
Integration points
- Imports
anthropic>=0.x,httpx. - Inherits from
langchain-corebase classes. - Registered in
_BUILTIN_PROVIDERSunder theanthropicandanthropic_bedrockkeys (the latter vialangchain-aws). - Used as the v1 reference implementation for several content-block types (notably
ReasoningContentBlockandCitation), which means changes here often propagate intolangchain-core.
Entry points for modification
- For new Claude features (new content type, new tool kind), edit
chat_models.pyand the translators in_compat.py. - For prompt-caching tweaks, look at
middleware/. - For new model support, add to
data/profile_augmentations.tomland run the profile refresh CLI.
Related
- partners/openai — companion partner, same standard tests
- primitives/messages — the content-block taxonomy
- packages/standard-tests
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.