11"""Langchain tools for workspace operations."""
22
33from collections .abc import Callable
4- from typing import Annotated , ClassVar , Literal , Optional
4+ from typing import ClassVar , Literal
55
6- from langchain_core .messages import ToolMessage
7- from langchain_core .tools import InjectedToolCallId
86from langchain_core .tools .base import BaseTool
97from pydantic import BaseModel , Field
108
@@ -54,11 +52,10 @@ class ViewFileInput(BaseModel):
5452 """Input for viewing a file."""
5553
5654 filepath : str = Field (..., description = "Path to the file relative to workspace root" )
57- start_line : Optional [int ] = Field (None , description = "Starting line number to view (1-indexed, inclusive)" )
58- end_line : Optional [int ] = Field (None , description = "Ending line number to view (1-indexed, inclusive)" )
59- max_lines : Optional [int ] = Field (None , description = "Maximum number of lines to view at once, defaults to 250" )
60- line_numbers : Optional [bool ] = Field (True , description = "If True, add line numbers to the content (1-indexed)" )
61- tool_call_id : Annotated [str , InjectedToolCallId ]
55+ start_line : int | None = Field (None , description = "Starting line number to view (1-indexed, inclusive)" )
56+ end_line : int | None = Field (None , description = "Ending line number to view (1-indexed, inclusive)" )
57+ max_lines : int | None = Field (None , description = "Maximum number of lines to view at once, defaults to 250" )
58+ line_numbers : bool | None = Field (True , description = "If True, add line numbers to the content (1-indexed)" )
6259
6360
6461class ViewFileTool (BaseTool ):
@@ -76,13 +73,12 @@ def __init__(self, codebase: Codebase) -> None:
7673
7774 def _run (
7875 self ,
79- tool_call_id : str ,
8076 filepath : str ,
81- start_line : Optional [ int ] = None ,
82- end_line : Optional [ int ] = None ,
83- max_lines : Optional [ int ] = None ,
84- line_numbers : Optional [ bool ] = True ,
85- ) -> ToolMessage :
77+ start_line : int | None = None ,
78+ end_line : int | None = None ,
79+ max_lines : int | None = None ,
80+ line_numbers : bool | None = True ,
81+ ) -> str :
8682 result = view_file (
8783 self .codebase ,
8884 filepath ,
@@ -92,15 +88,14 @@ def _run(
9288 max_lines = max_lines if max_lines is not None else 250 ,
9389 )
9490
95- return result .render (tool_call_id )
91+ return result .render ()
9692
9793
9894class ListDirectoryInput (BaseModel ):
9995 """Input for listing directory contents."""
10096
10197 dirpath : str = Field (default = "./" , description = "Path to directory relative to workspace root" )
10298 depth : int = Field (default = 1 , description = "How deep to traverse. Use -1 for unlimited depth." )
103- tool_call_id : Annotated [str , InjectedToolCallId ]
10499
105100
106101class ListDirectoryTool (BaseTool ):
@@ -114,9 +109,9 @@ class ListDirectoryTool(BaseTool):
114109 def __init__ (self , codebase : Codebase ) -> None :
115110 super ().__init__ (codebase = codebase )
116111
117- def _run (self , tool_call_id : str , dirpath : str = "./" , depth : int = 1 ) -> ToolMessage :
112+ def _run (self , dirpath : str = "./" , depth : int = 1 ) -> str :
118113 result = list_directory (self .codebase , dirpath , depth )
119- return result .render (tool_call_id )
114+ return result .render ()
120115
121116
122117class SearchInput (BaseModel ):
@@ -131,7 +126,6 @@ class SearchInput(BaseModel):
131126 page : int = Field (default = 1 , description = "Page number to return (1-based, default: 1)" )
132127 files_per_page : int = Field (default = 10 , description = "Number of files to return per page (default: 10)" )
133128 use_regex : bool = Field (default = False , description = "Whether to treat query as a regex pattern (default: False)" )
134- tool_call_id : Annotated [str , InjectedToolCallId ]
135129
136130
137131class SearchTool (BaseTool ):
@@ -145,17 +139,16 @@ class SearchTool(BaseTool):
145139 def __init__ (self , codebase : Codebase ) -> None :
146140 super ().__init__ (codebase = codebase )
147141
148- def _run (self , tool_call_id : str , query : str , file_extensions : Optional [ list [str ]] = None , page : int = 1 , files_per_page : int = 10 , use_regex : bool = False ) -> ToolMessage :
142+ def _run (self , query : str , file_extensions : list [str ] | None = None , page : int = 1 , files_per_page : int = 10 , use_regex : bool = False ) -> str :
149143 result = search (self .codebase , query , file_extensions = file_extensions , page = page , files_per_page = files_per_page , use_regex = use_regex )
150- return result .render (tool_call_id )
144+ return result .render ()
151145
152146
153147class EditFileInput (BaseModel ):
154148 """Input for editing a file."""
155149
156150 filepath : str = Field (..., description = "Path to the file to edit" )
157151 content : str = Field (..., description = "New content for the file" )
158- tool_call_id : Annotated [str , InjectedToolCallId ]
159152
160153
161154class EditFileTool (BaseTool ):
@@ -188,9 +181,9 @@ class EditFileTool(BaseTool):
188181 def __init__ (self , codebase : Codebase ) -> None :
189182 super ().__init__ (codebase = codebase )
190183
191- def _run (self , filepath : str , content : str , tool_call_id : str ) -> str :
184+ def _run (self , filepath : str , content : str ) -> str :
192185 result = edit_file (self .codebase , filepath , content )
193- return result .render (tool_call_id )
186+ return result .render ()
194187
195188
196189class CreateFileInput (BaseModel ):
@@ -347,7 +340,6 @@ class SemanticEditInput(BaseModel):
347340 edit_content : str = Field (..., description = FILE_EDIT_PROMPT )
348341 start : int = Field (default = 1 , description = "Starting line number (1-indexed, inclusive). Default is 1." )
349342 end : int = Field (default = - 1 , description = "Ending line number (1-indexed, inclusive). Default is -1 (end of file)." )
350- tool_call_id : Annotated [str , InjectedToolCallId ]
351343
352344
353345class SemanticEditTool (BaseTool ):
@@ -361,10 +353,10 @@ class SemanticEditTool(BaseTool):
361353 def __init__ (self , codebase : Codebase ) -> None :
362354 super ().__init__ (codebase = codebase )
363355
364- def _run (self , filepath : str , tool_call_id : str , edit_content : str , start : int = 1 , end : int = - 1 ) -> ToolMessage :
356+ def _run (self , filepath : str , edit_content : str , start : int = 1 , end : int = - 1 ) -> str :
365357 # Create the the draft editor mini llm
366358 result = semantic_edit (self .codebase , filepath , edit_content , start = start , end = end )
367- return result .render (tool_call_id )
359+ return result .render ()
368360
369361
370362class RenameFileInput (BaseModel ):
0 commit comments