You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(flows): aggregate token/cost usage in batch_run and enforce budgets
Populate the previously dead BatchResult.tokens_total and
cost_estimate_usd fields and enforce the declared-but-unenforced
max_total_input_tokens / max_total_cost_usd guardrails.
Usage is surfaced across the run_with_observability seam via a
contextvars-scoped accumulator (quantmind/flows/_usage.py): the runner
records each run's SDK usage into the active scope, and batch_run opens
one scope per input, so per-input usage aggregates without changing any
flow's return type. Cost is caller-priced via an optional prices table
so the library ships no model prices. When a running total crosses a
budget, batch_run stops launching new work and marks skipped inputs with
BudgetExceededError.
Adds tests/flows/test_usage.py, extends tests/flows/test_batch.py, adds
examples/flows/batch_usage.py, and updates the docs/README.md catalog.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ harness.
18
18
| Paper structure build |`quantmind.flows.PaperFlow`|`PaperFlow(PaperStructureCfg)`; `build()`: `PaperInput`|`PaperStructureTree` (self-contained) |[Build and retrieve](../examples/mind/paper_structure_retrieval.py)|[Structure retrieval design](../contexts/design/mind/retrieval.md)|
19
19
| Reasoning-based retrieval (agentic) |`quantmind.mind.AgenticRetriever`|`AgenticRetriever(RetrievalCfg)`; `retrieve()`: one `StructureTree` + question (no library) |`list[RetrievalEvidence]`|[Build and retrieve](../examples/mind/paper_structure_retrieval.py)|[Structure retrieval design](../contexts/design/mind/retrieval.md)|
20
20
| News collection |`quantmind.flows.collect_news`|`NewsWindow`, `NewsCollectionCfg`|`NewsBatch` from `quantmind.preprocess`|[Collect news](../examples/flows/collect_news.py)|[News collection design](../contexts/design/flow/news.md)|
21
-
| Bounded fan-out |`quantmind.flows.batch_run`| Operation inputs and shared config|`BatchResult`|[README usage](../README.md#-usage-examples)| API docstrings |
21
+
| Bounded fan-out |`quantmind.flows.batch_run`| Operation inputs, shared config, and optional `prices` table |`BatchResult`(with aggregate `tokens_total` / `cost_estimate_usd` and budget guardrails) |[Batch usage and budgets](../examples/flows/batch_usage.py)| API docstrings |
22
22
| Local semantic search |`quantmind.library.LocalKnowledgeLibrary`|`BaseKnowledge` or `PaperFlowResult`, `SemanticQuery`|`list[SemanticHit]`|[Library example](../examples/library/README.md)|[Library guide](library.md)|
0 commit comments