Page Refresh now restarts agent loop if status is STOPPED or ERROR (#6829)

This commit is contained in:
tofarr
2025-02-27 12:34:16 -07:00
committed by GitHub
parent 616ff49787
commit ce30d63510
4 changed files with 14 additions and 6 deletions

View File

@@ -121,7 +121,7 @@ class DockerRuntime(ActionExecutionClient):
'error',
f'Container {self.container_name} not found.',
)
raise e
raise AgentRuntimeDisconnectedError from e
if self.runtime_container_image is None:
if self.base_container_image is None:
raise ValueError(

View File

@@ -10,6 +10,7 @@ from openhands.core.exceptions import AgentRuntimeUnavailableError
from openhands.core.logger import openhands_logger as logger
from openhands.core.schema.agent import AgentState
from openhands.events.action import MessageAction
from openhands.events.observation.agent import AgentStateChangedObservation
from openhands.events.stream import EventStream, session_exists
from openhands.server.monitoring import MonitoringListener
from openhands.server.session.agent_session import WAIT_TIME_BEFORE_CLOSE
@@ -99,6 +100,15 @@ class StandaloneConversationManager(ConversationManager):
event_stream = await self._get_event_stream(sid)
if not event_stream:
return await self.maybe_start_agent_loop(sid, settings, user_id)
for event in event_stream.get_events(reverse=True):
if isinstance(event, AgentStateChangedObservation):
if event.agent_state in (
AgentState.STOPPED.value,
AgentState.ERROR.value,
):
await self.close_session(sid)
return await self.maybe_start_agent_loop(sid, settings, user_id)
break
return event_stream
async def detach_from_conversation(self, conversation: Conversation):

View File

@@ -175,10 +175,6 @@ class AgentSession:
if self.security_analyzer is not None:
await self.security_analyzer.close()
async def stop_agent_loop_for_error(self):
if self.controller is not None:
await self.controller.set_agent_state_to(AgentState.ERROR)
def _create_security_analyzer(self, security_analyzer: str | None):
"""Creates a SecurityAnalyzer instance that will be used to analyze the agent actions

View File

@@ -247,7 +247,9 @@ class Session:
async def _send_status_message(self, msg_type: str, id: str, message: str):
"""Sends a status message to the client."""
if msg_type == 'error':
await self.agent_session.stop_agent_loop_for_error()
controller = self.agent_session.controller
if controller is not None:
await controller.set_agent_state_to(AgentState.ERROR)
await self.send(
{'status_update': True, 'type': msg_type, 'id': id, 'message': message}
)