agentix.consistency¶
consistency ¶
Self-consistency.
SelfConsistencyModel wraps a model and, on each turn, samples it N times and
returns the majority vote — a simple, effective way to damp non-determinism
on hard reasoning steps. It's a ModelFn, so it drops into Agent(model=...).
Cost: it makes N model calls per turn. The returned response aggregates the
token/USD spend across all N samples, so the agent's budgets and
outcome.cost_usd reflect the real cost. Pair with a Limiter to bound the
extra concurrency.
Responses are grouped by a key (default: normalized text for a final answer,
or the tool-call signature otherwise); the largest group wins, ties go to the
first sampled.
SelfConsistencyModel ¶
SelfConsistencyModel(
model: ModelFn,
*,
samples: int = 5,
key: Callable[[ModelResponse], str] | None = None,
)
Sample the wrapped model N times per turn and return the majority vote.