CalQulator
The calQulator agent estimates token costs for processing briqs. It provides transparency into potential LLM expenditure by analyzing input content, codebase context, and instructions.
How it works
1. Configuration Loading:
- Loads
config.yamlto determine which AI provider/modelconstruQtorwill use - Checks
use_qompressorsetting to know whether to consider skeletons or full codebase
2. Token Estimation Functions:
get_directory_token_size(path, model): Recursively calculates total tokens for all text filesget_file_token_size(file_path, model): Calculates tokens for a single file
3. Core Calculation (run_calqulation):
-
Identifies all briq files (
cyqleN_*.md) for current cycle -
Base Context Cost:
- Uses
bloq.d(if qompressor enabled) orqodeyardas context source - Adds 2000 token
system_prompt_bufferfor internal instructions - This sum forms
base_context_tokens
- Uses
-
Per-Briq Calculation:
- Reads briq content
- Extracts referenced filenames
- Calculates token size for referenced files
- Sums:
base_context_tokens+tokens_for_referenced_files+task_instruction_tokens - Estimates monetary cost using
lib.calculate_cost
4. Annotation:
- Annotates each briq’s Markdown title with
[Est: XXX,XXX toks | $X.XX] - Subsequent agents and users can see estimated costs directly
5. Reporting:
- Prints detailed ledger: each briq file, estimated tokens, estimated cost
- Provides grand total for entire cycle
What’s configurable
Indirect configuration via config.yaml:
agents.construqtor.provider: Influences pricing modelagents.construqtor.model: Influences tokenization and pricingoptions.use_qompressor(boolean): Determines context source (skeletons vs full code)
Environment Variables:
CYCLE_NUM: Identifies relevant briq files for current cycle
lib_funqtions.py:
- Contains
estimate_tokensandcalculate_costfunctions - Changes directly impact calQulator’s estimates