Skip to content

[FEATURE] Track agent.messages token size #1197

@kmukher-amz

Description

@kmukher-amz

Problem Statement

Currently strands has accumulated token usage which keeps track of all the tokens used in the current turn. However, it is often useful to know what the token size of the current agent context (agent.messages) is. This value can be used for proactive conversation management (current tokens > threshold) or just to expose to a downstream user.
Today one option is to use count_tokens provided by bedrock but this tends to eat up TPM limits pretty fast as well as adding to the latency of the over-all turn.

Proposed Solution

Add another tracked metric in event logs that keeps track of current agent context token size.

Use Case

For proactive memory/context management (to trigger summarization) and to expose this information to a downstream user.

Alternatives Solutions

Today one option is to use count_tokens provided by bedrock but this tends to eat up TPM limits pretty fast as well as adding to the latency of the over-all turn.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions