fix(modelloop): feed the cached model catalog to the runtime so reasoning models get the right token parameter

This commit is contained in:
sam committed 2026-10-06 00:45:09 +11:00
1 parent 78c2f33928
commit d427671fc5
5 files changed
+20 -7

No files matched your search

+13 -3
View File
@@ -1,14 +1,19 @@
package modelloop
import (
"os"
"github.com/samcharles93/ai-sdk/runtime"
"github.com/samcharles93/archie-core/internal/domain/agentrun"
)
// NewRuntime builds a provider runtime for interactive chat or a worker-local
// workflow stage. Nil means no providers were configured.
func NewRuntime(providers map[string]agentrun.Provider) *runtime.Runtime {
// workflow stage. Nil means no providers were configured. catalogPath is the
// models.dev snapshot the service already cached; it supplies each model's
// reasoning flag so requests use the parameters the model accepts. Empty or
// unreadable leaves the runtime without model metadata.
func NewRuntime(providers map[string]agentrun.Provider, catalogPath string) *runtime.Runtime {
if len(providers) == 0 {
return nil
}
@@ -23,5 +28,10 @@ func NewRuntime(providers map[string]agentrun.Provider) *runtime.Runtime {
}
catalog[name] = cfg
}
return runtime.NewRuntime(runtime.Config{Providers: catalog})
cfg := runtime.Config{Providers: catalog}
models := runtime.NewCatalog(runtime.CatalogOptions{})
if raw, err := os.ReadFile(catalogPath); err == nil && models.LoadFromJSON(raw) == nil {
return runtime.NewRuntimeWithCatalog(cfg, models)
}
return runtime.NewRuntime(cfg)
}
+2 -2
View File
@@ -157,7 +157,7 @@ type taskDependencies struct {
type runnerFactory func(map[string]agentrun.Provider, *slog.Logger) agentrun.Runner
func newTaskRunner(providers map[string]agentrun.Provider, log *slog.Logger) agentrun.Runner {
return modelloop.NewLoopRunner(modelloop.NewRuntime(providers), log)
return modelloop.NewLoopRunner(modelloop.NewRuntime(providers, ""), log)
}
// applyToolLimits sets the task's tool policy and allowlist on a
@@ -231,7 +231,7 @@ func runTask(ctx context.Context, req taskrun.Request, dependencies taskDependen
// the task's own model rather than a second provider client.
var llm *runtime.Runtime
if len(req.MCPServers) > 0 {
llm = modelloop.NewRuntime(req.Providers)
llm = modelloop.NewRuntime(req.Providers, "")
}
mcpSet, mcpErr := startMCPProviders(ctx, req.MCPServers, taskSamplingHandler(llm, req.Cfg), log)
if mcpSet != nil {
+1 -1
View File
@@ -92,7 +92,7 @@ func (b *server) rebuildChatModelRuntime(cfg config.Config) {
if b.chatModels == nil {
return // this process serves no chat turns
}
b.setLLM(modelloop.NewRuntime(executionProviders(cfg)))
b.setLLM(modelloop.NewRuntime(executionProviders(cfg), b.catalog.Path()))
b.chatModels.SetConfigured(cfg.Models)
catalog, models := b.catalogState()
b.chatModels.SetModelCatalog(catalog, models)
@@ -27,7 +27,7 @@ func (b *server) setupChatRuntime(ctx context.Context, cfg config.Config, actor
// Created before the router so the LLMResponder can be wired in for
// non-command message processing.
providers := executionProviders(cfg)
b.setLLM(modelloop.NewRuntime(providers))
b.setLLM(modelloop.NewRuntime(providers, b.catalog.Path()))
// Transcription is a model-role capability, like the chat models it sits
// beside: it is built here, on the model-owning side, from this process's
// own [models]/[providers]. The Messaging Service carries a voice note's
@@ -29,6 +29,9 @@ func NewCatalog(cfgPath string) *Catalog {
return &Catalog{cachePath: filepath.Join(filepath.Dir(cfgPath), "models.json")}
}
// Path is the cached catalog file.
func (c *Catalog) Path() string { return c.cachePath }
// State returns the loaded snapshot and its model references.
func (c *Catalog) State() (Snapshot, []string) {
c.mu.RLock()