feat(plugins): add modelOverride/providerOverride to before_agent_start hook

Enable plugins to override the model and provider for agent runs by
returning modelOverride/providerOverride from the before_agent_start
hook. The hook is now invoked early in run.ts (before resolveModel)
so overrides take effect. The result is passed to attempt.ts via
earlyHookResult to prevent double-firing.

This enables security-critical use cases like routing PII-containing
prompts to local models instead of cloud providers.
This commit is contained in:
Nate Fikru
2026-02-15 12:05:29 -05:00
committed by Peter Steinberger
parent 15dd2cda20
commit b90eb51520
5 changed files with 73 additions and 25 deletions

View File

@@ -200,6 +200,8 @@ export function createHookRunner(registry: PluginRegistry, options: HookRunnerOp
acc?.prependContext && next.prependContext
? `${acc.prependContext}\n\n${next.prependContext}`
: (next.prependContext ?? acc?.prependContext),
modelOverride: next.modelOverride ?? acc?.modelOverride,
providerOverride: next.providerOverride ?? acc?.providerOverride,
}),
);
}

View File

@@ -332,6 +332,10 @@ export type PluginHookBeforeAgentStartEvent = {
export type PluginHookBeforeAgentStartResult = {
systemPrompt?: string;
prependContext?: string;
/** Override the model for this agent run. E.g. "llama3.3:8b" */
modelOverride?: string;
/** Override the provider for this agent run. E.g. "ollama" */
providerOverride?: string;
};
// llm_input hook