events

The bot’s output as the harness sees it.

EvalEventStream turns the frames the bot-facing transport produces into the events scenarios assert on, queues them for the matcher, and keeps the bookkeeping the rest of the harness reads: every event seen, when each event type last arrived (for send_after), and whether the bot’s next output is still the tail of an interrupted response.

The events, and the RTVI server messages the bot emits them as:

exception pipecat.evals.events.EvalBotEndedError[source]

Bases: Exception

The bot ended the call before the awaited event arrived, so it never will.

class pipecat.evals.events.EvalEventStream(*, bot_audio: bool, trace: EvalTrace)[source]

Bases: object

The bot’s output as events: a queue the drivers read, fed by the pipeline.

The sink turns each frame from the bot into an event and appends it; the drivers pop events as they wait for them. One rule runs through it: what the bot produced before the user’s latest send is not the reply to it. An LLM response still streaming at the send, or cut by an interruption, is dropped until the bot’s next llm-started, and a spoken turn that began before the send is dropped when it ends.

__init__(*, bot_audio: bool, trace: EvalTrace)[source]

Initialize the stream.

Parameters:
  • bot_audio – Whether the scenario runs in audio mode; tts_response is emitted only then.

  • trace – The run’s trace, where each event is logged as it arrives.

property bot_speaking: bool

Whether the bot reports itself speaking right now.

property talked_over_until: float | None

Monotonic time the bot started speaking again after the latest turn began.

The bot’s speech that began before then belongs to the turn before: what it was saying when a send talked over it, or the reply an observing turn waited out. Infinity until the bot starts speaking again, and None when the latest send did not talk over it.

property bot_transcribed: bool

Whether everything the bot has said is transcribed and closed into a turn.

property bot_has_ended: bool

Whether the bot ended the call (see bot_ended()).

property bot_speech_outstanding: str

What of the bot’s speech is not yet accounted for, for the trace.

async wait_bot_transcribed(timeout: float) → bool[source]

Wait for everything the bot has said to be transcribed and closed into a turn.

Parameters:

timeout – Seconds to wait at most.

Returns:

Whether the bot’s speech is fully accounted for, or False if some of it was still being transcribed at the timeout.

bot_segment_started() → None[source]

The VAD hears a segment of the bot’s speech.

bot_segment_ended() → None[source]

A segment of the bot’s speech ended and awaits transcription.

bot_segment_transcribed() → None[source]

A segment of the bot’s speech was transcribed, whether or not it yielded text.

bot_turn_started() → None[source]

The bot began a spoken turn.

bot_ended() → None[source]

The bot closed the connection: it sends nothing more, and is no longer speaking.

async wait_bot_quiet(timeout: float) → bool[source]

Wait for the bot to stop speaking.

Parameters:

timeout – Seconds to wait at most.

Returns:

Whether the bot is quiet, or False if it was still speaking at the timeout.

async append(event: dict) → None[source]

Queue an event for the drivers.

Stamps its arrival time as at (seconds since the stream began) unless it has one, records it, and logs it.

Parameters:

event – The event dict, with at least a type.

async next_any(deadline: float) → dict[source]

Pop the next queued event, whatever its type.

Parameters:

deadline – Monotonic time to give up at.

Returns:

The event.

Raises:

TimeoutError – If no event arrives before deadline.

property turn_position: int

where an expectation beginning now looks from.

Type:

How many events the turn has popped so far

begin_turn() → None[source]

Forget the events popped during the previous turn.

unclaimed_since(since: int) → list[dict][source]

The events popped from position since on that no expectation has claimed.

async next_event(event_type: str, deadline: float, *, since: int | None = None, accept: Callable[[dict], bool] | None = None) → dict[source]

The next unclaimed event of event_type that accept takes, looking from since.

The turn’s log is searched first, from since on, then the queue is popped until such an event arrives. Events popped on the way stay in the log, unclaimed: a scenario need not list every event the bot emits, and an expectation that looks back from an earlier point can still claim them. Every event stays in events_seen.

Parameters:
  • event_type – The event type to wait for.

  • deadline – Monotonic time to give up at.

  • since – Position in the turn’s log to look from; None looks only at what arrives from now on.

  • accept – A further check on an event of the type, such as a call’s name; one it turns down is left for another expectation.

Returns:

The event.

Raises:
  • TimeoutError – If none arrives before deadline.

  • EvalBotEndedError – If the bot ended the call and none is left to arrive. The harness’s transcription of what the bot said last (audio mode) is waited for first, since it can land after the bot is gone.

drop_pending_bot_output(why: str) → None[source]

Drop the bot’s queued output, so a later turn cannot match it.

A queued user_transcription stays: a DTMF keypress reports its transcription just before the turn starts, and that is the turn’s input, not stale bot output. events_seen and latest_event_times are left as they are.

Parameters:

why – What prompted the drop, for the trace.

elapsed() → float[source]

Seconds since the stream began, the clock the events’ at is on.

touch() → None[source]

Note activity that makes no event, so a lull is measured from it.

frame_to_event(frame: Frame) → dict | None[source]

Translate one frame from the bot into the event it maps to, if any.

The LLM text is buffered and emitted as one llm_response when the response ends; a marker is its own llm_marker as soon as it arrives; tts_response is emitted only in audio mode; the bot’s reports about the harness (its VAD, speaking, and transcription messages) become their events. The audio-mode response is not made here: the aggregator appends it when the bot’s spoken turn ends.

Parameters:

frame – A frame the bot-facing transport produced.

Returns:

The event the frame maps to, or None; most frames map to none.

property input_sent_at: float

Monotonic time of the user’s latest send; bot speech from before it is not the reply.

async bot_turn_stopped(text: str) → None[source]

Append the bot’s finished spoken turn as a response, unless it is stale.

Speech the bot was saying when a send talked over it never reaches a turn (the client drops it by its audio’s time). A turn is still stale while the bot’s LLM has not restarted since the send: the bot going on with what it was saying, which must not pass for the reply.

Parameters:

text – The turn’s transcription; nothing is appended when empty.

input_sent() → None[source]

Mark the user’s input as sent: the bot’s reply is what it says from now on.

turn_boundary() → None[source]

Start a new turn: only what the bot says from now on belongs to it.

When the bot is speaking at this point, the turn talks over it, and what the bot says until it starts speaking again, however late its transcription lands, is the previous turn’s and is discarded.

observing_boundary() → None[source]

Start a turn that sends nothing: what the bot says next belongs to it.

What the bot says until it starts speaking again, however late its transcription lands, is the previous turn’s and is discarded. What it says from then on is the turn’s, even when its LLM did not produce it.