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)
| 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. |
| 941 | func 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. |
| 978 | type contextKey int |
no test coverage detected