MCPcopy Index your code
hub / github.com/docker/docker-agent / loadExternalAgent

Function loadExternalAgent

pkg/teamloader/teamloader.go:941–975  ·  view source on GitHub ↗

loadExternalAgent loads an agent from an external reference (OCI or URL). It resolves the reference, loads its config, and returns the default agent.

(ctx context.Context, ref string, runConfig *config.RuntimeConfig, loadOpts *loadOptions)

Source from the content-addressed store, hash-verified

939// loadExternalAgent loads an agent from an external reference (OCI or URL).
940// It resolves the reference, loads its config, and returns the default agent.
941func loadExternalAgent(ctx context.Context, ref string, runConfig *config.RuntimeConfig, loadOpts *loadOptions) (*agent.Agent, error) {
942 depth := externalDepthFromContext(ctx)
943 if depth >= maxExternalDepth {
944 return nil, fmt.Errorf("maximum external agent nesting depth (%d) exceeded — check for circular references", maxExternalDepth)
945 }
946
947 // Tag references (including the implicit ":latest") are re-resolved against
948 // the registry every time the config is loaded, adding a digest lookup to
949 // startup even when the agent is never invoked. Digest-pinned references are
950 // served from the local cache with no network call, so nudge users to pin.
951 if config.IsOCIReference(ref) && !remote.IsDigestReference(ref) {
952 slog.WarnContext(ctx, "External agent reference uses a tag, not a digest; it is re-resolved against the registry on every run. Pin it to a digest (ref@sha256:...) to avoid the per-run registry lookup.", "ref", ref)
953 }
954
955 source, err := config.Resolve(ref, runConfig.EnvProvider())
956 if err != nil {
957 return nil, err
958 }
959
960 var opts []Opt
961 if loadOpts.toolsetRegistry != nil {
962 opts = append(opts, WithToolsetRegistry(loadOpts.toolsetRegistry))
963 }
964
965 if loadOpts.providerRegistry != nil {
966 opts = append(opts, WithProviderRegistry(loadOpts.providerRegistry))
967 }
968
969 result, err := Load(contextWithExternalDepth(ctx, depth+1), source, runConfig, opts...)
970 if err != nil {
971 return nil, err
972 }
973
974 return result.DefaultAgent()
975}
976
977// contextKey is an unexported type for context keys defined in this package.
978type contextKey int

Callers 1

resolveAgentRefsFunction · 0.85

Calls 10

IsOCIReferenceFunction · 0.92
IsDigestReferenceFunction · 0.92
ResolveFunction · 0.92
externalDepthFromContextFunction · 0.85
WithToolsetRegistryFunction · 0.85
contextWithExternalDepthFunction · 0.85
EnvProviderMethod · 0.80
DefaultAgentMethod · 0.80
WithProviderRegistryFunction · 0.70
LoadFunction · 0.70

Tested by

no test coverage detected