Long Term Memery for Agent

Hello everyone, when users engage in long conversations, what is the best practice for efficiently remembering the dialogue?

For example, if a user typically has 20 turns in a single conversation, it can cause the context window to overflow, consume a large number of tokens, and require frequent queries to the database to retrieve context…

Hi @hunglv53, thanks for reaching out and supporting Agno. I’ve shared this with the team, we’re working through all requests one by one and will get back to you soon.If it’s urgent, please let us know. We appreciate your patience!

Hi @hunglv53
You can enable efficient context handling by summarizing old sessions and limiting how much history is loaded each time.

I’d recommend this setup:
agent = Agent(
db=db,
add_history_to_context=True,
num_history_runs=3, # Only last 3 turns
enable_session_summaries=True, # Auto-summarize
enable_user_memories=True, # Store key facts
read_chat_history=True # Tool to read older messages
)

  • enable_session_summaries=True → automatically summarizes long chat histories

  • num_history_runs=3 → keeps only the last 3 exchanges in context

  • enable_user_memories=True → stores key facts about users persistently

  • read_chat_history=True → allows fetching older messages when needed

This keeps the memory lightweight while still maintaining continuity across sessions.

You can refer the below docs for more information. Thanks