mirror of
https://github.com/NCBM/plyngent.git
synced 2026-07-23 05:55:16 +08:00
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:
@@ -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 = (
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user