Skip to content

Functional Response Token Accounting

Choose a tag to compare

@Foxfire1st Foxfire1st released this 30 May 20:57

Agents Remember 0.9.5

Makes the response token counter functional: every MCP tool response now reports an accurate token count instead of placeholder zeros.

Highlights

  • The token-accounting engine (models/tokens.py) is now wired into the single response choke point (_tool_payload), so every public tool response carries a real tokens, tokenizer, and tokenCountExact. Previously these shipped as Pydantic defaults (0 / "" / false).
  • Default tokenizer is tiktoken o200k_base (tokenCountExact: true), with a deterministic approximate counter retained as a fallback.
  • Widened response_payload / dump_with_token_count to accept any ResponseModel, so operation-less responses such as ping are counted too.
  • Added test_tokens.py — first direct coverage of the counters, serializers, and the count fixpoint.

Verification

Full quality wrapper green (ruff clean, Pyright 0 errors, 289 passed / 3 skipped). ping now reports tokens: 44, tokenizer: "tiktoken:o200k_base", tokenCountExact: true.