← Back to PRs

#11155: feat(hooks): before_agent_start model/provider override (run-scoped, fail-closed)

by alanranger open 2026-02-07 13:32 View on GitHub →
agents stale size: M
## Summary Adds an **official plugin extension point** to request a **run-scoped** model/provider override via the existing `before_agent_start` hook. ### Contract - `PluginHookBeforeAgentStartResult` now supports: - `providerOverride?: string` - `modelOverride?: string` - Overrides are **run-scoped only** (not persisted to session). - **Fail-closed**: invalid overrides or hook errors are ignored and existing behavior remains. - Emits `onAgentEvent` lifecycle telemetry with accepted/rejected reason. ### Files - `src/plugins/types.ts` - `src/plugins/hooks.ts` - `src/agents/pi-embedded-runner/run.ts` - `src/agents/pi-embedded-runner.live-routing-before-agent-start.test.ts` ## Why We can already classify inbound messages in plugins, but there was no supported way to switch the model for the current run without local core patching. This enables safe, observable canaries like Tier-L routing for low-risk job classes. ## Testing - Adds a vitest unit test that asserts the override is applied before final model resolution. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR extends the `before_agent_start` plugin hook contract to optionally return `providerOverride`/`modelOverride`, and wires that into the embedded PI runner so plugins can request a run-scoped model/provider switch. The runner probes the requested override via `resolveModel` and emits lifecycle `onAgentEvent` telemetry indicating accepted/rejected decisions. A vitest test is added to assert the override is applied before final model resolution. <h3>Confidence Score: 3/5</h3> - This PR is close to mergeable but has a couple of correctness issues in hook merge semantics and override validation ordering. - The core idea is sound and changes are localized, but (1) the merge logic currently allows lower-priority hooks to override higher-priority ones, contradicting the stated contract, and (2) override probing happens before ensuring the model registry is available, which can cause valid overrides to be incorrectly rejected in some environments. Fixing these would reduce behavioral surprises for plugin authors. - src/plugins/hooks.ts, src/agents/pi-embedded-runner/run.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs