linuztx commited on
Commit
6f575da
·
1 Parent(s): ab0453b

CET capture partial tool output on intervention

Browse files
agent.py CHANGED
@@ -260,6 +260,7 @@ class LoopData:
260
  self.last_response = ""
261
  self.params_temporary: dict = {}
262
  self.params_persistent: dict = {}
 
263
 
264
  # override values with kwargs
265
  for key, value in kwargs.items():
@@ -714,6 +715,13 @@ class Agent:
714
  ): # if there is an intervention message, but not yet processed
715
  msg = self.intervention
716
  self.intervention = None # reset the intervention message
 
 
 
 
 
 
 
717
  if progress.strip():
718
  self.hist_add_ai_response(progress)
719
  # append the intervention message
@@ -766,27 +774,30 @@ class Agent:
766
  )
767
 
768
  if tool:
769
- await self.handle_intervention()
770
-
771
-
772
- # Call tool hooks for compatibility
773
- await tool.before_execution(**tool_args)
774
- await self.handle_intervention()
775
-
776
- # Allow extensions to preprocess tool arguments
777
- await self.call_extensions("tool_execute_before", tool_args=tool_args or {}, tool_name=tool_name)
778
-
779
- response = await tool.execute(**tool_args)
780
- await self.handle_intervention()
781
-
782
- # Allow extensions to postprocess tool response
783
- await self.call_extensions("tool_execute_after", response=response, tool_name=tool_name)
784
-
785
- await tool.after_execution(response)
786
- await self.handle_intervention()
787
-
788
- if response.break_loop:
789
- return response.message
 
 
 
790
  else:
791
  error_detail = (
792
  f"Tool '{raw_tool_name}' not found or could not be initialized."
 
260
  self.last_response = ""
261
  self.params_temporary: dict = {}
262
  self.params_persistent: dict = {}
263
+ self.current_tool = None
264
 
265
  # override values with kwargs
266
  for key, value in kwargs.items():
 
715
  ): # if there is an intervention message, but not yet processed
716
  msg = self.intervention
717
  self.intervention = None # reset the intervention message
718
+ # If a tool was running, save its progress to history
719
+ last_tool = self.loop_data.current_tool
720
+ if last_tool:
721
+ tool_progress = last_tool.progress.strip()
722
+ if tool_progress:
723
+ self.hist_add_tool_result(last_tool.name, tool_progress)
724
+ last_tool.set_progress(None)
725
  if progress.strip():
726
  self.hist_add_ai_response(progress)
727
  # append the intervention message
 
774
  )
775
 
776
  if tool:
777
+ self.loop_data.current_tool = tool # type: ignore
778
+ try:
779
+ await self.handle_intervention()
780
+
781
+ # Call tool hooks for compatibility
782
+ await tool.before_execution(**tool_args)
783
+ await self.handle_intervention()
784
+
785
+ # Allow extensions to preprocess tool arguments
786
+ await self.call_extensions("tool_execute_before", tool_args=tool_args or {}, tool_name=tool_name)
787
+
788
+ response = await tool.execute(**tool_args)
789
+ await self.handle_intervention()
790
+
791
+ # Allow extensions to postprocess tool response
792
+ await self.call_extensions("tool_execute_after", response=response, tool_name=tool_name)
793
+
794
+ await tool.after_execution(response)
795
+ await self.handle_intervention()
796
+
797
+ if response.break_loop:
798
+ return response.message
799
+ finally:
800
+ self.loop_data.current_tool = None
801
  else:
802
  error_detail = (
803
  f"Tool '{raw_tool_name}' not found or could not be initialized."
python/helpers/tool.py CHANGED
@@ -22,11 +22,20 @@ class Tool:
22
  self.args = args
23
  self.loop_data = loop_data
24
  self.message = message
 
25
 
26
  @abstractmethod
27
  async def execute(self,**kwargs) -> Response:
28
  pass
29
 
 
 
 
 
 
 
 
 
30
  async def before_execution(self, **kwargs):
31
  PrintStyle(font_color="#1B4F72", padding=True, background_color="white", bold=True).print(f"{self.agent.agent_name}: Using tool '{self.name}'")
32
  self.log = self.get_log_object()
 
22
  self.args = args
23
  self.loop_data = loop_data
24
  self.message = message
25
+ self.progress: str = ""
26
 
27
  @abstractmethod
28
  async def execute(self,**kwargs) -> Response:
29
  pass
30
 
31
+ def set_progress(self, content: str | None):
32
+ self.progress = content or ""
33
+
34
+ def add_progress(self, content: str | None):
35
+ if not content:
36
+ return
37
+ self.progress += content
38
+
39
  async def before_execution(self, **kwargs):
40
  PrintStyle(font_color="#1B4F72", padding=True, background_color="white", bold=True).print(f"{self.agent.agent_name}: Using tool '{self.name}'")
41
  self.log = self.get_log_object()
python/tools/code_execution_tool.py CHANGED
@@ -277,6 +277,7 @@ class CodeExecution(Tool):
277
  PrintStyle(font_color="#85C1E9").stream(partial_output)
278
  # full_output += partial_output # Append new output
279
  truncated_output = self.fix_full_output(full_output)
 
280
  heading = self.get_heading_from_output(truncated_output, 0)
281
  self.log.update(content=prefix + truncated_output, heading=heading)
282
  last_output_time = now
@@ -383,6 +384,7 @@ class CodeExecution(Tool):
383
  timeout=1, reset_full_output=reset_full_output
384
  )
385
  truncated_output = self.fix_full_output(full_output)
 
386
  heading = self.get_heading_from_output(truncated_output, 0)
387
 
388
  last_lines = (
 
277
  PrintStyle(font_color="#85C1E9").stream(partial_output)
278
  # full_output += partial_output # Append new output
279
  truncated_output = self.fix_full_output(full_output)
280
+ self.set_progress(truncated_output)
281
  heading = self.get_heading_from_output(truncated_output, 0)
282
  self.log.update(content=prefix + truncated_output, heading=heading)
283
  last_output_time = now
 
384
  timeout=1, reset_full_output=reset_full_output
385
  )
386
  truncated_output = self.fix_full_output(full_output)
387
+ self.set_progress(truncated_output)
388
  heading = self.get_heading_from_output(truncated_output, 0)
389
 
390
  last_lines = (