Skip to content

Commit 34de8ec

Browse files
eyurtsevnfcampos
andauthored
feat(anthropic): add more anthropic middleware (#33510)
Middleware Classes Text Editor Tools - StateClaudeTextEditorToolMiddleware: In-memory text editor using agent state - FilesystemClaudeTextEditorToolMiddleware: Text editor operating on real filesystem Implementing Claude's text editor tools https://docs.claude.com/en/docs/agents-and-tools/tool-use/text-editor-tool Operations: view, create, str_replace, insert Memory Tools - StateClaudeMemoryToolMiddleware: Memory persistence in agent state - FilesystemClaudeMemoryToolMiddleware: Memory persistence on filesystem Implementing Claude's memory tools https://docs.claude.com/en/docs/agents-and-tools/tool-use/memory-tool Operations: Same as text editor plus delete and rename File Search Tools - StateFileSearchMiddleware: Search state-based files Provides Glob and Grep tools with same schema as used by Claude Code (but compatible with any model) - Glob: Pattern matching (e.g., **/*.py, src/**/*.ts), sorted by modification time - Grep: Regex content search with output modes (files_with_matches, content, count) Usage ``` from langchain.agents import create_agent from langchain.agents.middleware import ( StateTextEditorToolMiddleware, StateFileSearchMiddleware, ) agent = create_agent( model=model, tools=[], middleware=[ StateTextEditorToolMiddleware(), StateFileSearchMiddleware(), ], ) ``` --------- Co-authored-by: Nuno Campos <[email protected]>
1 parent 3d288fd commit 34de8ec

File tree

6 files changed

+2462
-169
lines changed

6 files changed

+2462
-169
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
"""Middleware for Anthropic models."""
22

3+
from langchain_anthropic.middleware.anthropic_tools import (
4+
FilesystemClaudeMemoryMiddleware,
5+
FilesystemClaudeTextEditorMiddleware,
6+
StateClaudeMemoryMiddleware,
7+
StateClaudeTextEditorMiddleware,
8+
)
9+
from langchain_anthropic.middleware.file_search import (
10+
StateFileSearchMiddleware,
11+
)
312
from langchain_anthropic.middleware.prompt_caching import (
413
AnthropicPromptCachingMiddleware,
514
)
615

716
__all__ = [
817
"AnthropicPromptCachingMiddleware",
18+
"FilesystemClaudeMemoryMiddleware",
19+
"FilesystemClaudeTextEditorMiddleware",
20+
"StateClaudeMemoryMiddleware",
21+
"StateClaudeTextEditorMiddleware",
22+
"StateFileSearchMiddleware",
923
]

0 commit comments

Comments
 (0)