CET capture partial tool output on intervention
linuztx committed
Oct 10, 2025 at 09:40 UTC
5ef854f23d57b9eba0cffb443c61c74832ccadd0
3 files changed
+43
-21
agent.py
+32
-21
@@ -260,6 +260,7 @@ class LoopData:
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():
@@ -714,6 +715,13 @@ class Agent:
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
@@ -766,27 +774,30 @@ class Agent:
774
)
775
776
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
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
+9
@@ -22,11 +22,20 @@ class Tool:
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
+2
@@ -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
+ 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
@@ -383,6 +384,7 @@ class CodeExecution(Tool):
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 = (