From 1da3e92f7c0ffada8d5ff9cf5d7519663dac0757 Mon Sep 17 00:00:00 2001 From: worldmozara Date: Tue, 14 Jul 2026 23:42:44 +0800 Subject: [PATCH] core/agent: enrich ErrorEvent and CancelledEvent metadata Add retryable/source on errors and optional reason on cancel; show them in the CLI renderer. --- src/plyngent/agent/events.py | 4 +++- src/plyngent/cli/display.py | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/plyngent/agent/events.py b/src/plyngent/agent/events.py index 855accc..0825379 100644 --- a/src/plyngent/agent/events.py +++ b/src/plyngent/agent/events.py @@ -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 = ( diff --git a/src/plyngent/cli/display.py b/src/plyngent/cli/display.py index 1be30cb..3bd0a90 100644 --- a/src/plyngent/cli/display.py +++ b/src/plyngent/cli/display.py @@ -52,9 +52,17 @@ 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): - click.secho("\n[cancelled]", fg="yellow") + 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: click.secho(