Repository navigation
Record token usage for every model call. - #115
AlirezaValikhani wants to merge 2 commits into
Conversation
5d4d8c0 to
de69d3d
Compare
|
Thanks for picking this up! The advisor's placement inside the tool loop is exactly right, and covering subagents is a 1. Store the records in a table, not one file per call. Every tool-loop round writes a YAML file, which grows into CREATE TABLE IF NOT EXISTS token_usage (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
recorded_at TIMESTAMP NOT NULL,
session_id VARCHAR(64),
conversation VARCHAR(255),
channel VARCHAR(32),
kind VARCHAR(16),
model VARCHAR(128),
input_tokens INT NOT NULL,
output_tokens INT NOT NULL,
cache_read_tokens INT NOT NULL DEFAULT 0,
cache_write_tokens INT NOT NULL DEFAULT 0,
total_tokens INT NOT NULL
);
CREATE INDEX IF NOT EXISTS token_usage_recorded_at ON token_usage (recorded_at);Totals then become one query, and old rows can be removed with one 2. Take 3. Streaming: record only the final usage. Today the first chunk with non-zero usage is recorded, but providers 4. Cache tokens in their own columns. Since Spring AI 2.1, cached tokens are included in the prompt tokens for 5. No blocking I/O on the stream thread. Saving happens inside Smaller: record the model from the response that actually answered (a subagent may use another provider than the Happy to help if anything's unclear. |
Persist prompt and completion tokens per streaming and non-streaming round under workspace/usage so cost visibility and budgets can build on it later.
de69d3d to
d051692
Compare
All these changes are done. Please check again, and if there is a problem, leave a comment to me. Thanks, Aref. |
Persist prompt and completion tokens per streaming and non-streaming round under workspace/usage so cost visibility and budgets can build on it later.
Closese: #105