Access a specific event by index for assertions. Supports negative indices (e.g., -1 for last event).
result.expect.at(0).isMessage({ role: 'user' });
result.expect.at(-1).isMessage({ role: 'assistant' });
Assert that an agent handoff matching criteria exists anywhere in the events.
Optional options: AgentHandoffAssertOptionsresult.expect.containsAgentHandoff({ newAgentType: MyAgent });
Assert that a function call matching criteria exists anywhere in the events.
Optional options: FunctionCallAssertOptionsresult.expect.containsFunctionCall({ name: 'order_item' });
Assert that a function call output matching criteria exists anywhere in the events.
Optional options: FunctionCallOutputAssertOptionsresult.expect.containsFunctionCallOutput({ isError: false });
Assert that a message matching criteria exists anywhere in the events.
Optional options: MessageAssertOptionsresult.expect.containsMessage({ role: 'assistant' });
Advance to the next event, optionally filtering by type.
result.expect.nextEvent().isMessage({ role: 'assistant' });
result.expect.nextEvent({ type: 'function_call' }).isFunctionCall({ name: 'foo' });
Get an EventRangeAssert for a range of events. Similar to Python's slice access: expect[0:3] or expect[:]
Optional start: numberStart index (inclusive), defaults to 0
Optional end: numberEnd index (exclusive), defaults to events.length
// Search all events
result.expect.range().containsFunctionCall({ name: 'foo' });
// Search first 3 events
result.expect.range(0, 3).containsMessage({ role: 'assistant' });
Conditionally skip the next event if it matches the specified criteria. Returns the event assertion if matched and skipped, or undefined if not matched.
// Skip optional assistant message before function call
result.expect.skipNextEventIf({ type: 'message', role: 'assistant' });
result.expect.nextEvent().isFunctionCall({ name: 'foo' });
Assertion helper for verifying run events in sequence.