adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

Clarify and Control Conversational History for LLM Token Optimization

Open borso271 opened this issue 1 year ago • 4 comments

It's unclear how the ADK Runner uses session.events and session.state to construct the contents[] array for LLM prompts. This makes it difficult to manage and predict token consumption from conversational history, leading to potentially high costs and exceeding context limits as conversations grow.

We need to understand if/how the ADK inherently manages this token growth from history, or how developers are expected to.

Describe the solution you'd like:

  • Documentation: Clearly document the default mechanism by which the ADK Runner incorporates session.events and session.state into the LLM prompt's contents[], especially regarding history length and token count.
  • Control/Configuration: Provide clear configuration options or developer hooks to manage how much and what parts of the session history are included in LLM prompts, enabling strategies like summarization or windowing to optimize token usage.

borso271 avatar May 13 '25 12:05 borso271

It's unclear how the ADK Runner uses session.events and session.state to construct the contents[] array for LLM prompts. This makes it difficult to manage and predict token consumption from conversational history, leading to potentially high costs and exceeding context limits as conversations grow.

We need to understand if/how the ADK inherently manages this token growth from history, or how developers are expected to.

Describe the solution you'd like:

  • Documentation: Clearly document the default mechanism by which the ADK Runner incorporates session.events and session.state into the LLM prompt's contents[], especially regarding history length and token count.
  • Control/Configuration: Provide clear configuration options or developer hooks to manage how much and what parts of the session history are included in LLM prompts, enabling strategies like summarization or windowing to optimize token usage.

It is not well documented, but you can use callbacks for summarization and windowing

BenMawnMahlauNBTC avatar May 14 '25 13:05 BenMawnMahlauNBTC

Thanks for raising this. We are looking into this.

hangfei avatar Jun 01 '25 23:06 hangfei

I created 8 subagents. How Can I Control output token limit of each agent

Yash-Kavaiya avatar Jul 25 '25 18:07 Yash-Kavaiya

Hi @borso271 and thanks to everyone who participated in this thread.

We're currently doing some housekeeping on our issue tracker. Given the rapid pace of development and the number of updates since this was last active, there's a good chance this issue has been resolved in a newer version. To help us keep our backlog focused on current issues, we are closing this as stale.

If you're still facing this problem, could you please update to the very latest version of the library and confirm the issue still exists? If it does, please comment here, and we will be happy to reopen this issue and investigate further.

Thanks for your contribution and understanding!

klateefa avatar Oct 07 '25 07:10 klateefa