core/agent: enrich ErrorEvent and CancelledEvent metadata

Add retryable/source on errors and optional reason on cancel; show them
in the CLI renderer.
This commit is contained in:
2026-07-14 23:42:44 +08:00
parent bcfd1098f8
commit 1da3e92f7c
2 changed files with 13 additions and 3 deletions
+3 -1
View File
@@ -30,10 +30,12 @@ class MaxRoundsEvent(Struct, tag_field="type", tag="max_rounds"):
class ErrorEvent(Struct, tag_field="type", tag="error"):
message: str
retryable: bool = True
source: str = ""
class CancelledEvent(Struct, tag_field="type", tag="cancelled"):
pass
reason: str = ""
type AgentEvent = (
+9 -1
View File
@@ -52,8 +52,16 @@ async def render_events(events: AsyncIterator[AgentEvent]) -> None: # noqa: C90
one_line = preview.replace("\n", " ")
click.secho(f"[tool ok] {one_line}", fg="magenta")
elif isinstance(event, ErrorEvent):
click.secho(f"\n[error] {event.message}", fg="bright_red")
suffix = ""
if event.source:
suffix += f" source={event.source}"
if not event.retryable:
suffix += " (fatal)"
click.secho(f"\n[error]{suffix} {event.message}", fg="bright_red")
elif isinstance(event, CancelledEvent):
if event.reason:
click.secho(f"\n[cancelled] {event.reason}", fg="yellow")
else:
click.secho("\n[cancelled]", fg="yellow")
elif isinstance(event, MaxRoundsEvent):
if event.continued: