Skip to content

Commit 3aa647e

Browse files
tofarrenystopenhands-agent
authored
We now have an explicit ConversationErrorEvent in the stream (#1106)
Co-authored-by: enyst <engel.nyst@gmail.com> Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 06567f5 commit 3aa647e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
PauseEvent,
2424
UserRejectObservation,
2525
)
26+
from openhands.sdk.event.conversation_error import ConversationErrorEvent
2627
from openhands.sdk.llm import LLM, Message, TextContent
2728
from openhands.sdk.llm.llm_registry import LLMRegistry
2829
from openhands.sdk.logger import get_logger
@@ -312,6 +313,16 @@ def run(self) -> None:
312313
break
313314
except Exception as e:
314315
self._state.execution_status = ConversationExecutionStatus.ERROR
316+
317+
# Add an error event
318+
self._on_event(
319+
ConversationErrorEvent(
320+
source="environment",
321+
code=e.__class__.__name__,
322+
detail=str(e),
323+
)
324+
)
325+
315326
# Re-raise with conversation id for better UX; include original traceback
316327
raise ConversationRunError(self._state.id, e) from e
317328
finally:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from pydantic import Field
2+
3+
from openhands.sdk.event.base import Event
4+
5+
6+
class ConversationErrorEvent(Event):
7+
"""
8+
Conversation-level failure that is NOT sent back to the LLM.
9+
10+
This event is emitted by the conversation runtime when an unexpected
11+
exception bubbles up and prevents the run loop from continuing. It is
12+
intended for client applications (e.g., UIs) to present a top-level error
13+
state, and for orchestration to react. It is not an observation and it is
14+
not LLM-convertible.
15+
16+
Differences from AgentErrorEvent:
17+
- Not tied to any tool_name/tool_call_id (AgentErrorEvent is a tool
18+
observation).
19+
- Typically source='environment' and the run loop moves to an ERROR state,
20+
while AgentErrorEvent has source='agent' and the conversation can
21+
continue.
22+
"""
23+
24+
code: str = Field(description="Code for the error - typically a type")
25+
detail: str = Field(description="Details about the error")

0 commit comments

Comments
 (0)