Class MailAnsweringRunLedger
- Namespace
- MailFathom.Application.Retrieval.AskMail
- Assembly
- MailFathom.Application.dll
Counts what one run has spent, refuses what would take it past what one question may cost, and reports what it has spent so far.
public sealed class MailAnsweringRunLedger
- Inheritance
-
MailAnsweringRunLedger
- Inherited Members
Remarks
One instance serves one run, for the reason the run's retrieval does: a ceiling on a question is meaningless if two questions share it. It is nevertheless internally synchronized, because a tool loop may answer several lookups of one run at once, a streamed run reads its counts from a connection other than the one executing it, and both halves of a check-then-take have to happen together.
The two kinds of refusal are deliberately unequal. Retrieval is trimmed to what the run may still send and the run continues, because a question with some mail already retrieved is answerable and the model is told there is no more. A provider call is refused outright, because a run with no allowance for another call has no answer to trim.
A token ceiling is checked before a call and can only be checked against what earlier calls reported, so the call that crosses it is paid for. That is inherent rather than an oversight: what a call will cost is not knowable until the provider has answered, and the alternative — estimating it — would refuse calls on a guess.
It is in this layer rather than beside the agent that first used it because a Discover run is orchestrated here and spends at two ports it reaches the model through, so one ledger for the run has to be a thing this layer can hold. What the run reports about what it spent is Read(), which is ADR 0022's unit: the run's own consumption against the ceilings that will stop it.
Constructors
- MailAnsweringRunLedger(MailAnsweringRunBounds)
Initializes a ledger for one run, with nothing spent.
Properties
- Bounds
Gets what this run may send, call, and consume, which is what its counts are read against.
- RetrievalWasTruncated
Gets whether a lookup found mail this run's ceiling would not let it send.
Methods
- AdmitPassages(IReadOnlyList<EmailKnowledgePassage>)
Takes the passages of one lookup that still fit inside what this run may send.
- Read()
Reads what this run has consumed so far.
- RecordSpend(ChatTokenUsage)
Adds what one call consumed to this run's total.
- RequireAllowanceForNextCall()
Takes this run's allowance for one more provider call.