Back to stack
Dec 21, 2025
2 min read

CalQulator – The Cost Estimator

Provides token cost transparency by analyzing briqs before execution

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.yaml to determine which AI provider/model construQtor will use
  • Checks use_qompressor setting 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 files
  • get_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) or qodeyard as context source
    • Adds 2000 token system_prompt_buffer for internal instructions
    • This sum forms base_context_tokens
  • 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 model
  • agents.construqtor.model: Influences tokenization and pricing
  • options.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_tokens and calculate_cost functions
  • Changes directly impact calQulator’s estimates