getTitleModelForAgent resolves the dedicated title-generation model for an agent, if any. It returns the model named by the `title_model` field of the first of the agent's configured models that sets it, or nil when none do.
(ctx context.Context, cfg *latest.Config, a *latest.AgentConfig, runConfig *config.RuntimeConfig, providerRegistry *provider.Registry)
| 553 | // agent, if any. It returns the model named by the `title_model` field of the |
| 554 | // first of the agent's configured models that sets it, or nil when none do. |
| 555 | func getTitleModelForAgent(ctx context.Context, cfg *latest.Config, a *latest.AgentConfig, runConfig *config.RuntimeConfig, providerRegistry *provider.Registry) (provider.Provider, error) { |
| 556 | var titleRef string |
| 557 | for name := range strings.SplitSeq(a.Model, ",") { |
| 558 | if modelCfg, ok := cfg.Models[name]; ok && modelCfg.TitleModel != "" { |
| 559 | titleRef = modelCfg.TitleModel |
| 560 | break |
| 561 | } |
| 562 | } |
| 563 | if titleRef == "" { |
| 564 | return nil, nil |
| 565 | } |
| 566 | |
| 567 | modelsStore, modelsStoreErr := runConfig.ModelsDevStore() |
| 568 | |
| 569 | modelCfg, exists := cfg.Models[titleRef] |
| 570 | if !exists { |
| 571 | parsed, err := latest.ParseModelRef(titleRef) |
| 572 | if err != nil { |
| 573 | return nil, fmt.Errorf("title model '%s' not found in configuration and is not a valid provider/model format", titleRef) |
| 574 | } |
| 575 | modelCfg = parsed |
| 576 | } |
| 577 | modelCfg.Name = titleRef |
| 578 | |
| 579 | maxTokens := &defaultMaxTokens |
| 580 | if modelCfg.MaxTokens != nil { |
| 581 | maxTokens = modelCfg.MaxTokens |
| 582 | } else if modelsStoreErr == nil { |
| 583 | m, err := modelsStore.GetModel(ctx, modelsdev.NewID(modelCfg.Provider, modelCfg.Model)) |
| 584 | if err == nil { |
| 585 | maxTokens = &m.Limit.Output |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | opts := []options.Opt{ |
| 590 | options.WithGateway(runConfig.ModelsGateway), |
| 591 | options.WithStructuredOutput(a.StructuredOutput), |
| 592 | options.WithProviders(cfg.Providers), |
| 593 | } |
| 594 | if maxTokens != nil { |
| 595 | opts = append(opts, options.WithMaxTokens(*maxTokens)) |
| 596 | } |
| 597 | if modelsStoreErr == nil { |
| 598 | opts = append(opts, options.WithModelsDevStore(modelsStore)) |
| 599 | } |
| 600 | |
| 601 | model, err := providerRegistry.NewWithModels(ctx, &modelCfg, cfg.Models, runConfig.EnvProvider(), opts...) |
| 602 | if err != nil { |
| 603 | return nil, fmt.Errorf("failed to create title model '%s': %w", titleRef, err) |
| 604 | } |
| 605 | return model, nil |
| 606 | } |
| 607 | |
| 608 | // getCompactionModelForAgent resolves the dedicated compaction (summary |
| 609 | // generation) model for an agent, if any. It returns the model named by the |
no test coverage detected