CoolFace
Apppublic

venkateshannabathina/agent-memory-compressor

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
App README

๐Ÿง  Agent Memory Compressor

An OpenEnv reinforcement learning environment that trains AI agents to compress bloated conversation histories while preserving critical facts, avoiding hallucinations, and resolving contradictions.

Motivation

AI agents in production break down as conversations grow long. They lose track of key facts, get confused by contradictions across sessions, and eventually exceed their context window. This environment simulates that exact problem โ€” giving agents a real memory dump and challenging them to compress it intelligently. Every decision (what to keep, what to cut, what to resolve) is scored automatically.

ex:- The goal is to compress a long conversation into the shortest possible memory that still tells the full story. Like turning "Venky left home at 8:30am, took the bus, reached school by 9:00am, attended all classes, had lunch at 1pm, finished at 5:00pm and went home" into just "Venky: school 9amโ€“5pm." Same information, fraction of the size. ---

Environment Overview

PropertyValue
Tasks3 (easy, medium, hard)
Reward range0.0 โ€“ 1.0
Episode length1 step
StateIn-memory (stateless across restarts)
InterfaceHTTP REST API (FastAPI)

Observation Space

Returned by /reset. Contains everything the agent needs to attempt compression.

FieldTypeDescription
memory_dumplist of turnsFull conversation history (role + content)
task_contextstringWhat a downstream agent needs to know
token_budgetintMaximum tokens allowed in compressed output
task_idstringTask identifier (easy / medium / hard)
stepintCurrent step number

Action Space

Submitted to /step. The agent's compressed response.

FieldTypeDescription
compressed_memorystringThe compressed summary of the conversation
removed_itemslist of stringsWhat the agent decided to discard
conflicts_resolvedlist of stringsContradictions found and resolved (hard task)
compression_ratiofloat (0โ€“1)Size of output relative to input

Reward Function

Scores are computed deterministically by grader.py.

ComponentMaxLogic
Facts preserved+0.5Checks key facts survived compression
Compression bonus+0.2โ‰ค0.3 ratio โ†’ +0.2, โ‰ค0.5 โ†’ +0.1
Conflict resolution+0.2Agent must resolve contradictions in hard task
Hallucination penalty-0.3-0.1 per trap found in output, capped at -0.3

Final score is clamped between 0.0 and 1.0.


Tasks

Easy โ€” Subscription Cancellation

A customer support conversation where a user wants to cancel their Pro subscription. The agent must extract the key facts (email, deadline, intent) and compress the conversation tightly.

  • โ€”Token budget: 150
  • โ€”Key facts: 3
  • โ€”Hallucination traps: 2

Medium โ€” API Debugging Session

A technical troubleshooting conversation about a broken API integration. The root cause is buried deep in the conversation. The agent must identify it and preserve it without getting distracted by noise.

  • โ€”Token budget: 200
  • โ€”Key facts: 4
  • โ€”Hallucination traps: 3

Hard โ€” Multi-session Address Conflict

A conversation spanning multiple sessions where the user's delivery address changes and contradicts earlier sessions. The agent must identify the conflict, resolve it, and produce a clean compressed memory.

  • โ€”Token budget: 180
  • โ€”Key facts: 3
  • โ€”Hallucination traps: 2
  • โ€”Conflicts to resolve: 1

Inference Scores

Inference run using LLM via compatible API.

TaskScoreFactsCompression Ratio
Easy0.93/30.14
Medium0.94/40.15
Hard0.93/30.13
Average0.9

API Endpoints

EndpointMethodDescription
/GETHealth check
/healthGETReturns {"status": "ok"}
/resetPOSTStart a new episode, returns observation
/stepPOSTSubmit action, returns reward and score
/stateGETGet current episode state
/tasksGETList all tasks and action schema
/graderPOSTGet grader status for an episode
/baselineGETRun inference script across all 3 tasks

Setup & Usage

Local

bash
git clone https://huggingface.co/spaces/venkateshannabathina/agent-memory-compressor
cd agent-memory-compressor
pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 7860

Docker

bash
docker build -t agent-memory-compressor .
docker run -p 7860:7860 \
  -e HF_TOKEN=your_key \
  -e API_BASE_URL=https://api.groq.com/openai/v1 \
  agent-memory-compressor

Environment Variables

VariableDescription
HF_TOKENYour Hugging Face / API token
API_BASE_URL'https://api.groq.com/openai/v1'
MODEL_NAMEgpt-oss-120b
ENV_URLhttps://venkateshannabathina-agent-memory-compressor.hf.space

Running Inference

bash
python inference.py

Project Structure

agent_memory_compressor/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ main.py        # FastAPI server and endpoints
โ”‚   โ”œโ”€โ”€ env.py         # Environment logic (reset, step, state)
โ”‚   โ”œโ”€โ”€ grader.py      # Scoring engine
โ”‚   โ”œโ”€โ”€ dataset.py     # Raw memory dumps and gold standards
โ”‚   โ”œโ”€โ”€ tasks.py       # Public task catalog
โ”‚   โ””โ”€โ”€ models.py      # Pydantic data models
โ”œโ”€โ”€ server/
โ”‚   โ””โ”€โ”€ app.py         # Entry point for openenv
โ”œโ”€โ”€ inference.py       # Inference script
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ openenv.yaml

Built With


Built for the Meta x Scaler OpenEnv Hackathon 2026 by Venkatesh Annabathina,praneeth,aryashi.