Skip to main content

Module provider

Module provider 

Source
Expand description

Provider abstraction and per-agent model routing.

Why: Each agent routes to its own model, possibly behind a different backend (OpenRouter today, AWS Bedrock later). The agent loop depends on the Provider trait rather than branching on the backend, and a factory maps a model slug to the right implementation. What: Provider, ToolChoice, OpenRouterProvider, BedrockProvider, provider_for, resolve_model, DEFAULT_MODEL. Test: provider::* submodule tests. Provider abstraction and per-agent model routing.

Why: trusty-code routes each agent to its own model, which may live behind different backends (OpenRouter today, AWS Bedrock later). The agent loop must not branch on the backend; it depends on the Provider trait and asks a factory for the right implementation given a model slug. This module is that seam (#1021) and the precedence resolver for which slug to use. What: Re-exports the Provider trait and ToolChoice enum, the five concrete providers (OpenRouterProvider, BedrockProvider, FireworksProvider, TogetherProvider, AtlasCloudProvider), the provider_for factory, the resolve_model precedence function plus its DEFAULT_MODEL constant, the resolve_max_tokens precedence function plus its DEFAULT_MAX_TOKENS constant, and (#2207) the resolve_deadline_secs precedence function plus its DEFAULT_RUN_DEADLINE_SECS constant and RUN_DEADLINE_ENV_VAR name, and (#2308) the resolve_context_window precedence function plus its DEFAULT_CONTEXT_WINDOW constant. (#8030/#8128) The per-run top-level overrides live here too: resolve_pm_model_override + resolve_model_with_override with PM_MODEL_ENV_VAR, and resolve_max_turns with MAX_TURNS_ENV_VAR. Test: submodule tests in each file; routing/adapter coverage in routing.rs and adapter.rs.

Structs§

AtlasCloudProvider
Provider for AtlasCloud-hosted models (atlascloud/* slugs), served behind the OpenAI-compatible /chat/completions schema.
BedrockProvider
Provider for AWS Bedrock-hosted models (bedrock/* slugs), backed by the Converse API.
FireworksProvider
Provider for Fireworks-hosted models (fireworks/* slugs), served behind the OpenAI-compatible /chat/completions schema.
OpenRouterProvider
The default OpenRouter-backed provider.
TogetherProvider
Provider for Together.ai-hosted models (together/* slugs), served behind the OpenAI-compatible /chat/completions schema.

Enums§

ToolChoice
Provider-neutral tool-choice policy.

Constants§

DEFAULT_CONTEXT_WINDOW
Fallback context-window size (in tokens) for a model slug this resolver does not recognise.
DEFAULT_MAX_TOKENS
Default per-turn completion token cap when [llm].max_tokens is unset.
DEFAULT_MODEL
Default model slug when nothing else is specified.
DEFAULT_RUN_DEADLINE_SECS
Generous default wall-clock deadline for a run-task invocation, in seconds, when neither a CLI override nor RUN_DEADLINE_ENV_VAR is set.
MAX_TURNS_ENV_VAR
Environment variable overriding the PM loop’s turn cap (#8128).
PM_MODEL_ENV_VAR
Environment variable overriding the TOP-LEVEL (PM) agent’s model (#8030).
RUN_DEADLINE_ENV_VAR
Environment variable overriding the run-task wall-clock deadline (#2207).

Traits§

Provider
A backend that normalises tool-choice and usage for one family of models.

Functions§

provider_for
Select the provider implementation for a model slug.
resolve_context_window
Resolve the real context-window size (in tokens) for a model slug.
resolve_deadline_secs
Resolve the wall-clock deadline (in seconds) for a run-task invocation.
resolve_max_tokens
Resolve the per-turn completion-token cap for an invocation.
resolve_max_turns
Resolve the PM loop’s turn-cap override for one invocation (#8128).
resolve_model
Resolve the model slug for an invocation.
resolve_model_with_override
Resolve a model slug with an explicit per-run override ahead of the agent config (#8030).
resolve_pm_model_override
Resolve the TOP-LEVEL (PM) agent’s model override for one invocation.