feat: add tool-level file cache with LRU eviction and mtime invalidation
Introduces FileCache (OrderedDict LRU, st_mtime_ns validation) to avoid redundant disk reads and duplicate content in conversation context. Read tools return a short "[Cached]" message on cache hit instead of resending unchanged file content, saving tokens. Write/edit/delete tools invalidate affected paths; str_replace pre-warms the cache after edits. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -73,11 +73,19 @@ class ShellToolConfig(BaseModel):
|
||||
max_output_bytes: int = Field(default=65536, description="Max output capture size in bytes")
|
||||
|
||||
|
||||
class FileCacheConfig(BaseModel):
|
||||
"""File cache configuration."""
|
||||
|
||||
enabled: bool = Field(default=True, description="Enable file content caching")
|
||||
max_entries: int = Field(default=128, description="Maximum cached file entries (LRU eviction)")
|
||||
|
||||
|
||||
class FilesystemToolConfig(BaseModel):
|
||||
"""Filesystem tool limits."""
|
||||
|
||||
max_file_size_bytes: int = Field(default=1_048_576, description="Max file size for read/write")
|
||||
binary_detection: bool = Field(default=True, description="Detect and reject binary files")
|
||||
cache: FileCacheConfig = Field(default_factory=FileCacheConfig, description="File cache settings")
|
||||
|
||||
|
||||
class ToolsConfig(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user