Ways to reduce context or event history sent to orchestrator llm
My agents keep crashing with the error code 500 and refer me to the generative ai documentation to read on.
It's most likely too much context error and I would like to know if there is a way to reduce context or summarize context whenever there is a point an LLM's context is bloated.
I have a very similar problem I know i we use the same session there's a chain of events within the session, and its somehow important to give some context to agent, but how can we limit this, I have over 200 events and the input context blows to over 30000 input tokens and hence inducing latency. Any suggestions?
Could you apply a before_model_callback to reduce the size of LLM request?
I was thinking of this very thing, I need to test it out
From another thread, I heard about invlude_contents ='none' on the sub agent but I have yet to verify if it works
https://github.com/google/adk-python/blob/3fa2ea7cb923c9f8606d98b45a23bd58a7027436/src/google/adk/flows/llm_flows/contents.py#L255
You can see this function and try to create a new one that can take some windowed history
For now I think we can either take whole content or just the most recent one as per above function definition. To answer without history we need to pass the include_content as flag string 'none' as follows
agent = LlmAgent( name="Agent", model=GEMINI_2_FLASH, instruction=SYSTEM_PROMPT, include_content="none", output_key="final_answer" )
Hello @sourabh-patil-infocusp
Did the include_content="none" solved your problem? I'm thinking of finding a way to implement "context pruning" or "context offloading" I have the examples from langchain and I'm studying if it could reduce the tokens consumption.
Thanks!
@a-ml Yes. If we set include_content = "none" then LLM gets only the recent question as history. But there should be an option that can do windowed approach. I did it on my own so that LLM can look at most recent N responses and queries. Surely, we can take inspiration from langchain.
Just being able to work with the latest context with include_content = "none" is not sufficient.
This is a definite issue when you have nested workflows.
However, one can handle the scenario by mutating the request passed in callback.
It seems we are looking for a short-term equivalent of https://google.github.io/adk-docs/sessions/memory/, to intelligently checkpoint/summarize the most relevant chat context from the current conversation. It is not clear from https://google.github.io/adk-docs/sessions/session/ whether any of the session services provide that capability. @hangfei do we have that in the ADK roadmap?
It's supported as filtering plugin: https://github.com/google/adk-python/blob/main/src/google/adk/plugins/context_filter_plugin.py