CommBus.Budget (CommBus v0.1.0)

Copy Markdown View Source

Token budget management.

Summary

Functions

Selects entries that fit within a token budget using priority-based greedy selection.

Functions

fit_budget(entries, limit)

@spec fit_budget([CommBus.Entry.t()], non_neg_integer()) :: [CommBus.Entry.t()]

Selects entries that fit within a token budget using priority-based greedy selection.

Entries are sorted by (priority, weight, id) in descending order, then accumulated until the token limit is reached. Entries whose token_count would exceed the remaining budget are skipped.

Parameters

  • entries — List of %CommBus.Entry{} structs with token_count populated.
  • limit — Maximum number of tokens allowed.

Returns

A list of %CommBus.Entry{} structs that fit within the budget, preserving the priority-based selection order.