Skip to content
dmis-labPublic

About

An agent memory system for small language models (SLMs), featuring semantic clustering and focused long-term memory retrieval. Findings of ACL 2026.

Topics

Resources

Stars

18 stars

Watchers

0 watching

Forks

Repository files navigation

CLAG: Adaptive Memory Organization via Agent-Driven Clustering for Small Language Model Agents

Python License Paper

Official repository for the Findings of ACL 2026 paper "CLAG: Adaptive Memory Organization via Agent-Driven Clustering for Small Language Model Agents."

CLAG is an agent memory system designed for small language model (SLM) agents. It organizes long-term memory through agent-driven semantic clustering, tailoring memory organization and retrieval to SLMs' sensitivity to irrelevant context.

CLAG employs an SLM-driven router to assign incoming memories to semantically coherent clusters and autonomously generates cluster-specific profiles—including topic summaries and descriptive tags—to establish each cluster as a self-contained functional unit.

Keywords: Agent memory · LLM memory · Small language models (SLMs) · Long-term memory · Memory-augmented agents · Semantic clustering

Teaser Figure


Overview

Why do SLM agents need a dedicated memory system?

SLM agents need memory systems optimized for their capabilities. A single global retrieval pool can mix unrelated topics and expose an agent to distracting context. Small language models are especially sensitive to this irrelevant evidence, making focused memory retrieval essential. CLAG keeps memory updates local to coherent clusters and retrieves evidence in two stages to reduce cross-topic interference and keep retrieved context relevant.

CLAG addresses this problem with three key components:

  • Agentic Routing: routes each new memory into the most appropriate semantic cluster
  • Localized Evolution: refines and consolidates memories only within the routed cluster
  • Cluster-Aware Two-Stage Retrieval: first selects relevant clusters, then retrieves fine-grained evidence only inside them

Main Figure


Repository Structure

.
├── CLAG_memory.py                  # CLAG memory implementation
├── test_CLAG.py                    # Main evaluation / experiment entry point
├── prepare_bioasq.py               # BioASQ preprocessing
├── prepare_bioasq_gold_context.py  # BioASQ preprocessing utilities
├── run_prepare_bioasq_all.sh       # BioASQ preprocessing pipeline
├── data/                           # Datasets and processed files
├── logs_CLAG/                      # Experiment logs
├── results_CLAG/                   # Output results
└── figure/                         # README figures

Installation

Requirements

  • Python 3.9+ recommended

Setup

git clone https://github.com/dmis-lab/CLAG.git
cd CLAG

python -m venv .venv
source .venv/bin/activate

pip install -r requirements.txt

Note
Some NLTK resources may be downloaded at runtime if they are not already installed.


Data Preparation

Included datasets

The following datasets are already included under data/:

  • HotpotQA
  • LoCoMo

BioASQ

BioASQ is not distributed with this repository. Please download the required files from the official BioASQ participant area:

  • training10b
  • test dataset

After downloading, place the files under data/ and run:

bash run_prepare_bioasq_all.sh

This script generates processed files under data/processed/, including chunked versions used in the experiments.


Quickstart

Run CLAG evaluation with:

python3 test_CLAG.py \
  --dataset data/locomo10.json \
  --backend sglang \
  --model gpt-4o-mini

Common arguments

  • --dataset: path to the evaluation dataset JSON
  • --backend: backend to use (openai, ollama, or sglang)
  • --model: model name for the selected backend
  • --output: path to save output JSON
  • --ratio: evaluate only a subset of the dataset (0.0 to 1.0)
  • --retrieve_k: retrieval top-k (default: 10)

Backend Setup

OpenAI backend

export OPENAI_API_KEY="YOUR_KEY"

SGLang backend

By default, CLAG expects an SGLang server at:

http://localhost:30000

You can override this with:

  • --sglang_host
  • --sglang_port

Ollama backend

Make sure your Ollama server is running locally and the specified model is available.


Reproducibility

To reproduce the main experiments, use test_CLAG.py with the target dataset and backend configuration.


Citation

If you find this repository useful, please cite the Findings of ACL 2026 paper:

@inproceedings{roh-etal-2026-clag,
  title = "{CLAG}: Adaptive Memory Organization via Agent-Driven Clustering for Small Language Model Agents",
  author = "Roh, Taeyun  and
    Jang, WonJune  and
    Jung, Junha  and
    Kang, Jaewoo",
  editor = "Liakata, Maria  and
    Moreira, Viviane P.  and
    Zhang, Jiajun  and
    Jurgens, David",
  booktitle = "Findings of the {A}ssociation for {C}omputational {L}inguistics: {ACL} 2026",
  month = jul,
  year = "2026",
  address = "San Diego, California, United States",
  publisher = "Association for Computational Linguistics",
  url = "https://aclanthology.org/2026.findings-acl.824/",
  doi = "10.18653/v1/2026.findings-acl.824",
  pages = "16707--16726",
  ISBN = "979-8-89176-395-1"
}

About

An agent memory system for small language models (SLMs), featuring semantic clustering and focused long-term memory retrieval. Findings of ACL 2026.

Topics

Resources

Stars

18 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages