Skip to content

GML 2193 Add short-term and long-term agent memory in the KB graph (replace last-4 SQLite history) - #71

Open
prinskumar-tigergraph wants to merge 1 commit into
release_2.1.0from
feat/agent-memory
Open

prinskumar-tigergraph wants to merge 1 commit into
release_2.1.0from
feat/agent-memory

Conversation

@prinskumar-tigergraph

@prinskumar-tigergraph prinskumar-tigergraph commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds short-term and long-term agent memory so GraphRAG can remember the current conversation and durable user preferences across chats. This replaces the chat-history service for conversation storage.

STM is per conversation: recent exact turns plus a rolling summary, capped by stm_context_tokens. When the budget is exceeded, older turns are folded into the summary; rows are not deleted.

LTM is per username + graphname: mem0 extracts durable user facts (preferences, decisions, goals) after each reply. Fact text lives in Postgres; only the vector is written to TigerGraph MemoryEmbedding. conversation_id is provenance, not a recall filter, so a preference planted in chat A is available in chat B for the same user and graph.

Identity:

  • STM = username + graphname + conversation_id
  • LTM = username + graphname
  • mem0 user_id = graphname + "\0" + username

How a turn works

  1. Persist the user message in Postgres.
  2. Build STM from the rolling summary + newest turns that fit the remaining token budget. The in-flight user question is excluded so the planner does not treat it as already-answered context.
  3. If this user+graph has any facts, embed the question and search MemoryEmbedding, then join hits back to memory_facts (ltm_top_k, ltm_score_threshold). Empty scopes skip mem0/TigerGraph startup.
  4. Append the STM/LTM block to agent history as memory context, not graph evidence.
  5. After the answer, persist the assistant message. Extract + compact run asynchronously (fact_extract_async). Secrets matching _SECRET_PATTERN are dropped before extract. mem0 infer=True may ADD/UPDATE/DELETE facts; TigerGraph upserts go through memory_outbox.

MemoryEmbedding and Memory_* queries are hidden from agent-visible schema and MCP tools so the agent cannot treat the memory index as graph evidence.

Storage and deploy

Store Holds
Postgres conversations, messages, rolling summaries, fact text, fact history, outbox
TigerGraph MemoryEmbedding LTM vectors only, scoped by scope_hash(username, graphname)
mem0 2.1.0 fact extract / update / delete; persistence is swapped out

Compose and k8s replace chat-history with Postgres. Enable via memory_config in server_config.json, or GRAPHRAG_MEMORY_ENABLED / GRAPHRAG_MEMORY_DATABASE_URL.

"memory_config": {
  "enabled": true,
  "database_url": "postgresql+psycopg://graphrag:graphrag@postgres:5432/graphrag",
  "stm_context_tokens": 6000,
  "ltm_top_k": 5,
  "ltm_score_threshold": 0.7,
  "ltm_retention_days": 365,
  "max_facts_per_scope": 1000,
  "fact_extract_async": true
}

UI history/feedback routes are now graph-scoped (/ui/{graphname}/user, /conversation, /feedback) and read/write through MemoryService instead of the chat-history HTTP API.

Test plan

  • Enable memory_config, start postgres, keep chat-history stopped; rebuild the graphrag image
  • Same conversation: retrieve a graph answer, then ask a follow-up that only STM can answer (no retrieve)
  • Plant a standing preference; confirm a row in memory_facts for that user+graph
  • New conversation, same user+graph: ask only for the preference and confirm LTM recall (no STM of the plant)
  • Confirm MemoryEmbedding / Memory_* do not appear in agent-visible schema or installed-query lists
  • Confirm first message on a graph with no facts does not boot mem0/TigerGraph memory search

@prinskumar-tigergraph prinskumar-tigergraph changed the title Add agent STM/LTM memory GML 2193 Add short-term and long-term agent memory in the KB graph (replace last-4 SQLite history) Oct 15, 2026
@chengbiao-jin

Copy link
Copy Markdown
Collaborator

@prinskumar-tigergraph — GraphRAG 2.0.4 is released, and 2.1.0 work now collects on release_2.1.0, which is forked from main after the 2.0.4 release.

Please change this PR's base branch from main to release_2.1.0, and update the branch from release_2.1.0 so it includes the 2.0.4 changes. 2.1.0 will be merged into main as one release PR, as 2.0.4 was.

Thanks!

Replace chat-history with mem0-backed short-term context and user/graph-scoped long-term facts so the agent can recall conversation state and standing preferences across chats.
@prinskumar-tigergraph
prinskumar-tigergraph changed the base branch from main to release_2.1.0 October 23, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants