# Middleware

> langchain_anthropic → Middleware

!!! note "Reference docs"

    This page contains **reference documentation** for Anthropic Middleware. See [the docs](https://docs.langchain.com/oss/python/langchain/middleware/built-in#anthropic) for conceptual guides, tutorials, and examples on using Anthropic Middleware.

Provider-specific middleware for Anthropic's Claude models:

| CLASS                                                                                                          | DESCRIPTION                                                               |
| -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| [`AnthropicPromptCachingMiddleware`](#langchain_anthropic.middleware.AnthropicPromptCachingMiddleware)         | Reduce costs by caching repetitive prompt prefixes                        |
| [`ClaudeBashToolMiddleware`](#langchain_anthropic.middleware.ClaudeBashToolMiddleware)                         | Execute Claude's native bash tool with local command execution            |
| [`StateClaudeTextEditorMiddleware`](#langchain_anthropic.middleware.StateClaudeTextEditorMiddleware)           | Provide Claude's text editor tool for state-based file editing            |
| [`FilesystemClaudeTextEditorMiddleware`](#langchain_anthropic.middleware.FilesystemClaudeTextEditorMiddleware) | Provide Claude's text editor tool for filesystem-based file editing       |
| [`StateClaudeMemoryMiddleware`](#langchain_anthropic.middleware.StateClaudeMemoryMiddleware)                   | Provide Claude's memory tool for state-based persistent agent memory      |
| [`FilesystemClaudeMemoryMiddleware`](#langchain_anthropic.middleware.FilesystemClaudeMemoryMiddleware)         | Provide Claude's memory tool for filesystem-based persistent agent memory |
| [`StateFileSearchMiddleware`](#langchain_anthropic.middleware.StateFileSearchMiddleware)                       | Search tools for state-based file systems                                 |

<!-- TODO: `ignore_init_summary` doesn't seem to work.  -->

<!-- `"^__init__$"` used to exclude everything other than `__init__` -->

## Classes

- [`AnthropicTool`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicTool)
- [`AnthropicContextOverflowError`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicContextOverflowError)
- [`AnthropicAuthenticationError`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicAuthenticationError)
- [`AnthropicPermissionDeniedError`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicPermissionDeniedError)
- [`AnthropicInvalidRequestError`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicInvalidRequestError)
- [`AnthropicModelNotFoundError`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicModelNotFoundError)
- [`AnthropicRateLimitError`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicRateLimitError)
- [`AnthropicAPIError`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicAPIError)
- [`AnthropicOverloadedError`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicOverloadedError)
- [`AnthropicConnectionError`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicConnectionError)
- [`AnthropicTimeoutError`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicTimeoutError)
- [`ChatAnthropic`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic)
- [`ToolsOutputParser`](https://reference.langchain.com/python/langchain-anthropic/output_parsers/ToolsOutputParser)
- [`AnthropicLLM`](https://reference.langchain.com/python/langchain-anthropic/llms/AnthropicLLM)
- [`FileData`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/FileData)
- [`AnthropicToolsState`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/AnthropicToolsState)
- [`StateClaudeTextEditorMiddleware`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/StateClaudeTextEditorMiddleware)
- [`StateClaudeMemoryMiddleware`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/StateClaudeMemoryMiddleware)
- [`FilesystemClaudeTextEditorMiddleware`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/FilesystemClaudeTextEditorMiddleware)
- [`FilesystemClaudeMemoryMiddleware`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/FilesystemClaudeMemoryMiddleware)
- [`ClaudeBashToolMiddleware`](https://reference.langchain.com/python/langchain-anthropic/middleware/bash/ClaudeBashToolMiddleware)
- [`StateFileSearchMiddleware`](https://reference.langchain.com/python/langchain-anthropic/middleware/file_search/StateFileSearchMiddleware)
- [`AnthropicPromptCachingMiddleware`](https://reference.langchain.com/python/langchain-anthropic/middleware/prompt_caching/AnthropicPromptCachingMiddleware)

## Functions

- [`convert_to_anthropic_tool()`](https://reference.langchain.com/python/langchain-anthropic/chat_models/convert_to_anthropic_tool)
- [`extract_tool_calls()`](https://reference.langchain.com/python/langchain-anthropic/output_parsers/extract_tool_calls)
- [`get_system_message()`](https://reference.langchain.com/python/langchain-anthropic/experimental/get_system_message)
- [`files_reducer()`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/files_reducer)
- [`file_tool()`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_StateClaudeFileToolMiddleware/__init__/file_tool)
- [`file_tool()`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_FilesystemClaudeFileToolMiddleware/__init__/file_tool)
- [`glob_search()`](https://reference.langchain.com/python/langchain-anthropic/middleware/file_search/StateFileSearchMiddleware/__init__/glob_search)
- [`grep_search()`](https://reference.langchain.com/python/langchain-anthropic/middleware/file_search/StateFileSearchMiddleware/__init__/grep_search)

## Modules

- [`langchain_anthropic`](https://reference.langchain.com/python/langchain-anthropic/langchain_anthropic)
- [`chat_models`](https://reference.langchain.com/python/langchain-anthropic/chat_models)
- [`output_parsers`](https://reference.langchain.com/python/langchain-anthropic/output_parsers)
- [`experimental`](https://reference.langchain.com/python/langchain-anthropic/experimental)
- [`llms`](https://reference.langchain.com/python/langchain-anthropic/llms)
- [`data`](https://reference.langchain.com/python/langchain-anthropic/data)
- [`middleware`](https://reference.langchain.com/python/langchain-anthropic/middleware)
- [`anthropic_tools`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools)
- [`bash`](https://reference.langchain.com/python/langchain-anthropic/middleware/bash)
- [`file_search`](https://reference.langchain.com/python/langchain-anthropic/middleware/file_search)
- [`prompt_caching`](https://reference.langchain.com/python/langchain-anthropic/middleware/prompt_caching)

## Constants

- [`name`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicTool/name)
- [`input_schema`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicTool/input_schema)
- [`description`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicTool/description)
- [`strict`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicTool/strict)
- [`cache_control`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicTool/cache_control)
- [`defer_loading`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicTool/defer_loading)
- [`input_examples`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicTool/input_examples)
- [`allowed_callers`](https://reference.langchain.com/python/langchain-anthropic/chat_models/AnthropicTool/allowed_callers)
- [`model_config`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/model_config)
- [`model`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/model)
- [`max_tokens`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/max_tokens)
- [`temperature`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/temperature)
- [`top_k`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/top_k)
- [`top_p`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/top_p)
- [`default_request_timeout`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/default_request_timeout)
- [`max_retries`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/max_retries)
- [`stop_sequences`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/stop_sequences)
- [`anthropic_api_url`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/anthropic_api_url)
- [`anthropic_api_key`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/anthropic_api_key)
- [`anthropic_proxy`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/anthropic_proxy)
- [`default_headers`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/default_headers)
- [`betas`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/betas)
- [`model_kwargs`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/model_kwargs)
- [`streaming`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/streaming)
- [`stream_usage`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/stream_usage)
- [`thinking`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/thinking)
- [`output_config`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/output_config)
- [`reasoning_effort`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/reasoning_effort)
- [`mcp_servers`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/mcp_servers)
- [`context_management`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/context_management)
- [`container`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/container)
- [`reuse_last_container`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/reuse_last_container)
- [`inference_geo`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/inference_geo)
- [`user_profile_id`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/user_profile_id)
- [`effort`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/effort)
- [`lc_secrets`](https://reference.langchain.com/python/langchain-anthropic/chat_models/ChatAnthropic/lc_secrets)
- [`type`](https://reference.langchain.com/python/langchain-anthropic/chat_models/_AnthropicToolUse/type)
- [`name`](https://reference.langchain.com/python/langchain-anthropic/chat_models/_AnthropicToolUse/name)
- [`input`](https://reference.langchain.com/python/langchain-anthropic/chat_models/_AnthropicToolUse/input)
- [`id`](https://reference.langchain.com/python/langchain-anthropic/chat_models/_AnthropicToolUse/id)
- [`caller`](https://reference.langchain.com/python/langchain-anthropic/chat_models/_AnthropicToolUse/caller)
- [`first_tool_only`](https://reference.langchain.com/python/langchain-anthropic/output_parsers/ToolsOutputParser/first_tool_only)
- [`args_only`](https://reference.langchain.com/python/langchain-anthropic/output_parsers/ToolsOutputParser/args_only)
- [`pydantic_schemas`](https://reference.langchain.com/python/langchain-anthropic/output_parsers/ToolsOutputParser/pydantic_schemas)
- [`model_config`](https://reference.langchain.com/python/langchain-anthropic/output_parsers/ToolsOutputParser/model_config)
- [`SYSTEM_PROMPT_FORMAT`](https://reference.langchain.com/python/langchain-anthropic/experimental/SYSTEM_PROMPT_FORMAT)
- [`TOOL_FORMAT`](https://reference.langchain.com/python/langchain-anthropic/experimental/TOOL_FORMAT)
- [`TOOL_PARAMETER_FORMAT`](https://reference.langchain.com/python/langchain-anthropic/experimental/TOOL_PARAMETER_FORMAT)
- [`logger`](https://reference.langchain.com/python/langchain-anthropic/_sdk_compat/logger)
- [`client`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/client)
- [`async_client`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/async_client)
- [`model`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/model)
- [`max_tokens`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/max_tokens)
- [`temperature`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/temperature)
- [`top_k`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/top_k)
- [`top_p`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/top_p)
- [`streaming`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/streaming)
- [`default_request_timeout`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/default_request_timeout)
- [`max_retries`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/max_retries)
- [`anthropic_api_url`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/anthropic_api_url)
- [`anthropic_api_key`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/anthropic_api_key)
- [`HUMAN_PROMPT`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/HUMAN_PROMPT)
- [`AI_PROMPT`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/AI_PROMPT)
- [`count_tokens`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/count_tokens)
- [`model_kwargs`](https://reference.langchain.com/python/langchain-anthropic/llms/_AnthropicCommon/model_kwargs)
- [`model_config`](https://reference.langchain.com/python/langchain-anthropic/llms/AnthropicLLM/model_config)
- [`lc_secrets`](https://reference.langchain.com/python/langchain-anthropic/llms/AnthropicLLM/lc_secrets)
- [`TEXT_EDITOR_TOOL_TYPE`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/TEXT_EDITOR_TOOL_TYPE)
- [`TEXT_EDITOR_TOOL_NAME`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/TEXT_EDITOR_TOOL_NAME)
- [`MEMORY_TOOL_TYPE`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/MEMORY_TOOL_TYPE)
- [`MEMORY_TOOL_NAME`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/MEMORY_TOOL_NAME)
- [`MEMORY_SYSTEM_PROMPT`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/MEMORY_SYSTEM_PROMPT)
- [`content`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/FileData/content)
- [`created_at`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/FileData/created_at)
- [`modified_at`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/FileData/modified_at)
- [`text_editor_files`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/AnthropicToolsState/text_editor_files)
- [`memory_files`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/AnthropicToolsState/memory_files)
- [`state_schema`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_StateClaudeFileToolMiddleware/state_schema)
- [`tool_type`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_StateClaudeFileToolMiddleware/tool_type)
- [`tool_name`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_StateClaudeFileToolMiddleware/tool_name)
- [`state_key`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_StateClaudeFileToolMiddleware/state_key)
- [`allowed_prefixes`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_StateClaudeFileToolMiddleware/allowed_prefixes)
- [`system_prompt`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_StateClaudeFileToolMiddleware/system_prompt)
- [`tools`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_StateClaudeFileToolMiddleware/tools)
- [`tool_type`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_FilesystemClaudeFileToolMiddleware/tool_type)
- [`tool_name`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_FilesystemClaudeFileToolMiddleware/tool_name)
- [`root_path`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_FilesystemClaudeFileToolMiddleware/root_path)
- [`allowed_prefixes`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_FilesystemClaudeFileToolMiddleware/allowed_prefixes)
- [`max_file_size_bytes`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_FilesystemClaudeFileToolMiddleware/max_file_size_bytes)
- [`system_prompt`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_FilesystemClaudeFileToolMiddleware/system_prompt)
- [`tools`](https://reference.langchain.com/python/langchain-anthropic/middleware/anthropic_tools/_FilesystemClaudeFileToolMiddleware/tools)
- [`BASH_TOOL_TYPE`](https://reference.langchain.com/python/langchain-anthropic/middleware/bash/BASH_TOOL_TYPE)
- [`BASH_TOOL_NAME`](https://reference.langchain.com/python/langchain-anthropic/middleware/bash/BASH_TOOL_NAME)
- [`state_schema`](https://reference.langchain.com/python/langchain-anthropic/middleware/file_search/StateFileSearchMiddleware/state_schema)
- [`state_key`](https://reference.langchain.com/python/langchain-anthropic/middleware/file_search/StateFileSearchMiddleware/state_key)
- [`glob_search`](https://reference.langchain.com/python/langchain-anthropic/middleware/file_search/StateFileSearchMiddleware/glob_search)
- [`grep_search`](https://reference.langchain.com/python/langchain-anthropic/middleware/file_search/StateFileSearchMiddleware/grep_search)
- [`tools`](https://reference.langchain.com/python/langchain-anthropic/middleware/file_search/StateFileSearchMiddleware/tools)
- [`msg`](https://reference.langchain.com/python/langchain-anthropic/middleware/prompt_caching/msg)
- [`trace_policy`](https://reference.langchain.com/python/langchain-anthropic/middleware/prompt_caching/AnthropicPromptCachingMiddleware/trace_policy)
- [`type`](https://reference.langchain.com/python/langchain-anthropic/middleware/prompt_caching/AnthropicPromptCachingMiddleware/type)
- [`ttl`](https://reference.langchain.com/python/langchain-anthropic/middleware/prompt_caching/AnthropicPromptCachingMiddleware/ttl)
- [`min_messages_to_cache`](https://reference.langchain.com/python/langchain-anthropic/middleware/prompt_caching/AnthropicPromptCachingMiddleware/min_messages_to_cache)
- [`unsupported_model_behavior`](https://reference.langchain.com/python/langchain-anthropic/middleware/prompt_caching/AnthropicPromptCachingMiddleware/unsupported_model_behavior)
