Skip to content

Trace

autogen.beta.eval.trace.Trace #

Trace(*, events, exception, duration_ms)

Read-only view of one captured eval run.

Scorers receive a Trace through the trace parameter (resolved by name by the @scorer decorator). Use :meth:events_of to filter by event type, and :attr:tokens / :attr:duration_ms / :attr:exception for run-level signals.

Trace is constructed by the eval runner and has no equivalent inside autogen.beta itself — it is an eval-only view object.

Source code in autogen/beta/eval/trace.py
def __init__(
    self,
    *,
    events: Iterable[BaseEvent],
    exception: BaseException | None,
    duration_ms: int,
) -> None:
    self._events: tuple[BaseEvent, ...] = tuple(events)
    self._exception = exception
    self._duration_ms = duration_ms

events property #

events

Every event emitted on the agent's stream during this task, in order.

exception property #

exception

Exception raised by agent.ask(...), or None on clean completion.

duration_ms property #

duration_ms

Wall-clock duration of the task, in milliseconds.

tokens property #

tokens

Token counts summed across every :class:ModelResponse in this run.

events_of #

events_of(event_type, *, name=None)

Return events matching event_type (and optionally .name).

isinstance is used to test the type, so subclasses match too. When name is supplied, only events whose .name attribute equals it are returned — useful for tool events::

trace.events_of(ToolCallEvent, name="get_weather")

Events without a name attribute are excluded when name is set.

RETURNS DESCRIPTION
tuple[_E, ...]

A tuple preserving original event order.

Source code in autogen/beta/eval/trace.py
def events_of(
    self,
    event_type: type[_E],
    *,
    name: str | None = None,
) -> tuple[_E, ...]:
    """Return events matching ``event_type`` (and optionally ``.name``).

    ``isinstance`` is used to test the type, so subclasses match too.
    When ``name`` is supplied, only events whose ``.name`` attribute
    equals it are returned — useful for tool events::

        trace.events_of(ToolCallEvent, name="get_weather")

    Events without a ``name`` attribute are excluded when ``name`` is set.

    Returns:
        A tuple preserving original event order.
    """
    if name is None:
        return tuple(e for e in self._events if isinstance(e, event_type))
    return tuple(e for e in self._events if isinstance(e, event_type) and getattr(e, "name", None) == name)