Build an AI Support Agent with Memory
Goal: in 30 minutes, get a support Agent running that remembers a user's past questions, recovers automatically from crashes, and distills knowledge on demand.
Architecture diagram
Three services each play a distinct role: MemX handles long-term memory recall and distillation, the Lurus API handles LLM calls, and the Kova WAL handles state persistence and crash recovery.
graph LR
U[User] --> W[Web frontend]
W -->|HTTP| A[Agent App]
A -->|1. Recall| M[MemX]
A -->|2. LLM| L[Lurus API]
A -->|3. State| K[Kova WAL]
A -->|4. Write| M
L --> A
M --> A6 steps
Install dependencies
bashpip install lurus memx-client kova-py lumen-ai openaiInitialize the three services
pythonfrom openai import OpenAI from memx import Memory from kova import KovaClient llm = OpenAI(base_url="https://hub.lurus.cn/v1", api_key="sk-...") mem = Memory(config={"ace_enabled": True}) kova = KovaClient("kova://localhost")Define the Agent state
pythonfrom typing import TypedDict, Annotated, Sequence class State(TypedDict): user_id: str messages: Annotated[Sequence, "chat history"] relevant_memory: listRecall history — fetch memories from MemX relevant to the current question
pythondef retrieve_memory(state: State) -> State: last = state["messages"][-1]["content"] hits = mem.search(last, user_id=state["user_id"], limit=5) return {**state, "relevant_memory": hits}Call the LLM and return — inject the recalled facts into the system prompt
pythondef respond(state: State) -> State: context = "\n".join(h["text"] for h in state["relevant_memory"]) resp = llm.chat.completions.create( model="deepseek-chat", messages=[ {"role": "system", "content": f"已知事实:\n{context}"}, *state["messages"], ], ) reply = resp.choices[0].message.content return {**state, "messages": [*state["messages"], {"role": "assistant", "content": reply}]}Distill and write back — write the new conversation back to MemX so it's available on the next recall
pythondef distill(state: State) -> State: mem.add( list(state["messages"][-2:]), user_id=state["user_id"], scope="support:general", ) return state
Add Kova crash recovery
Wire Kova in as the LangGraph checkpointer so that after the Agent crashes it recovers from the WAL without re-calling the LLM:
from kova.langgraph import KovaCheckpointer
graph = wf.compile(checkpointer=KovaCheckpointer(kova))Why no re-call to the LLM
Kova writes a write-ahead log (WAL) for every step. After a process crash, the engine replays execution state from the checkpoint, and LLM calls that already completed are not issued again — saving tokens while keeping the answer consistent.
Complete project artifact
Example repository
https://github.com/hanmahong5-arch/lurus-examples/tree/main/memory-agent — includes the full code, docker-compose.yml (run MemX + Kova locally), Pytest covering the three nodes, and .env.example.