fix(modelloop): mark reasoning models from the carried model limits, in the gateway and the agent worker
This commit is contained in:
1 parent
193d13ac32
commit
399098329b
5 files changed
+24
-22
No files matched your search
@@ -1,26 +1,26 @@
|
||||
package modelloop
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/ai-sdk/runtime"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"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. 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 {
|
||||
// workflow stage. Nil means no providers were configured. limits is keyed
|
||||
// "provider/model"; its Reasoning flag tells the runtime which models need
|
||||
// max_completion_tokens instead of max_tokens.
|
||||
func NewRuntime(providers map[string]agentrun.Provider, limits map[string]config.ModelLimits) *runtime.Runtime {
|
||||
if len(providers) == 0 {
|
||||
return nil
|
||||
}
|
||||
runtime.RegisterBuiltinClasses()
|
||||
catalog := make(map[string]runtime.ProviderConfig, len(providers))
|
||||
for name, provider := range providers {
|
||||
cfg := runtime.ProviderConfig{ID: name, Class: provider.Class, BaseURL: provider.BaseURL}
|
||||
cfg := runtime.ProviderConfig{ID: name, Class: provider.Class, BaseURL: provider.BaseURL, Models: reasoningModels(name, limits)}
|
||||
if provider.APIKeyEnv == "" {
|
||||
cfg.Auth = runtime.AuthConfig{Type: runtime.AuthTypeNone}
|
||||
} else {
|
||||
@@ -28,10 +28,15 @@ func NewRuntime(providers map[string]agentrun.Provider, catalogPath string) *run
|
||||
}
|
||||
catalog[name] = cfg
|
||||
}
|
||||
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(runtime.Config{Providers: catalog})
|
||||
}
|
||||
|
||||
func reasoningModels(provider string, limits map[string]config.ModelLimits) []runtime.ModelConfig {
|
||||
var models []runtime.ModelConfig
|
||||
for ref, l := range limits {
|
||||
if id, ok := strings.CutPrefix(ref, provider+"/"); ok && l.Reasoning {
|
||||
models = append(models, runtime.ModelConfig{ID: id, Reasoning: true})
|
||||
}
|
||||
}
|
||||
return runtime.NewRuntime(cfg)
|
||||
return models
|
||||
}
|
||||
@@ -154,10 +154,10 @@ type taskDependencies struct {
|
||||
guardrails *tools.GuardrailEngine
|
||||
}
|
||||
|
||||
type runnerFactory func(map[string]agentrun.Provider, *slog.Logger) agentrun.Runner
|
||||
type runnerFactory func(map[string]agentrun.Provider, map[string]config.ModelLimits, *slog.Logger) agentrun.Runner
|
||||
|
||||
func newTaskRunner(providers map[string]agentrun.Provider, log *slog.Logger) agentrun.Runner {
|
||||
return modelloop.NewLoopRunner(modelloop.NewRuntime(providers, ""), log)
|
||||
func newTaskRunner(providers map[string]agentrun.Provider, limits map[string]config.ModelLimits, log *slog.Logger) agentrun.Runner {
|
||||
return modelloop.NewLoopRunner(modelloop.NewRuntime(providers, limits), log)
|
||||
}
|
||||
|
||||
// applyToolLimits sets the task's tool policy and allowlist on a
|
||||
@@ -186,7 +186,7 @@ func stageRunners(req taskrun.Request, mcpSet *mcpProviderSet, newRunner runnerF
|
||||
if mcpSet != nil && mcpSet.registry != nil {
|
||||
agent = modelloop.NewLoopRunner(llm, log, mcpSet.registry)
|
||||
} else {
|
||||
agent = newRunner(req.Providers, log)
|
||||
agent = newRunner(req.Providers, req.Cfg.ModelLimits, log)
|
||||
}
|
||||
if agent == nil {
|
||||
return nil, fmt.Errorf("no agent runner configured for task %d", req.Task.ID)
|
||||
@@ -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, req.Cfg.ModelLimits)
|
||||
}
|
||||
mcpSet, mcpErr := startMCPProviders(ctx, req.MCPServers, taskSamplingHandler(llm, req.Cfg), log)
|
||||
if mcpSet != nil {
|
||||
|
||||
@@ -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.catalog.Path()))
|
||||
b.setLLM(modelloop.NewRuntime(executionProviders(cfg), cfg.ModelLimits))
|
||||
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.catalog.Path()))
|
||||
b.setLLM(modelloop.NewRuntime(providers, cfg.ModelLimits))
|
||||
// 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,9 +29,6 @@ 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()
|
||||
|
||||
Reference in new issue
Block a user