Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Fix run finish handling
Tomas Valentae16d0caf7f81
diff --git a/api-service/agent/base.py b/api-service/agent/base.pyindex 6016c9a18..48a636fa8 100644--- a/api-service/agent/base.py+++ b/api-service/agent/base.py@@ -152,10 +152,10 @@ class AgentRun:# -----# Create log handlers# Used for sending logs to db/frontend without blocking- steps_ws_streamer = WorkQueue[List[Step]](+ ws_streamer = WorkQueue[List[Step]](on_workload=lambda steps: self._notify("steps", {"steps": steps}))- steps_db_streamer = WorkQueue[List[Step]](+ db_streamer = WorkQueue[List[Step]](on_workload=lambda steps: db.upsert_deployment_steps(run_id=self.run_id,steps=steps,@@ -164,8 +164,8 @@ class AgentRun:)def stream_steps(steps: List[Step]):- steps_db_streamer.schedule(steps)- steps_ws_streamer.schedule(steps)+ db_streamer.schedule(steps)+ ws_streamer.schedule(steps)# Used for parsing token stream into logs+actionsself._output_parser = OutputStreamParser(tool_names=self.tool_names)@@ -228,7 +228,6 @@ class AgentRun:breakawait self._check_interrupt()- # Process logs in a separate tasksteps = self._output_parser.ingest_token(token).get_steps()stream_steps(steps)@@ -267,6 +266,7 @@ class AgentRun:finally:if playground is not None:playground.close()+ await self._close()async def _check_interrupt(self):if self.canceled:diff --git a/api-service/agent/output/output_stream_parser.py b/api-service/agent/output/output_stream_parser.pyindex 8481131a6..43ab30685 100644--- a/api-service/agent/output/output_stream_parser.py+++ b/api-service/agent/output/output_stream_parser.py@@ -76,7 +76,7 @@ class OutputStreamParser:buffered_step=Step(output="", logs=[]),) -> None:self._tool_names = tool_names- self.id = uuid.uuid4()+# All "finished" logs that the parser saved.self._steps = steps[:]@@ -87,7 +87,7 @@ class OutputStreamParser:# They are flushed to self._logs after outputs for all tools in self._logs.buffer are ingested.self._logs_buffer: List[ToolLog | ThoughtLog] = buffered_step["logs"]self._logs_meta_buffer: List[LogMeta] = [- LogMeta(created_at=log.get("created_at", ""), id=log.get("id", ""))+ LogMeta(created_at=log.get[str]("created_at", ""), id=log.get("id", ""))for log in self._logs_buffer]