inspect_swarm.analysis
Columns
SwarmColumns
Columns for inspect_ai.analysis.samples_df() with each sample’s realized cost and what the swarm’s ledger says about it, as in samples_df(logs, columns=SampleSummary + SwarmColumns). The inspect_swarm.analysis module docstring lists every column.
SwarmColumns: list[Column] = [
SampleColumn("swarm_cost", path=_cost, type=float, full=True),
SampleColumn("swarm_complete", path=_complete, type=bool, full=True),
SampleColumn("swarm_members", path=_members, type=int, full=True),
SampleColumn("swarm_resumed", path=_resumed, type=bool, full=True),
SampleColumn("swarm_cost_cap", path=_cost_cap, type=float, full=True),
SampleColumn("swarm_token_cap", path=_token_cap, type=float, full=True),
SampleColumn("swarm_time_cap", path=_time_cap, type=float, full=True),
SampleColumn("swarm_errored", path=_errored, type=int, full=True),
SampleColumn("swarm_no_usage", path=_no_usage, type=int, full=True),
SampleColumn("swarm_unpriced", path=_unpriced, type=int, full=True),
SampleColumn("swarm_unpriced_models", path=_unpriced_models, full=True),
]The ledger
swarm_ledger
Read the swarm’s ledger from a sample.
def swarm_ledger(sample: EvalSample) -> SwarmLedger | NonesampleEvalSample-
A sample read from a log with its store, for example from read_eval_log(). A sample that runs two swarms keeps only the last one’s ledger.
SwarmLedger
Realized usage and cost of one run of the swarm, and how complete they are.
The swarm writes its ledger once, when it ends, to the sample store as inspect_swarm:ledger and as an InfoEvent with source inspect_swarm. Read it from a sample with swarm_ledger().
The store entry’s shape follows version. This inspect_swarm reads version 1 only.
class SwarmLedger(BaseModel)Attributes
versionLiteral[1]-
Format version of the ledger.
budgetBudget-
The swarm’s budget as configured.
capsdict[str, float | None]-
The swarm’s caps, derived or explicit, keyed by
cost(dollars),tokensandtime(seconds).Nonefor a kind with no cap. sample_limitsdict[str, float | None]-
The sample’s limits when the swarm started, keyed by
token,cost,message,turn,workingandtime.Nonefor a limit not set. memberslist[MemberLedger]-
Each member, in roster order.
runtimeMeter-
Calls made by the swarm’s runtime, such as the controller’s.
finalMeter-
Calls made by the final step, which chooses the answer.
swarmMeter-
Every call in the swarm’s context: the members, the runtime, the final step and anything else.
callsCalls-
Model events in the swarm’s span tree: the members, the runtime and the final step.
unpriced_calls_recordedint-
Calls the swarm meter recorded with usage but no cost.
sample_deltaModelUsage-
The sample’s model usage over the swarm’s lifetime, summed over its models.
unattributedModelUsage-
What the sample used over the swarm’s lifetime that the swarm meter did not record: tokens are
sample_deltaminusswarm.usage, andtotal_costissample_delta’s cost minusswarm.cost. unpriced_modelslist[str]-
Models in
sample_deltawith tokens but no cost. native_compaction_classeslist[str]-
Loaded ModelAPI classes that override
compact(), when the swarm started or ended. Native compaction emits no event, so the ledger cannot count its calls. overshootdict[str, float]-
How far usage at the end went past each cap, keyed by
cost,tokensandtime. Only kinds over their cap appear. stop_reasonstr | None-
The reason the swarm stopped its members, from the first stop begun.
Nonewhen no stop began. ended_bystr | None-
The sample limit (
sample_limit:<type>) or operator interrupt (operator) that ended the swarm, even during its own stop.unknownwhen an outside cause may have ended it but cannot be named.Nonewhen nothing from outside ended it. interruptedbool-
The swarm did not finish: an error, a limit or a cancellation ended it before or during its final step.
final_cancelledbool-
The final step was cancelled.
resumedbool-
The sample resumed from a checkpoint, so the swarm restarted its caps from zero.
total_completebool-
No call is known to be missing from the swarm’s usage and cost: no member, member background task or final step was cancelled, the swarm was not interrupted, every call completed with priced usage, every model in
sample_deltais priced, and no loaded model class compacts natively. attribution_completebool-
total_complete, and the swarm meter recorded all the sample used over the swarm’s lifetime:unattributedis zero, to within rounding.
MemberLedger
One member’s entry in the swarm’s ledger.
class MemberLedger(BaseModel)Attributes
namestr-
The member’s name.
statusstr | None-
How the member ended (
submitted,swarm_cap, …), orNonefor a member never started. bridgedbool-
The member runs a CLI agent through Inspect’s agent bridge.
meterMeter-
Usage and cost of the calls made in the member’s context.
callsCalls-
Model events in the member’s spans.
cancelledbool-
The member’s agent was cancelled, or the swarm’s hard stop cancelled its background drain after the agent had returned. A hard stop during the drain keeps the agent’s status, so
cancelledcan beTruewithstatus="submitted". The agent is cancelled by the hard stop after a grace period, a member time limit or a cancellation from outside the swarm. A bridged member is also cancelled at once when it reaches a cap, its share or one of its own limits, or makes a call after the swarm stopped it. background_startedint-
Tasks the member’s agent started with background(), such as deepagent() background subagents.
background_cancelledint-
Of
background_started, the tasks that were cancelled: still running when the member’s drain ended, or cancelled by an error from the member’s work or by the hard stop.
Meter
Usage and cost recorded by one of the swarm’s meters.
A meter counts the model calls made in its context: one member’s, the runtime’s, the final step’s, or the whole swarm’s.
class Meter(BaseModel)Attributes
usageModelUsage-
Token usage of the calls recorded, except those made while token metering was suspended (approval and review calls).
costfloat-
Cost in dollars of the priced calls recorded, suspended calls included.
suspended_costfloat-
The part of
costrecorded while token metering was suspended (approval and review calls).
Calls
Counts of the model events in the swarm, or in one member’s spans.
errored, no_usage and unpriced count calls whose cost is missing, so any of them above zero makes the cost a lower bound.
class Calls(BaseModel)Attributes
callsint-
Model calls that completed, cache replays excluded.
cache_replaysint-
Model events replayed from the cache (
cache="read"). They cost nothing. erroredint-
Model calls that ended in an error or were cancelled, plus the requests a provider’s client retried inside one call. Their usage is unknown.
no_usageint-
Model calls that completed with output but no usage.
unpricedint-
Model calls that completed with usage but no cost (
total_costisNone).