agora.fleet.cast

Cast loader + validator (roles-and-casting Stage 1).

A CAST binds each ROLE to a model profile for one hardware envelope, with evidence citations. This module loads a casts/<envelope>.yaml file into a validated Cast and checks it against the four rules from docs/design/roles-and-casting.md:

  1. Every profile reference resolves in profiles.yaml.

  2. Sum of resident model sizes ≤ vram_budget_gb (sizes from the local manifest store — Ollama /api/show — not hand-entered).

  3. Every binding either cites evidence or carries a waiver …

  4. … UNLESS it is binding: human, which is always valid and needs neither.

Loading (resolve_cast()) produces the role→profile table the orchestrator would consume; the resident/keep_alive fields are advisory to the eviction protocol. Deliberately small: schema + four rules + loud failures. Model-size lookup is injected so the validator stays pure and testable — the CLI supplies the live Ollama probe, tests supply a static map.

Finding: rule 3’s evidence requirement is where F12 lands — a binding’s evidence key is per-(model × TOOL SURFACE), not per-model alone. A model measured reliable on one tool family has not been shown reliable casting onto a seat that uses a different, unmeasured one (the run-1.3 add_function wall). So “cite evidence” means cite a row for the seat’s actual tools, not a generic 9/9.

Module Attributes

HUMAN_BINDING

The sentinel value for a role deliberately bound to a human, not a model.

Functions

load_cast(path)

Load and schema-validate a cast YAML file.

ollama_sizes_gb(cast, profiles, base_url)

Best-effort: query the local Ollama manifest store for resident sizes.

resolve_cast(cast, profiles)

Build the role table a loader would hand the orchestrator.

validate_cast(cast, profiles, *[, sizes_gb])

Check a cast against the four casting rules; return a list of problems.

Classes

Cast

A full cast: hardware envelope + role bindings.

CastBinding

One role→profile binding inside a cast.

CastHardware

The hardware envelope a cast targets.

ResolvedBinding

One entry of the role table produced by resolve_cast().

class agora.fleet.cast.Cast[source]

Bases: BaseModel

A full cast: hardware envelope + role bindings.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

schema_version: int
name: str
hardware: CastHardware
bindings: dict[str, CastBinding]
class agora.fleet.cast.CastBinding[source]

Bases: BaseModel

One role→profile binding inside a cast.

Exactly one of profile or binding: human should be set (checked in validate_cast(), not here, so the error is reported not raised).

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

profile: str | None
binding: str | None
resident: bool
keep_alive: str
evidence: dict[str, Any] | None
waiver: str | None
class agora.fleet.cast.CastHardware[source]

Bases: BaseModel

The hardware envelope a cast targets.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

gpu: str
gpu_uuid: str
vram_budget_gb: float
agora.fleet.cast.HUMAN_BINDING = 'human'

The sentinel value for a role deliberately bound to a human, not a model.

class agora.fleet.cast.ResolvedBinding[source]

Bases: BaseModel

One entry of the role table produced by resolve_cast().

profile is None for a human-bound role. model is the concrete model id (e.g. ollama/gemma4:e4b) for a profile binding, else “”.

model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

role: str
is_human: bool
profile: ModelProfile | None
model: str
resident: bool
keep_alive: str
agora.fleet.cast.load_cast(path)[source]

Load and schema-validate a cast YAML file.

YAML parse errors and pydantic validation failures both surface as AgoraError with the offending path attached — mirrors agora.fleet.profiles.load_profiles().

async agora.fleet.cast.ollama_sizes_gb(cast, profiles, base_url)[source]

Best-effort: query the local Ollama manifest store for resident sizes.

Returns {model_id: size_gb} for every RESIDENT profile binding whose profile resolves. Used by the CLI to feed validate_cast()’s residency rule; kept out of the pure validator so tests need no daemon.

agora.fleet.cast.resolve_cast(cast, profiles)[source]

Build the role table a loader would hand the orchestrator.

Resolves each profile binding to its ModelProfile; leaves human bindings profile-less. Raises AgoraError if the cast does not validate structurally (unknown profile / malformed binding) — load refuses an invalid cast. Residency-budget failures do NOT block load (residency is advisory to the eviction protocol), so this ignores sizes_gb.

agora.fleet.cast.validate_cast(cast, profiles, *, sizes_gb=None)[source]

Check a cast against the four casting rules; return a list of problems.

An empty list means the cast is valid. sizes_gb maps a concrete model id (profile.model) → its on-disk size in GB; supply it (from the local manifest store) to enable the residency-budget rule. When it is None, the residency sum is not checkable and is reported as a single skip note rather than silently passing.