Home / Function/ files_reducer() — langchain Function Reference

files_reducer() — langchain Function Reference

Architecture documentation for the files_reducer() function in anthropic_tools.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  9c64aef2_9f69_3011_0f8b_e50a4e374b8e["files_reducer()"]
  19f1d717_5fcb_e619_f4a8_c2fc5a4421aa["anthropic_tools.py"]
  9c64aef2_9f69_3011_0f8b_e50a4e374b8e -->|defined in| 19f1d717_5fcb_e619_f4a8_c2fc5a4421aa
  style 9c64aef2_9f69_3011_0f8b_e50a4e374b8e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py lines 60–83

def files_reducer(
    left: dict[str, FileData] | None, right: dict[str, FileData | None]
) -> dict[str, FileData]:
    """Custom reducer that merges file updates.

    Args:
        left: Existing files dict.
        right: New files dict to merge (`None` values delete files).

    Returns:
        Merged `dict` where right overwrites left for matching keys.
    """
    if left is None:
        # Filter out None values when initializing
        return {k: v for k, v in right.items() if v is not None}

    # Merge, filtering out None values (deletions)
    result = {**left}
    for k, v in right.items():
        if v is None:
            result.pop(k, None)
        else:
            result[k] = v
    return result

Domain

Subdomains

Frequently Asked Questions

What does files_reducer() do?
files_reducer() is a function in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py.
Where is files_reducer() defined?
files_reducer() is defined in libs/partners/anthropic/langchain_anthropic/middleware/anthropic_tools.py at line 60.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free