Skip to main content

Overview

Instructor dispatches events at every significant stage of its execution. You can listen to these events for logging, monitoring, debugging, or custom processing. All event classes extend Cognesy\Events\Event.

Listening to Events

Targeted Listeners

Use onEvent() on the StructuredOutputRuntime to listen for a specific event type:

Wiretap (All Events)

Use wiretap() to receive every event dispatched by Instructor. This is useful for debugging or comprehensive logging:

Practical Example

Event Categories

Events are organized into namespaces that correspond to the processing stage:

High-Level Events (Events\StructuredOutput)

Request Events (Events\Request)

Response Events (Events\Response)

Extraction Events (Events\Extraction)

Streaming Events (Events\PartialsGenerator)

Event Methods

Every event inherits the following convenience methods from Cognesy\Events\Event: Events carry a $logLevel property (PSR log level) and a $data payload. The print() method respects a configurable log-level threshold. Instructor event payloads are normalized arrays. Structured-output lifecycle events also expose correlation fields such as requestId, executionId, attemptId, phase, and phaseId where applicable.