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"):
|
class ErrorEvent(Struct, tag_field="type", tag="error"):
|
||||||
message: str
|
message: str
|
||||||
|
retryable: bool = True
|
||||||
|
source: str = ""
|
||||||
|
|
||||||
|
|
||||||
class CancelledEvent(Struct, tag_field="type", tag="cancelled"):
|
class CancelledEvent(Struct, tag_field="type", tag="cancelled"):
|
||||||
pass
|
reason: str = ""
|
||||||
|
|
||||||
|
|
||||||
type AgentEvent = (
|
type AgentEvent = (
|
||||||
|
|||||||
@@ -52,8 +52,16 @@ async def render_events(events: AsyncIterator[AgentEvent]) -> None: # noqa: C90
|
|||||||
one_line = preview.replace("\n", " ")
|
one_line = preview.replace("\n", " ")
|
||||||
click.secho(f"[tool ok] {one_line}", fg="magenta")
|
click.secho(f"[tool ok] {one_line}", fg="magenta")
|
||||||
elif isinstance(event, ErrorEvent):
|
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):
|
elif isinstance(event, CancelledEvent):
|
||||||
|
if event.reason:
|
||||||
|
click.secho(f"\n[cancelled] {event.reason}", fg="yellow")
|
||||||
|
else:
|
||||||
click.secho("\n[cancelled]", fg="yellow")
|
click.secho("\n[cancelled]", fg="yellow")
|
||||||
elif isinstance(event, MaxRoundsEvent):
|
elif isinstance(event, MaxRoundsEvent):
|
||||||
if event.continued:
|
if event.continued:
|
||||||
|
|||||||
Reference in New Issue
Block a user