> ## Documentation Index
> Fetch the complete documentation index at: https://phaseo.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Lifecycle hooks

> Observe PHP agent runs, model turns, tools, pauses, and completion.

Pass an `onEvent` callback to receive structured lifecycle events while the run executes.

```php theme={null}
$result = $agent->run(
    input: $prompt,
    client: $client,
    onEvent: function (array $event): void {
        $logger->info("agent event", [
            "type" => $event["type"],
            "run_id" => $event["run_id"],
            "details" => $event["details"] ?? [],
        ]);
    }
);
```

Useful events cover run start/completion/failure, model attempts, text and reasoning deltas, tool start/progress/completion/failure, and human checkpoints.

Keep callbacks fast. Queue slow persistence work, and redact sensitive tool inputs before forwarding events to external telemetry.
