---
title: "MemEx: A Programmable Scratchpad for LLM Agents"
description: "MemEx addresses the context-window bottleneck in LLM agents, where large tool outputs persist in the shared prompt even when later steps need only a small portion. It gives the agent a persistent, typed Python kernel: tool results remain as objects in scope, code can filter, summarize, and compose them, and only printed values are materialized as context tokens. MemEx preserves existing Tool Calling schemas while adding typed submit(), persistent state, backend-agnostic execution, and asynchronous spawn_agent() sub-agents, enabling multi-step workflows and parallel trajectory analysis. Across nine-model evaluations on OfficeQA Pro and Enterprise Structured Retrieval, it was reported as better and cheaper than parallel structured Tool Calling; examples include roughly 10-point OfficeQA gains for some models and Qwen structured-retrieval accuracy rising from 18% to 36% and 20% to 38% at lower token cost."
---

# MemEx: A Programmable Scratchpad for LLM Agents

[Databricks](https://yomu.fyi/company/databricks) · The Databricks AI Research Team · May 19, 2026

**Type:** Explainer

## Summary

MemEx addresses the context-window bottleneck in LLM agents, where large tool outputs persist in the shared prompt even when later steps need only a small portion. It gives the agent a persistent, typed Python kernel: tool results remain as objects in scope, code can filter, summarize, and compose them, and only printed values are materialized as context tokens. MemEx preserves existing Tool Calling schemas while adding typed submit(), persistent state, backend-agnostic execution, and asynchronous spawn\_agent() sub-agents, enabling multi-step workflows and parallel trajectory analysis. Across nine-model evaluations on OfficeQA Pro and Enterprise Structured Retrieval, it was reported as better and cheaper than parallel structured Tool Calling; examples include roughly 10-point OfficeQA gains for some models and Qwen structured-retrieval accuracy rising from 18% to 36% and 20% to 38% at lower token cost.

## Context

LLM agents use the context window as the persistent substrate for prompts, reasoning, tool calls, and raw tool outputs. Large results, such as SQL query outputs, are carried through later turns even when only a small part is relevant, making agent traces token-heavy, lossy, slow, expensive, and vulnerable to cascading errors.

## Approach / What changed

MemEx replaces repeated text-based tool-output handling with a persistent typed Python kernel integrated into an existing ReAct-style agent loop. Tools retain parameter schemas and become typed Python functions; outputs persist as objects, code performs transformations before results reach the model, submit() returns typed objects, and spawn\_agent() enables asynchronous sub-agents. Execution supports in-process, subprocess, and pool backends.

## Takeaways

- Existing Tool Calling tools are auto-injected as Python functions with their parameter schemas and return-type metadata, allowing a switch to MemEx through a configuration change.
- MemEx supports in-process execution for research, subprocess isolation for evaluation, and pooled execution for high-throughput batch generation; production deployments can use a hosted sandbox with filesystem, network, and resource controls.
- For trajectory aggregation, a MemEx agent can inspect full prior traces rather than summaries; one reported case found a duplicate-data error that the summary-based Tool Calling aggregator could not verify.

**Tags:** [AI Agents](https://yomu.fyi/topic/ai-agents), [Architecture](https://yomu.fyi/topic/architecture), [Python](https://yomu.fyi/topic/python)

- Source: [Databricks](https://www.databricks.com/blog/memex-programmable-scratchpad-llm-agents)
- Source URL: https://www.databricks.com/blog/memex-programmable-scratchpad-llm-agents
- Ingested by Yomu: 2026-08-31T03:34:17.894Z

[Read original post](https://www.databricks.com/blog/memex-programmable-scratchpad-llm-agents)
