feat(agent): implement user interruption handling in agent execution

This commit is contained in:
0xallam
2026-01-06 16:44:22 -08:00
committed by Ahmed Allam
parent 0954ac208f
commit 48fb48dba3
3 changed files with 58 additions and 2 deletions
+15
View File
@@ -34,6 +34,7 @@ class Tracer:
self.tool_executions: dict[int, dict[str, Any]] = {}
self.chat_messages: list[dict[str, Any]] = []
self.streaming_content: dict[str, str] = {}
self.interrupted_content: dict[str, str] = {}
self.vulnerability_reports: list[dict[str, Any]] = []
self.final_scan_result: str | None = None
@@ -343,5 +344,19 @@ class Tracer:
def get_streaming_content(self, agent_id: str) -> str | None:
return self.streaming_content.get(agent_id)
def finalize_streaming_as_interrupted(self, agent_id: str) -> str | None:
content = self.streaming_content.pop(agent_id, None)
if content and content.strip():
self.interrupted_content[agent_id] = content
self.log_chat_message(
content=content,
role="assistant",
agent_id=agent_id,
metadata={"interrupted": True},
)
return content
return self.interrupted_content.pop(agent_id, None)
def cleanup(self) -> None:
self.save_run_data(mark_complete=True)