Inspiration

Coding agents re-read the same files and re-discover the same fixes on every session because they have no memory between runs. That's wasted tokens and wasted time. We wanted a memory layer that learns how a bug was fixed the same way a person does: not by re-reading the whole history, but by remembering the shape of the problem and where the fix lives.

What it does

Cogram is a zero-LLM procedural memory layer for coding agents. It builds a concept graph from past agent trajectories (SWE-agent style bug-fix sessions): every recurring term becomes a node, co-occurring terms become weighted edges, and each edge is tagged with the exact file and line it came from. No LLM call is used to build or query this graph -- it's pure statistics (token counts, co-occurrence, IDF-style discounting for boilerplate).

On a new bug report, Cogram activates the matching concepts, walks the graph to the most relevant lines across the whole corpus, and hands a small, ranked, provenance-tagged context (which file, which line) to Qwen Cloud, which writes the final grounded answer. The memory layer costs zero LLM tokens; the only LLM call is the last-mile answer generation.

Two mechanisms make it behave like real memory instead of a static index:

  • Tick-based decay: edge weight only fades on the agent's own interaction ticks, not wall-clock time. An idle agent's memory freezes instead of rotting.
  • Surprise-gated promotion: new concepts and "concept-of-concepts" motifs (recurring problem+fix clusters) are promoted based on how novel/surprising they are (a prediction-error-style signal), not a fixed frequency threshold.

How we built it

  1. Pulled a public slice of the nebius/SWE-agent-trajectories dataset (600 real bug-fix sessions across many repos) and converted it into per-session transcripts.
  2. Built the concept graph with graph_lib.py / extract_swe.py: tokenize, weight edges by co-occurrence, cap edges per node, mine higher-level "motifs" (problem-fix clusters) with a self-calibrating surprise threshold.
  3. Built memory_api.py, a facade that turns the graph into an active memory recommender (query -> ranked, provenance-tagged lines, under a token budget).
  4. Added qwen_agent.py: takes the zero-token recall from memory_api, and makes exactly one Qwen Cloud call (OpenAI-compatible DashScope endpoint) to turn it into a grounded natural-language answer.
  5. Deployed the whole pipeline behind an HTTP endpoint on Alibaba Cloud Function Compute (deploy/fc_handler.py, deploy/s.yaml).
  6. Wrote benchmark_procedural_precision.py to measure whether the memory layer actually routes a new bug report to the correct repository/fix -- not just whether it "feels" relevant.

Challenges we ran into

  • Generic SWE-agent prompt boilerplate ("We're currently solving the following issue...") was polluting both the concept graph and the benchmark queries. We added an IDF-style discount so common terms stop dominating recall.
  • Early motif mining produced one giant undifferentiated blob because high-frequency "hub" terms bridged unrelated bug fixes. Fixed by excluding hub concepts and capping motif size.
  • Getting decay right without using wall-clock time meant re-deriving "time" as agent-experienced ticks, which changes how you think about forgetting: nothing decays while the agent is idle.

Accomplishments that we're proud of

  • A memory layer that stores roughly 4x less data than the raw transcripts it's built from (interned graph vs. raw corpus, gzip-compared), while remaining lossless where it counts: every edge carries an exact file:line pointer back to source, so nothing is invented, only found.
  • Zero LLM calls anywhere in the write path (graph construction, decay, motif mining) -- only the final answer step touches an LLM.
  • A dedicated precision benchmark (not just "looks relevant") that shows the graph actually routes queries to the right repository.

What we learned

Memory doesn't need to be an LLM summarizing an LLM. A lot of what makes memory useful -- provenance, controllable forgetting, cheap incremental updates -- comes for free from plain statistics if you're willing to give up trying to make it "understand" anything.

What's next for Cogram

Drop-in adapters for SWE-agent, OpenHands, and Claude Code hooks so any agent gets this memory layer with zero code changes; validating the directed "next step" ordering (not just "which line"), with a dedicated benchmark.

Links

Built With

  • alibaba-cloud-function-compute
  • dashscope
  • jieba
  • nebius/swe-agent-trajectories-dataset
  • python
  • qwen-cloud
  • serverless-devs
  • tiktoken
Share this project:

Updates