From 9839f1222a29fc94a9353f533656a85e85242d7a Mon Sep 17 00:00:00 2001 From: Eugene Yurtsev Date: Tue, 4 Nov 2025 14:43:09 -0500 Subject: [PATCH] x --- libs/deepagents/backends/protocol.py | 23 +++++++++++++++++++++-- libs/deepagents/backends/utils.py | 28 +++++++--------------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/libs/deepagents/backends/protocol.py b/libs/deepagents/backends/protocol.py index 185d3ade..8cb529d9 100644 --- a/libs/deepagents/backends/protocol.py +++ b/libs/deepagents/backends/protocol.py @@ -7,11 +7,30 @@ from collections.abc import Callable from dataclasses import dataclass -from typing import Any, Protocol, TypeAlias, runtime_checkable +from typing import Any, Protocol, TypeAlias, TypedDict, runtime_checkable from langchain.tools import ToolRuntime -from deepagents.backends.utils import FileInfo, GrepMatch + +class FileInfo(TypedDict, total=False): + """Structured file listing info. + + Minimal contract used across backends. Only "path" is required. + Other fields are best-effort and may be absent depending on backend. + """ + + path: str + is_dir: bool + size: int # bytes (approx) + modified_at: str # ISO timestamp if known + + +class GrepMatch(TypedDict): + """Structured grep match entry.""" + + path: str + line: int + text: str @dataclass diff --git a/libs/deepagents/backends/utils.py b/libs/deepagents/backends/utils.py index c1aece0c..437c6f6d 100644 --- a/libs/deepagents/backends/utils.py +++ b/libs/deepagents/backends/utils.py @@ -8,36 +8,22 @@ import re from datetime import UTC, datetime from pathlib import Path -from typing import Any, Literal, TypedDict +from typing import Any, Literal import wcmatch.glob as wcglob +from deepagents.backends.protocol import FileInfo as _FileInfo +from deepagents.backends.protocol import GrepMatch as _GrepMatch + EMPTY_CONTENT_WARNING = "System reminder: File exists but has empty contents" MAX_LINE_LENGTH = 10000 LINE_NUMBER_WIDTH = 6 TOOL_RESULT_TOKEN_LIMIT = 20000 # Same threshold as eviction TRUNCATION_GUIDANCE = "... [results truncated, try being more specific with your parameters]" - -class FileInfo(TypedDict, total=False): - """Structured file listing info. - - Minimal contract used across backends. Only "path" is required. - Other fields are best-effort and may be absent depending on backend. - """ - - path: str - is_dir: bool - size: int # bytes (approx) - modified_at: str # ISO timestamp if known - - -class GrepMatch(TypedDict): - """Structured grep match entry.""" - - path: str - line: int - text: str +# Re-export protocol types for backwards compatibility +FileInfo = _FileInfo +GrepMatch = _GrepMatch def sanitize_tool_call_id(tool_call_id: str) -> str: