Skip to content

TokenBudgetExtensions

NexusLabs.Foundry.MicrosoftAgentFramework.Workflows

NexusLabs.Foundry.MicrosoftAgentFramework.Workflows.Budget

TokenBudgetExtensions Class

Extension methods for wiring token-budget enforcement into the agent framework.

public static class TokenBudgetExtensions

Inheritance System.Object 🡒 TokenBudgetExtensions

Methods

TokenBudgetExtensions.UsingTokenBudget(this AgentFrameworkBuilder) Method

Wraps the configured Microsoft.Extensions.AI.IChatClient with TokenBudgetChatMiddleware, enabling per-pipeline token budgets via NexusLabs.Foundry.MicrosoftAgentFramework.Budget.ITokenBudgetTracker. Automatically includes UsingTokenTracking(this AgentFrameworkBuilder) for token recording.

public static NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder UsingTokenBudget(this NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder syringe);

Parameters

syringe NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder

Returns

NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder

TokenBudgetExtensions.UsingTokenTracking(this AgentFrameworkBuilder) Method

Wires TokenUsageRecordingMiddleware to record token usage from every LLM call into NexusLabs.Foundry.MicrosoftAgentFramework.Budget.ITokenBudgetTracker. This enables NexusLabs.Foundry.MicrosoftAgentFramework.Budget.ITokenBudgetTracker.CurrentTokens without enforcing any budget.

public static NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder UsingTokenTracking(this NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder syringe);

Parameters

syringe NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder

Returns

NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder

Remarks

Idempotent — calling this multiple times (or via both UsingTokenBudget() and UsingDiagnostics()) wires the recording middleware exactly once.