shreyanbr/openenv-memory-management
Memory Management RL Environment
An OpenEnv benchmark for training agents to selectively remember, update, retrieve, and forget under a fixed memory budget.
Why This Matters
Long-running assistants constantly hit the same wall: context is expensive, user state changes, and simple memory policies either hoard everything or drop the one thing that actually mattered. This environment puts that problem front and center with realistic multi-turn conversations, tight budgets, and adversarial noise.
Specifically, agents are tested on:
- preferences that need to be stored and recalled later
- corrections that should replace stale memory, not stack on top of it
- confabulations and distractors that look relevant but should be ignored
- formatting constraints that the final answer must actually follow
- memory budgets that force prioritization rather than brute-force storage
What Gets Tested
Tasks
On medium and hard, current_turn_kind returns "unknown". Agents have to read the message and figure out intent themselves rather than relying on the label.
Reward
Terminal reward comes from deterministic grader metrics:
R = 0.40 * success
+ 0.18 * precision
+ 0.12 * recall
+ 0.10 * constraint_adherence
+ 0.05 * compactness
+ 0.05 * freshness
+ 0.10 * non_interference
- penaltiesDense step rewards fire on each store, retrieve, ignore, update, delete, and answer action during the episode. Final task scores are clamped to the strict open interval (0, 1), so externally reported scores are never exactly 0.0 or 1.0.
Quick Start
uv venv .venv
uv pip install -r requirements.txt --python .venv
.venv/bin/python -m unittest tests/test_core.py -vStart the server:
.venv/bin/uvicorn server.app:app --host 0.0.0.0 --port 7860Run baseline agents:
.venv/bin/python run_baseline.py
.venv/bin/python run_baseline.py --task hard_full_memory_management
.venv/bin/python run_baseline.py --jsonLLM Agent Evaluation
# Anthropic
ANTHROPIC_API_KEY=sk-ant-... .venv/bin/python run_llm_agent.py
# OpenRouter
OPENROUTER_API_KEY=sk-or-... .venv/bin/python run_llm_agent.py \
--provider openrouter --model anthropic/claude-haiku-4-5
# Single task, specific seeds
ANTHROPIC_API_KEY=... .venv/bin/python run_llm_agent.py \
--task easy_preference_recall --seeds 42 43 44
# JSON output
ANTHROPIC_API_KEY=... .venv/bin/python run_llm_agent.py --jsonBenchmark Results (claude-haiku-4-5, 5 seeds)
The LLM agent beats the rule-based baseline by a wide margin on the hard task.
Python Usage
from src.memory_management_agent import MemoryManagementEnv, RuleBasedMemoryAgent, run_episode
env = MemoryManagementEnv(memory_budget=200)
agent = RuleBasedMemoryAgent()
result = run_episode(agent, env, seed=42)
print(result.reward)
print(result.metrics.constraint_adherence)Task-aware setup:
from src.memory_management_agent import TASK_HARD, generator_for_task
from src.memory_management_agent.environment import MemoryManagementEnv
env = MemoryManagementEnv(
generator=generator_for_task(TASK_HARD),
memory_budget=TASK_HARD.memory_budget,
max_turns=TASK_HARD.max_turns,
expose_turn_kind=TASK_HARD.expose_turn_kind,
decay_rate=TASK_HARD.decay_rate,
)HTTP API
GET /healthGET /tasksPOST /resetPOST /stepPOST /graderGET /baselineWS /ws(OpenEnv WebSocket)
curl -s http://localhost:7860/tasks
curl -s -X POST http://localhost:7860/reset \
-H 'Content-Type: application/json' \
-d '{"task_id":"medium_preference_constraint_correction","seed":42}'Score Interpretation
Repository Layout
src/memory_management_agent/
agents.py # baseline heuristic agents
environment.py # reset/step loop
episode.py # conversation template pools
grader.py # deterministic reward composer
memory_store.py # budgeted memory with decay
tasks.py # easy / medium / hard task generators
training.py # prompt building and rollout collection
server/
app.py # FastAPI server (HTTP + WebSocket)
tests/test_core.py
run_baseline.py # rule-based baseline evaluation
run_llm_agent.py # LLM agent evaluation (Anthropic / OpenRouter)
inference.py # submission inference script
openenv.yaml # OpenEnv manifest