A task hosts the same configured MCP servers as a chat turn, but the worker's provider builder passed no sampling handler, so a task-scoped server's sampling/createMessage request got a JSON-RPC method-not-found while the identical request succeeded on the chat path. The worker runs its own model runtime, so it can answer. Thread a sampling handler built from the task's builder model into the worker's MCP provider builder, beside the chat path's handler. Build the task's model runtime once and share it with the stage runners instead of creating a second client for sampling. Move the sampling message mapping and max-token bound to agentexec, next to the runtime both paths call models through, so a server gets the same bound on either path. Carry the catalog's reasoning flag in ModelLimits: a reasoning-class builder model must omit the max-token bound its provider rejects, exactly as the chat path does.
78 lines
2.6 KiB
Go
78 lines
2.6 KiB
Go
package archied
|
|
|
|
import (
|
|
"maps"
|
|
"slices"
|
|
"strings"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/modelcatalog"
|
|
"github.com/samcharles93/archie-core/internal/secret"
|
|
"github.com/samcharles93/archie-core/internal/webui"
|
|
)
|
|
|
|
func applyModelCatalog(cfg *config.Config, snapshot modelcatalog.Snapshot) []string {
|
|
discovered := make(map[string]config.Provider, len(snapshot.Providers))
|
|
limits := make(map[string]config.ModelLimits)
|
|
var models []string
|
|
for _, provider := range snapshot.Providers {
|
|
discovered[provider.ID] = config.Provider{
|
|
Class: provider.Class, APIKeyEnv: provider.APIKeyEnv, BaseURL: provider.BaseURL,
|
|
}
|
|
for _, model := range provider.Models {
|
|
ref := provider.ID + "/" + model.ID
|
|
models = append(models, ref)
|
|
limits[ref] = config.ModelLimits{ContextWindow: model.ContextWindow, MaxOutputTokens: model.MaxOutputTokens, Reasoning: model.Reasoning}
|
|
}
|
|
}
|
|
cfg.ModelLimits = limits
|
|
cfg.Providers = mergeProviders(discovered, cfg.Providers)
|
|
for i := range cfg.Identities {
|
|
cfg.Identities[i].Providers = mergeProviders(discovered, cfg.Identities[i].Providers)
|
|
}
|
|
slices.Sort(models)
|
|
return models
|
|
}
|
|
|
|
func mergeProviders(base, overrides map[string]config.Provider) map[string]config.Provider {
|
|
merged := make(map[string]config.Provider, len(base)+len(overrides))
|
|
maps.Copy(merged, base)
|
|
for id, override := range overrides {
|
|
resolved := merged[id]
|
|
if override.Class != "" {
|
|
resolved.Class = override.Class
|
|
}
|
|
if override.APIKeyEnv != "" {
|
|
resolved.APIKeyEnv = override.APIKeyEnv
|
|
}
|
|
if override.APIKey != (secret.SecretRef{}) {
|
|
resolved.APIKey = override.APIKey
|
|
}
|
|
if override.BaseURL != "" {
|
|
resolved.BaseURL = override.BaseURL
|
|
}
|
|
merged[id] = resolved
|
|
}
|
|
return merged
|
|
}
|
|
|
|
// catalogView renders the usable providers for the published config view,
|
|
// sorted by id with each provider's model ids sorted, so the document is
|
|
// stable across publishes.
|
|
func catalogView(snapshot modelcatalog.Snapshot) []webui.CatalogProviderView {
|
|
view := make([]webui.CatalogProviderView, 0, len(snapshot.Providers))
|
|
for _, provider := range snapshot.Providers {
|
|
models := make([]string, 0, len(provider.Models))
|
|
for _, model := range provider.Models {
|
|
models = append(models, model.ID)
|
|
}
|
|
slices.Sort(models)
|
|
view = append(view, webui.CatalogProviderView{
|
|
ID: provider.ID, Name: provider.Name, Class: provider.Class,
|
|
APIKeyEnv: provider.APIKeyEnv, BaseURL: provider.BaseURL, Models: models,
|
|
})
|
|
}
|
|
slices.SortFunc(view, func(a, b webui.CatalogProviderView) int { return strings.Compare(a.ID, b.ID) })
|
|
return view
|
|
}
|