Skip to main content

Function: resolveModelOption()

resolveModelOption(opts, task?): ParsedModel

Defined in: packages/agentos/src/api/model.ts:613

Resolves a { providerId, modelId } pair from flexible caller-supplied options.

Resolution priority:

  1. Explicit model string — a provider:model id is split when its prefix is a known provider id (a key of PROVIDER_DEFAULTS), whatever provider says, except under provider: 'ollama', where an id is never split. Any other id is kept whole: with provider set, the pair is used as-is; without it, auto-detection from env vars is attempted.
  2. provider only — default model for the requested task is looked up in PROVIDER_DEFAULTS.
  3. Neither — auto-detect the first provider with a set API key/URL env var and use its default model for the requested task.

In 2 and 3, a text call to Anthropic whose toolChoice forces a tool takes ANTHROPIC_FORCED_TOOL_MODEL when the default model refuses a forced tool choice, so the tool stays required.

Parameters​

opts​

ModelOption

Caller options containing optional provider and/or model.

task?​

TaskType = 'text'

Task type used to select the correct default model. Defaults to "text".

Returns​

ParsedModel

A ParsedModel with providerId and modelId.

Throws​

When no provider can be determined, the provider is unknown, or the provider has no default model for the requested task.