AgentSM: Semantic Memory for Agentic Text-to-SQL

AuthorsAsim Biswal, Chuan Lei, Xiao Qin et al.

2026

TL;DR

AgentSM uses structured semantic memory plus composite tools to reuse Text-to-SQL trajectories, reaching 44.8% execution accuracy on Spider 2.0 Lite (+16.1 points over SpiderAgent).

SharePost on XLinkedIn

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

THE PROBLEM

Agentic Text-to-SQL Wastes Steps and Still Misses Answers (25% accuracy, 22.62 steps)

Existing Text-to-SQL agents repeatedly explore the same schemas, leading to long trajectories and only 25% execution accuracy with 22.62 steps when reading raw trajectories.

On enterprise-style benchmarks like Spider 2.0, this instability and redundancy cause high latency, token bloat, and frequent failures to generate valid SQL for complex databases.

HOW IT WORKS

AgentSM — Structured Semantic Memory with Composite Tools

AgentSM centers on a planner agent, schema linking agent, trajectory store, and composite tools connected through structured trajectory synthesis and retrieval.

You can think of AgentSM like a developer using a well-organized notebook and macros instead of retyping the same exploratory commands for every new query.

This design lets AgentSM reuse prior reasoning paths and bundled tool sequences, enabling targeted exploration and SQL generation that a plain context window or scratchpad cannot sustain across tasks.

DIAGRAM

AgentSM Inference Flow for a New Question

This diagram shows how AgentSM routes a new Text-to-SQL question through trajectory retrieval, schema linking, and composite tools during inference.

DIAGRAM

AgentSM Evaluation and Ablation Pipeline

This diagram shows how AgentSM is evaluated on Spider 2.0 Lite and how ablations disable trajectory reading or composite tools.

PROCESS

How AgentSM Handles a Text-to-SQL Workflow

  1. 01

    Trajectory Synthesis

    AgentSM generates synthetic questions per schema and runs agents with SQL and file tools to populate the trajectory store with exploration rich traces.

  2. 02

    Step Classification

    AgentSM classifies each trajectory step into exploration, query execution, or validation phases, then restructures them into readable markdown segments.

  3. 03

    Trajectory Retrieval

    At inference, AgentSM filters trajectories by database, selects the most similar question using embeddings, and loads only the relevant trajectory phase.

  4. 04

    Composite Tool Construction

    AgentSM mines frequent tool subsequences like get_ext then get_ddl and bundles them into composite tools that the planner agent can call in one step.

KEY CONTRIBUTIONS

Key Contributions

  • 01

    AgentSM agentic framework

    AgentSM introduces a two agent architecture with a planner agent and schema linking agent plus a trajectory store tailored for enterprise Text-to-SQL workloads like Spider 2.0.

  • 02

    Structured semantic memory

    AgentSM designs a structured semantic memory that encodes prior trajectories with step classification and markdown headers, enabling retrieval that cuts steps by 25% and boosts accuracy by 35%.

  • 03

    Composite tools for efficiency

    AgentSM automatically constructs composite tools from frequent tool sequences, reducing average steps from 20.36 to 15.99 and latency from 523.7s to 252.4s in ablations.

RESULTS

By the Numbers

EX (%)

44.8%

+16.1 over SpiderAgent (claude-3-7-sonnet)

Avg. Steps

16.4

-2.5 vs SpiderAgent (claude-3-7-sonnet)

Avg Latency (s)

247.1

-116.1 seconds vs SpiderAgent (claude-3-7-sonnet)

EX (%) gold tables

57.6%

+12.8 points over AgentSM without gold tables

On Spider 2.0 Lite, which stresses multi dialect, long context Text-to-SQL, AgentSM with Claude 4 Sonnet reaches 44.8% execution accuracy. This demonstrates that structured semantic memory and composite tools let AgentSM trade redundant exploration for more effective reasoning under strict step and latency budgets.

BENCHMARK

By the Numbers

On Spider 2.0 Lite, which stresses multi dialect, long context Text-to-SQL, AgentSM with Claude 4 Sonnet reaches 44.8% execution accuracy. This demonstrates that structured semantic memory and composite tools let AgentSM trade redundant exploration for more effective reasoning under strict step and latency budgets.

BENCHMARK

Execution Accuracy on Spider 2.0 Lite

Overall execution accuracy (%) on Spider 2.0 Lite across agentic Text-to-SQL systems.

BENCHMARK

Ablation: Accuracy vs Memory Components

Execution accuracy (%) over 75 sampled Spider 2.0 Lite questions under different AgentSM configurations.

KEY INSIGHT

The Counterintuitive Finding

Reading raw, unstructured trajectories in AgentSM yields no gain over not using any trajectory at all, both stuck at 25% accuracy.

This is surprising because more past information usually helps, but AgentSM shows that unstructured logs just add noise without structure and annotations.

WHY IT MATTERS

What this unlocks for the field

AgentSM unlocks reusable, interpretable semantic memory for Text-to-SQL agents, turning one off explorations into durable programs for future queries.

Builders can now design agentic systems that get faster and more accurate with use, instead of re paying the same exploration cost on every enterprise database question.

~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: AgentSM: Semantic Memory for Agentic Text-to-SQL

Answers use this explainer on Memory Papers.

Checking…