How It Works
Async enforcement (1.6.88+):
ExecutionConfig(max_budget=...) is now enforced on async agent runs (astart()) as well as sync runs. BudgetExceededError is raised on both paths when the cap is exceeded. Gateway bots also honour the budget.Quick Start
1
Agent with Knowledge
Knowledge retrieval applies token budgets automatically when indexing and retrieving.
2
Long-Context Model (gpt-5)
Pass a model name and the window resolves automatically — gpt-5 unlocks the full 1M context.
3
Direct Budget Control
Use
TokenBudget when building custom RAG pipelines.Configuration
TokenBudget Options
Model Context Windows
RAG context-window values are sourced from a single canonical
MODEL_LIMITS table shared with the rest of the SDK; RAG-only extras (Mistral, Llama, DeepSeek, Cohere, o1 variants, gpt-4-32k) are layered on top. Values here match get_model_context_window() exactly — pass any model name and get the same window everywhere.As of PraisonAI PR #3796, the shared context-window lookup consults litellm’s
model_cost registry first, so any litellm-known model (Mistral, DeepSeek, xAI, Qwen, Bedrock, Azure, OpenRouter, versioned OpenAI/Anthropic/Google ids) resolves to its true window even when it is not in the table below. The static table is the offline fallback. See How the context window is resolved for the full order.Unknown or versioned model names resolve via partial match (e.g.
gpt-4o-2024-05-13 → gpt-4o). The default 128,000 tokens only applies when both litellm and the static partial-match miss.Budget Enforcement
BudgetEnforcerProtocol for priority-based or custom selection strategies.
CLI Usage
Best Practices
Reserve adequate response tokens
Reserve adequate response tokens
Leave enough headroom for complete answers — undersized
reserved_response truncates outputs mid-sentence.Account for chat history
Account for chat history
Multi-turn conversations consume tokens quickly; increase
reserved_history or enable context compaction on long sessions.Match budget to model
Match budget to model
Different models have different context windows — always pass the actual model name so
dynamic_budget() calculates correctly.Monitor with verbose indexing
Monitor with verbose indexing
Run
praisonai knowledge index ./docs --verbose to see chunk counts and token estimates before production retrieval.Related
Thinking Budgets
Extended reasoning token limits
Token Usage Protocol
Track token consumption across runs

