Skip to content

NexusLabs.Needlr.AgentFramework.Workflows.Budget

NexusLabs.Needlr.AgentFramework.Workflows

NexusLabs.Needlr.AgentFramework.Workflows.Budget Namespace

Classes
ContextWindowGuardMiddleware Microsoft.Extensions.AI.DelegatingChatClient safety net that estimates cumulative context size across LLM calls and emits a warning when approaching a configurable limit. Optionally prunes oldest non-system messages to keep context under the limit.
TokenBudgetChatMiddleware Microsoft.Extensions.AI.DelegatingChatClient that enforces token budget limits by aborting when NexusLabs.Needlr.AgentFramework.Budget.ITokenBudgetTracker thresholds are exceeded. Depends on TokenUsageRecordingMiddleware (wired as an inner middleware) to keep the tracker's token counts up to date.
TokenBudgetExtensions Extension methods for wiring token-budget enforcement into the agent framework.
TokenUsageRecordingMiddleware Lightweight Microsoft.Extensions.AI.DelegatingChatClient that records token usage from each LLM call into NexusLabs.Needlr.AgentFramework.Budget.ITokenBudgetTracker. Does NOT enforce budgets — that is the responsibility of TokenBudgetChatMiddleware.