WithAgentModel applies modelRef as a model override on the named agent and returns a function that restores the previous override safely. The returned restore func is always non-nil. On success it uses pointer-identity compare-and-swap on the agent's override, so a concurrent change made between th
(ctx context.Context, agentName, modelRef string)
| 393 | // untouched and restore is a no-op, so callers can always defer it |
| 394 | // without nil-checking. |
| 395 | func (r *LocalRuntime) WithAgentModel(ctx context.Context, agentName, modelRef string) (restore func(), err error) { |
| 396 | noop := func() {} |
| 397 | a, err := r.team.Agent(agentName) |
| 398 | if err != nil { |
| 399 | return noop, fmt.Errorf("agent not found: %w", err) |
| 400 | } |
| 401 | prev := a.SnapshotModelOverride() |
| 402 | ours, err := r.setAgentModelInternal(ctx, agentName, modelRef) |
| 403 | if err != nil { |
| 404 | return noop, err |
| 405 | } |
| 406 | return func() { a.RestoreModelOverride(prev, ours) }, nil |
| 407 | } |
| 408 | |
| 409 | // resolveModelRef resolves a model reference to a single provider. |
| 410 | // The reference can be a named model from the config or an inline |