MCPcopy
hub / github.com/docker/docker-agent / WithAgentModel

Method WithAgentModel

pkg/runtime/model_switcher.go:395–407  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

393// untouched and restore is a no-op, so callers can always defer it
394// without nil-checking.
395func (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

Callers 2

RunSkillForkMethod · 0.95
TestWithAgentModelFunction · 0.95

Calls 4

setAgentModelInternalMethod · 0.95
AgentMethod · 0.80
SnapshotModelOverrideMethod · 0.80
RestoreModelOverrideMethod · 0.80

Tested by 1

TestWithAgentModelFunction · 0.76