adk-docs
adk-docs copied to clipboard
Session Persistence Through Callbacks
Is your feature request related to a problem? Please describe.
I'm trying to modify session state and events through ADK callbacks, but changes don't persist properly between invocations. When using callbacks to modify session.events (adding, removing, or marking events), the modifications either don't persist or don't affect subsequent LLM requests as expected. It's unclear if session mutations through callbacks are officially supported or if there are specific patterns that should be followed.
The Context docs mention that "modifications to state or artifacts made via context methods are automatically linked to the current step's EventActions and handled by the SessionService" but don't extend this guidance to session events.
Describe the solution you'd like
(Not sure if this already exists) Either documentation or support for:
- Whether session.events can be safely modified within callbacks
- How to ensure session modifications persist across invocations
- Best practices for maintaining custom session state that affects LLM context
- Official methods for controlling which events are included in LLM requests
Describe alternatives you've considered
- Using event.actions.state_delta for custom event metadata
- Modifying session.events directly in callbacks
Additional context
The implementation is for a summarization callback in which based on a max message threshold, I want a callback to directly be able to generate a summary of the 'new' short-term items (not the issue) and remove the summarized events directly from the session within the callback. Currently I am able to generate & append to summaries through state and use that state to inject the summary into the agent's instructions or system message, but am unable to directly remove the events that were summarized.
I have been able to get away with keeping a index of summarized messages along with the summary itself within the state and removing the appropriate content within a 'before_model' callback.