feat(plugins): add before_agent_start model/provider overrides before resolution#18568
Merged
steipete merged 3 commits intoopenclaw:mainfrom Feb 16, 2026
Merged
Conversation
…rt 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.
Layer 1: Hook merger tests verify modelOverride/providerOverride are correctly propagated through the before_agent_start merger with priority ordering, backward compatibility, and field isolation. Layer 2: Pipeline wiring tests verify the earlyHookResult passthrough contract between run.ts and attempt.ts, graceful error degradation, and that overrides correctly modify provider/model variables. 19 tests total across 2 test files.
Make before_agent_start override merging preserve the first defined model/provider override so higher-priority hooks cannot be overwritten by lower-priority handlers, and align the corresponding test title and expectation with the intended precedence behavior. Co-authored-by: Cursor <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR extends the
before_agent_startplugin hook so plugins can deterministically select provider/model before model resolution.Clawforce needs this to enforce policy-driven routing (for example, forcing local models for sensitive prompts) at the correct point in the run pipeline.
What changed
modelOverrideandproviderOverridetoPluginHookBeforeAgentStartResult.before_agent_startearlier inrun.tsso overrides are applied beforeresolveModel.earlyHookResultintoattempt.tsto avoid double-firingbefore_agent_start.prependContext/systemPromptbehavior.Scope boundaries
message_sending,tool_result_persist,agent_end).Why this is needed
Previously,
before_agent_startcould enrich prompt context but could not reliably control provider/model selection at the point where selection actually occurs. This made hard policy routing non-deterministic. The new override contract closes that gap.Test plan
pnpm vitest run src/plugins/hooks.before-agent-start.test.ts src/plugins/hooks.model-override-wiring.test.tsCompatibility
prependContextand/orsystemPrompt.