Open-Source Wikis

/

LangChain

/

Partners

/

langchain-anthropic

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 tools

What 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 ServerToolCall blocks when appropriate.
  • Vision via Anthropic's image content blocks, translated to LangChain's ImageContentBlock.
  • Streaming with delta events for text, tool input, and usage accumulation.
  • Prompt caching via Anthropic's cache_control markers. The middleware/ subdirectory has helpers for inserting them.
  • Reasoning from Claude's extended thinking models, mapped to ReasoningContentBlock.
  • Citations mapped to LangChain's Citation content block.

Model profiles

data/ ships one JSON file per Claude model family. Capability flags include:

  • context_window (typically 200K)
  • max_output_tokens
  • supports_tool_choice, supports_parallel_tool_calls
  • supports_vision
  • supports_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 full langchain_tests.integration_tests.ChatModelIntegrationTests suite 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-core base classes.
  • Registered in _BUILTIN_PROVIDERS under the anthropic and anthropic_bedrock keys (the latter via langchain-aws).
  • Used as the v1 reference implementation for several content-block types (notably ReasoningContentBlock and Citation), which means changes here often propagate into langchain-core.

Entry points for modification

  • For new Claude features (new content type, new tool kind), edit chat_models.py and the translators in _compat.py.
  • For prompt-caching tweaks, look at middleware/.
  • For new model support, add to data/profile_augmentations.toml and run the profile refresh CLI.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

langchain-anthropic – LangChain wiki | Factory