AgentRunBudget
AgentPrism.Abstractions.dllA run budget shared across an entire call tree.
public sealed class AgentRunBudgetInheritance
Section titled “Inheritance”Inherited Members
Section titled “Inherited Members”object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”This type is deliberately a class, not a record.
The budget is shared mutable state: every run in the tree uses the
same instance. A record invites copying; a copied budget
would give each branch its own limit, and the limit would lose its meaning.
Counters increment lock-free (Threading.Interlocked). Child runs start
concurrently: Microsoft Agent Framework’s background agents run without
blocking, so the same budget is read and written from multiple threads.
The budget blocks new child runs; it does not interrupt a run in progress. A child run cut off midway would leave the model with an incomplete context and would also corrupt the root run.
Constructors
Section titled “Constructors”AgentRunBudget()
Section titled “ AgentRunBudget()”public AgentRunBudget()Properties
Section titled “Properties”ConsumedTokens
Section titled “ ConsumedTokens”The tokens spent across the tree so far.
public long ConsumedTokens { get; }Property Value
Section titled “Property Value”IsTokenBudgetExhausted
Section titled “ IsTokenBudgetExhausted”Whether the token limit has been exceeded.
public bool IsTokenBudgetExhausted { get; }Property Value
Section titled “Property Value”MaxDepth
Section titled “ MaxDepth”The maximum allowed call depth. The root run is 0, so the default value allows a three-layer tree.
public int MaxDepth { get; init; }Property Value
Section titled “Property Value”MaxTotalRuns
Section titled “ MaxTotalRuns”The maximum number of child runs that may start. The root run is not counted toward this number. If null, there is no count limit.
public int? MaxTotalRuns { get; init; }Property Value
Section titled “Property Value”int?
MaxTotalTokens
Section titled “ MaxTotalTokens”The maximum tokens spendable across the tree. If null, there is no token limit.
public long? MaxTotalTokens { get; init; }Property Value
Section titled “Property Value”long?
StartedRuns
Section titled “ StartedRuns”The number of child runs started so far.
public int StartedRuns { get; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”DescribeExhaustion()
Section titled “ DescribeExhaustion()”Produces a user-facing text describing the limit that was exceeded.
public string DescribeExhaustion()Returns
Section titled “Returns”Text stating which limit was exceeded.
Remarks
Section titled “Remarks”The text is returned to the model as a tool result. Saying “budget exhausted” is not enough; unless the exceeded limit is named, the user cannot see which setting to raise.
RecordUsage(long)
Section titled “ RecordUsage(long)”Records the number of tokens spent into the budget.
public void RecordUsage(long tokens)Parameters
Section titled “Parameters”tokens long
The number of tokens to add. A negative value is ignored.
TryReserveRun()
Section titled “ TryReserveRun()”Reserves budget room for a new child run.
public bool TryReserveRun()Returns
Section titled “Returns”true if room was reserved; false if the token or count limit has been exceeded.
Remarks
Section titled “Remarks”The counter increments only when room is reserved. If a failed attempt incremented the counter, every new attempt in a tree that has hit its limit would keep growing the count, and the UI would show runs that never actually started.