CodeMem: Architecting Reproducible Agents via Dynamic MCP and Procedural Memory

AuthorsNishant Gaurav, Adit Akarsh, Tejas Ravishankar, Manoj Bajaj

2025

TL;DR

CodeMem uses a Dynamic MCP layer plus a persistent procedural memory bank to turn sandboxed Python workflows into reproducible skills, reaching 96% correctness with Gemini 3 Full.

SharePost on XLinkedIn

Read our summary here, or open the publisher PDF on the next tab.

THE PROBLEM

Agents Reinvent Logic and Drift Without Procedural Memory

CodeMem targets probabilistic instability where agents follow different trajectories for the same task, wasting planning and debugging time every run.

This instability breaks repetitive workflows like Outlook to OneDrive orchestration, causing trajectory divergence, context collapse, and unreliable execution for multi-step tool chains.

HOW IT WORKS

CodeMem Architecture with Dynamic MCP and Procedural Memory Bank

CodeMem centers on search_functions, load_functions, write_todos, execute_code, and register_skill to discover tools, plan tasks, execute code, and freeze successful logic.

Think of CodeMem as an LLM architect designing scripts, a sandbox CPU executing them, and a procedural memory bank acting like a versioned code library instead of a fragile prompt.

This KEY_MECHANISM lets CodeMem move complex loops and filters into deterministic Python, enabling infinite-depth workflows and reproducible skills that plain context windows and prompt edits cannot guarantee.

DIAGRAM

CodeMem Workflow for Outlook OneDrive Bridge

This diagram shows how CodeMem handles the Outlook OneDrive Bridge case study from discovery to sandbox execution and skill registration.

DIAGRAM

CodeMem Evaluation Pipeline Across 25 Tasks

This diagram shows how CodeMem is evaluated on 25 multi step tasks using Gemini 2.5 Flash as an LLM as a Judge.

PROCESS

How CodeMem Handles a Multi Step Agentic Task Lifecycle

  1. 01

    Discovery and Planning

    CodeMem uses search_functions and load_functions to discover Dynamic MCP tools, then write_todos to externalize a Pending to Completed checklist for the task.

  2. 02

    Script Generation

    CodeMem authors Python using execute_code in a sandbox, composing loops and conditionals that orchestrate tools like Outlook and OneDrive deterministically.

  3. 03

    Execution and Self Correction

    CodeMem runs the script, inspects stdout and stderr, and updates write_todos to recover state, iterating until the workflow matches user constraints.

  4. 04

    Skill Registration and Reuse

    CodeMem calls register_skill to freeze the validated agent_main function into procedural memory, enabling future runs to skip planning and coding.

KEY CONTRIBUTIONS

Key Contributions

  • 01

    CodeMem Architecture

    CodeMem combines Dynamic MCP search_functions and load_functions with execute_code and register_skill to turn ephemeral scripts into deterministic procedural memory for agents.

  • 02

    Procedural Memory via Frozen Code

    CodeMem treats procedural memory as versioned Python functions, avoiding brittle prompt updates and ensuring deterministic execution of workflows like the Outlook OneDrive Bridge.

  • 03

    Experimental Benchmark on 25 Tasks

    CodeMem evaluates Gemini 3 Full, Claude 4.5 Sonnet, and GPT-5 Chat on 25 multi step tasks, reporting 96% minimum correctness and 100.48s P50 latency for Gemini 3 Full.

RESULTS

By the Numbers

Correctness Min

96%

+28 percentage points over GPT-5 Chat

Avg Calls

7.00

Gemini 3 Full vs 2.80 for GPT-5 Chat

P50 Latency

100.48s

Longer latency than 14.75s GPT-5 Chat due to deeper iteration

Total Tokens

2.02M

Token budget for Gemini 3 Full trajectories on 25 tasks

Table 2 reports CodeMem performance on a 25 task benchmark of multi step agentic workflows. The 96% minimum correctness for Gemini 3 Full shows that CodeMem can reliably complete complex tool chains when allowed to iterate about seven times per task.

BENCHMARK

By the Numbers

Table 2 reports CodeMem performance on a 25 task benchmark of multi step agentic workflows. The 96% minimum correctness for Gemini 3 Full shows that CodeMem can reliably complete complex tool chains when allowed to iterate about seven times per task.

BENCHMARK

Performance Comparison on CodeMem Benchmarks

Correctness Min across models when using CodeMem on 25 multi step tasks.

KEY INSIGHT

The Counterintuitive Finding

GPT-5 Chat shows the lowest P50 latency at 14.75s and only 0.49M tokens, yet its minimum correctness is just 68% on CodeMem tasks.

This is surprising because faster, cheaper runs usually seem better, but CodeMem reveals that shallow trajectories with 2.80 calls miss edge cases that higher reasoning models reliably handle.

WHY IT MATTERS

What this unlocks for the field

CodeMem unlocks reproducible, deterministic workflows where agents architect Python pipelines once, then reuse them as procedural memory without re planning or re coding.

Builders can now treat LLMs as workflow designers that crystallize skills into code, enabling Zapier like reliability for complex multi tool automations that were previously brittle and stochastic.

~12 min read← Back to papers

Related papers

BenchmarkAgent Memory

Active Context Compression: Autonomous Memory Management in LLM Agents

Nikhil Verma

· 2026

Focus Agent adds start_focus, complete_focus, a persistent Knowledge block, and an optimized Persistent Bash plus String-Replace Editor scaffold to actively compress context during long software-engineering tasks. On five hard SWE-bench Lite instances against a Baseline ReAct agent, Focus Agent achieves 22.7% token reduction (14.9M → 11.5M) while matching 3/5 = 60% task success.

Questions about this paper?

Paper: CodeMem: Architecting Reproducible Agents via Dynamic MCP and Procedural Memory

Answers use this explainer on Memory Papers.

Checking…