BudgetPolicy#

class scikitplot.corpus.BudgetPolicy(max_iterations=4, max_retrieval_calls=8, max_subqueries=8, max_evidence_documents=64, max_graph_expansions=4, max_wall_time_seconds=30.0, max_context_tokens=None, max_model_tokens=None, token_counter=None, _iterations=0, _retrieval_calls=0, _subqueries=0, _graph_expansions=0, _started=None)[source]#

Deterministic, decrementing limits on an investigation.

Parameters:
max_iterationsint, optional
max_retrieval_callsint, optional
max_subqueriesint, optional
max_evidence_documentsint, optional
max_graph_expansionsint, optional
max_wall_time_secondsfloat or None, optional
max_context_tokensint or None, optional
max_model_tokensint or None, optional
token_countercallable or None, optional

str -> int. Corpus cannot know the consumer’s model, so token budgets are caller-supplied.

Parameters:
  • max_iterations (int)

  • max_retrieval_calls (int)

  • max_subqueries (int)

  • max_evidence_documents (int)

  • max_graph_expansions (int)

  • max_wall_time_seconds (float | None)

  • max_context_tokens (int | None)

  • max_model_tokens (int | None)

  • token_counter (Callable[[str], int] | None)

  • _iterations (int)

  • _retrieval_calls (int)

  • _subqueries (int)

  • _graph_expansions (int)

  • _started (float | None)

Notes

Developer. The policy is the sole authority: a model may propose a next step, the policy decides whether it runs (ADR-R10-002). Every check is arithmetic on counters and clocks, never a model call, so termination is provable.

When token_counter is None the two token budgets are reported UNENFORCEABLE rather than silently treated as unlimited. Guessing with a chunking tokenizer would give a budget wrong by an unknown, model-dependent factor – a budget that appears enforced and is not, which is the same silent-partial-evidence shape found elsewhere in this codebase.

check(*, evidence_count=0)[source]#

Return a record naming the exhausted budget, or None.

Notes

Checked before an action runs, so the loop never exceeds a budget and then reports it.

Parameters:

evidence_count (int)

Return type:

ErrorRecord | None

debit_iteration()[source]#

Record one loop iteration.

Return type:

None

debit_retrieval()[source]#

Record one retrieval call.

Return type:

None

max_context_tokens: int | None = None#
max_evidence_documents: int = 64#
max_graph_expansions: int = 4#
max_iterations: int = 4#
max_model_tokens: int | None = None#
max_retrieval_calls: int = 8#
max_subqueries: int = 8#
max_wall_time_seconds: float | None = 30.0#
spent()[source]#

Return what has been consumed so far.

Return type:

dict[str, Any]

start()[source]#

Begin the wall-clock budget.

Return type:

None

token_counter: Callable[[str], int] | None = None#
unenforceable()[source]#

Budgets this policy cannot enforce, declared rather than assumed.

Return type:

list[str]