@@ -45,10 +45,20 @@ async def run_multi_agent(
4545 from grokcode .agent .grok_client import GrokClient
4646 from grokcode .agent .tool_registry import ToolRegistry
4747 from grokcode .tools .bash import BashTool
48- from grokcode .tools .fs import FS_TOOL_SCHEMAS , edit_file , glob_files , grep_files , read_directory , read_file , write_file
48+ from grokcode .tools .fs import (
49+ FS_TOOL_SCHEMAS ,
50+ edit_file ,
51+ glob_files ,
52+ grep_files ,
53+ read_directory ,
54+ read_file ,
55+ write_file ,
56+ )
4957 from grokcode .utils .ui import console
5058
51- async with GrokClient (api_key = api_key , model = config .model , max_tokens = config .max_tokens ) as client :
59+ async with GrokClient (
60+ api_key = api_key , model = config .model , max_tokens = config .max_tokens
61+ ) as client :
5262 # Step 1: Orchestrator decomposes the task
5363 console .print (" [cyan]●[/cyan] Orchestrator: decomposing task..." )
5464 subtasks = await _decompose_task (task , config , client )
@@ -84,17 +94,42 @@ async def locked_write_file(path: str, content: str) -> str:
8494
8595 async def run_subtask (subtask : SubtaskPlan ) -> list [str ]:
8696 async with semaphore :
87- console .print (f" [yellow]→[/yellow] Starting sub-agent: { subtask .description [:60 ]} " )
88- bash_tool = BashTool (auto_confirm = auto_confirm )
97+ console .print (
98+ f" [yellow]→[/yellow] Starting sub-agent: { subtask .description [:60 ]} "
99+ )
89100 registry = ToolRegistry ()
90101 registry .register ("read_file" , lambda path : read_file (path ), FS_TOOL_SCHEMAS [0 ])
91- registry .register ("read_directory" , lambda path , recursive = False : read_directory (path , recursive ), FS_TOOL_SCHEMAS [1 ])
92- registry .register ("write_file" , lambda path , content : locked_write_file (path , content ), FS_TOOL_SCHEMAS [2 ])
93- registry .register ("edit_file" , lambda path , old_str , new_str : locked_edit_file (path , old_str , new_str ), FS_TOOL_SCHEMAS [3 ])
94- registry .register ("glob_files" , lambda pattern , directory = "." : glob_files (pattern , directory ), FS_TOOL_SCHEMAS [5 ])
95- registry .register ("grep_files" , lambda pattern , directory = "." , file_glob = "**/*" : grep_files (pattern , directory , file_glob ), FS_TOOL_SCHEMAS [6 ])
96-
97- async with GrokClient (api_key = api_key , model = config .model , max_tokens = config .max_tokens ) as sub_client :
102+ registry .register (
103+ "read_directory" ,
104+ lambda path , recursive = False : read_directory (path , recursive ),
105+ FS_TOOL_SCHEMAS [1 ],
106+ )
107+ registry .register (
108+ "write_file" ,
109+ lambda path , content : locked_write_file (path , content ),
110+ FS_TOOL_SCHEMAS [2 ],
111+ )
112+ registry .register (
113+ "edit_file" ,
114+ lambda path , old_str , new_str : locked_edit_file (path , old_str , new_str ),
115+ FS_TOOL_SCHEMAS [3 ],
116+ )
117+ registry .register (
118+ "glob_files" ,
119+ lambda pattern , directory = "." : glob_files (pattern , directory ),
120+ FS_TOOL_SCHEMAS [5 ],
121+ )
122+ registry .register (
123+ "grep_files" ,
124+ lambda pattern , directory = "." , file_glob = "**/*" : grep_files (
125+ pattern , directory , file_glob
126+ ),
127+ FS_TOOL_SCHEMAS [6 ],
128+ )
129+
130+ async with GrokClient (
131+ api_key = api_key , model = config .model , max_tokens = config .max_tokens
132+ ) as sub_client :
98133 agent = Agent (config = config , tool_registry = registry , grok_client = sub_client )
99134 files : list [str ] = []
100135 async for event in agent .run (
@@ -105,7 +140,9 @@ async def run_subtask(subtask: SubtaskPlan) -> list[str]:
105140 if hasattr (event , "files_touched" ):
106141 files .extend (event .files_touched ) # type: ignore[attr-defined]
107142 if isinstance (event , DoneEvent ):
108- console .print (f" [green]✓[/green] Sub-agent done: { subtask .description [:50 ]} " )
143+ console .print (
144+ f" [green]✓[/green] Sub-agent done: { subtask .description [:50 ]} "
145+ )
109146 elif isinstance (event , ErrorEvent ):
110147 console .print (f" [red]✗[/red] Sub-agent error: { event .message [:80 ]} " )
111148 return files
@@ -165,7 +202,7 @@ async def _decompose_task(
165202 full_response += chunk .content
166203
167204 # Strip markdown fences
168- cleaned = re .sub (r"```(?:json)?\s*" , "" , full_response ).strip ().rstrip ("```" ).strip ()
205+ cleaned = re .sub (r"```(?:json)?\s*" , "" , full_response ).strip ().removesuffix ("```" ).strip ()
169206
170207 try :
171208 data = json .loads (cleaned )
0 commit comments