Skip to content
This page was translated from the Chinese original, which has changed since — it may be out of date. The Chinese version is authoritative. View the Chinese original →
MemX × Kova × Lurus API

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.

30 minutesTime to running
6 stepsFrom dependencies to write-back
3 servicesMemX · Kova · API

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.

AI support agent with memory architecture
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 --> A

6 steps ​

  1. Install dependencies

    bash
    pip install lurus memx-client kova-py lumen-ai openai
  2. Initialize the three services

    python
    from 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")
  3. Define the Agent state

    python
    from typing import TypedDict, Annotated, Sequence
    
    class State(TypedDict):
        user_id: str
        messages: Annotated[Sequence, "chat history"]
        relevant_memory: list
  4. Recall history — fetch memories from MemX relevant to the current question

    python
    def 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}
  5. Call the LLM and return — inject the recalled facts into the system prompt

    python
    def 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}]}
  6. Distill and write back — write the new conversation back to MemX so it's available on the next recall

    python
    def 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:

python
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.

Next steps ​

Next steps

Powered by Lurus Technologies