Token estimation for context planning and compression.
Token counting helps you estimate context token count for an Agent run. Token counting can be used for features like token-based context compression and memory optimization.
Content of the message - Includes the system message, user message, and the assistant message content.
Tool call arguments and results
Optional reasoning content
Multimodal content blocks
Tools
Tool definitions can be a meaningful part of the total token count, especially with large parameter schemas or long descriptions.
Output schema
If you use an Output Schema, the schema is included in the token count.
Multimodal attachments
Images, audio, video, and files attached to messages are counted using conservative estimates.
Token counts are estimates. Provider billing and exact tokenization can
differ due to model/provider behavior, hidden/system prompts, and how
tools/schemas are serialized internally.
When you set compress_token_limit, Agno checks the estimated token count during the run loop and triggers compression when the threshold is reached.Because token counting can include message history, tool definitions, and the output schema/response format, it more closely matches the “true” request size than counting only message text.
Token counting is still in Beta. We do our best to provide an estimate but we do not claim it to be 100% accurate across all providers and models. Please be wary of using this token count for calculating costs.
For some providers like Claude we are able to call the exact endpoint and get an exact token count. This is not supported for all providers yet.