Session and context token management #544
-
I am working on an agent that will have access to MCP tools. I have a few questions related to sessions if someone can clarify. Currently if I understood the documentation correctly, when we execute the code with: session_service = DatabaseSessionService(
db_url="<DB Connection goes here>"
)
agent = LlmAgent(
... basic setup
)
runner = Runner(
app_name='some_agent_name',
agent=agent,
session_service=session_service,
)
content = types.Content(role='user', parts=[types.Part(text=query)])
events_async = runner.run_async(
session_id=session.id,
user_id=session.user_id,
new_message=content,
) For every interaction within the same chat, the LLM will get access to the FULL conversation history because we're using persistent history here. The problem I ran into is since this also includes the function_calls and function_responses, I'm running out of tokens in the context window fast. To get past this, what I'm doing is adding one more agent before this to understand whether the main agent will require old session data or not and only provide it with full session if it does. But is there a better way of doing this? Is there any way to not pass function_calls and function_responses and only pass its summary? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This looks like it might be related to #826 |
Beta Was this translation helpful? Give feedback.
You could make a callback that rewrites the history to remove the calls.
Once you have made the decision to replace a function call/response with a summary, you could store the replacement in the state to look it up on future invocations.