From cd6473aae82428b8934d23d3a11328d4430eb9ca Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Thu, 16 Apr 2026 09:20:32 +0800 Subject: [PATCH] fix: error handling in _resolve_final_data function Signed-off-by: Frost Ming --- src/bub/builtin/agent.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bub/builtin/agent.py b/src/bub/builtin/agent.py index 0eef3a7b..4b1180f4 100644 --- a/src/bub/builtin/agent.py +++ b/src/bub/builtin/agent.py @@ -20,6 +20,7 @@ LLM, AsyncStreamEvents, AsyncTapeStore, + RepublicError, StreamEvent, StreamState, TapeContext, @@ -229,7 +230,7 @@ async def _stream_events_with_auto_handoff( }, ) elif event.kind == "final": - outcome = _resolve_tool_auto_result(event.data) + outcome = _resolve_final_data(event.data, output.error) state.error = output.error state.usage = output.usage @@ -363,12 +364,13 @@ class _ToolAutoOutcome: error: str = "" -def _resolve_tool_auto_result(final_data: dict[str, Any]) -> _ToolAutoOutcome: +def _resolve_final_data(final_data: dict[str, Any], error: RepublicError | None) -> _ToolAutoOutcome: if final_data.get("tool_calls") or final_data.get("tool_results"): return _ToolAutoOutcome(kind="continue") if (text := final_data.get("text")) is not None: return _ToolAutoOutcome(kind="text", text=text) - return _ToolAutoOutcome(kind="error", error="unknown error") + error_message = error.message if error else "" + return _ToolAutoOutcome(kind="error", error=error_message or "unknown error") def _build_llm(settings: AgentSettings, tape_store: AsyncTapeStore, tape_context: TapeContext) -> LLM: