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§
- Atlas
Cloud Provider - Provider for AtlasCloud-hosted models (
atlascloud/*slugs), served behind the OpenAI-compatible/chat/completionsschema. - Bedrock
Provider - Provider for AWS Bedrock-hosted models (
bedrock/*slugs), backed by the Converse API. - Fireworks
Provider - Provider for Fireworks-hosted models (
fireworks/*slugs), served behind the OpenAI-compatible/chat/completionsschema. - Open
Router Provider - The default OpenRouter-backed provider.
- Together
Provider - Provider for Together.ai-hosted models (
together/*slugs), served behind the OpenAI-compatible/chat/completionsschema.
Enums§
- Tool
Choice - 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_tokensis unset. - DEFAULT_
MODEL - Default model slug when nothing else is specified.
- DEFAULT_
RUN_ DEADLINE_ SECS - Generous default wall-clock deadline for a
run-taskinvocation, in seconds, when neither a CLI override norRUN_DEADLINE_ENV_VARis 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-taskwall-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-taskinvocation. - 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.