ag-ui-protocol / ag-ui-protocol/ag-ui

AbstractAgent.onError uses hardcoded console.error, bypassing host application loggers

Đang mở
#2,360 3 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
15.9k
Fork
1.4k
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
163

Mô tả

## Problem

`AbstractAgent.onError` in `sdks/typescript/packages/client/src/agent/agent.ts` (line ~507) calls `console.error` directly:

```ts
console.error('Agent execution failed:', error)
```

This bypasses any structured logging the host application has configured (e.g. Winston, Pino, or other JSON loggers). When the error object contains a stack trace — as `MastraError` does — Node.js serialises it as a multi-line string, producing unstructured, multi-line log entries in log aggregation systems (e.g. Humio, Datadog, Splunk) that expect newline-delimited JSON.

## Impact

- Log aggregation pipelines that parse NDJSON receive broken, multi-line entries for every agent execution failure.
- The error is invisible to the host application's error tracking / alerting stack unless the host also intercepts `console.error` globally.
- There is no way to suppress or redirect these logs without monkey-patching the global `console`.

## Suggested fix

Expose a configurable `logger` option on `AbstractAgent` (or the `RunAgentInput` / constructor options) and use it inside `onError` instead of `console.error`. Falling back to `console.error` when no logger is provided keeps the current behaviour for users who have not opted in.

```ts
// example API
const agent = new MyAgent({ logger: myStructuredLogger });

// inside AbstractAgent.onError
(this.logger ?? console).error('Agent execution failed:', error)
```

Alternatively, an `onError` callback hook would give host applications the same control.

## Environment

- Package: `@ag-ui/client`
- Affected method: `AbstractAgent.onError`
- Node.js serialises objects passed to `console.error` using `util.inspect`, which expands stack traces across multiple lines.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.