Skip to content

Commit 91a9086

Browse files
authored
fix: error handling in _resolve_final_data function (#169)
Signed-off-by: Frost Ming <me@frostming.com>
1 parent 8d0ae0b commit 91a9086

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/bub/builtin/agent.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
LLM,
2121
AsyncStreamEvents,
2222
AsyncTapeStore,
23+
RepublicError,
2324
StreamEvent,
2425
StreamState,
2526
TapeContext,
@@ -229,7 +230,7 @@ async def _stream_events_with_auto_handoff(
229230
},
230231
)
231232
elif event.kind == "final":
232-
outcome = _resolve_tool_auto_result(event.data)
233+
outcome = _resolve_final_data(event.data, output.error)
233234

234235
state.error = output.error
235236
state.usage = output.usage
@@ -363,12 +364,13 @@ class _ToolAutoOutcome:
363364
error: str = ""
364365

365366

366-
def _resolve_tool_auto_result(final_data: dict[str, Any]) -> _ToolAutoOutcome:
367+
def _resolve_final_data(final_data: dict[str, Any], error: RepublicError | None) -> _ToolAutoOutcome:
367368
if final_data.get("tool_calls") or final_data.get("tool_results"):
368369
return _ToolAutoOutcome(kind="continue")
369370
if (text := final_data.get("text")) is not None:
370371
return _ToolAutoOutcome(kind="text", text=text)
371-
return _ToolAutoOutcome(kind="error", error="unknown error")
372+
error_message = error.message if error else ""
373+
return _ToolAutoOutcome(kind="error", error=error_message or "unknown error")
372374

373375

374376
def _build_llm(settings: AgentSettings, tape_store: AsyncTapeStore, tape_context: TapeContext) -> LLM:

0 commit comments

Comments
 (0)