AgentSM: Semantic Memory for Agentic Text-to-SQL

Asim Biswal, Chuan Lei, Xiao Qin, Aodong Li, Balakrishnan Narayanaswamy, Tim Kraska · DOI

Abstract

Recent advances in LLM-based Text-to-SQL have achieved remarkable gains on public benchmarks such as BIRD and Spider. Yet, these systems struggle to scale in realistic enterprise settings with large, complex schemas, diverse SQL dialects, and expensive multi-step reasoning. Emerging agentic approaches show potential for adaptive reasoning but often suffer from inefficiency and instability—repeating interactions with databases, producing inconsistent outputs, and occasionally failing to generate valid answers. To address these challenges, we introduce Agent Semantic Memory (AgentSM), an agentic framework for Text-to-SQL that builds and leverages interpretable semantic memory. Instead of relying on raw scratchpads or vector retrieval, AgentSM captures prior execution traces—or synthesizes curated ones—as structured programs that directly guide future reasoning. This design enables systematic reuse of reasoning paths, which allows agents to scale to larger schemas, more complex questions, and longer trajectories efficiently and reliably. Compared to state-of-the-art systems, AgentSM achieves higher efficiency by reducing average token usage and trajectory length by 25% and 35%, respectively, on the Spider 2.0 benchmark. It also improves execution accuracy, reaching a state-of-the-art accuracy of 44.8% on the Spider 2.0 Lite benchmark.

Introduction: The Challenge of Enterprise Text-to-SQL

While Large Language Models (LLMs) excel at simple SQL generation, they often falter when faced with "enterprise-grade" environments. Real-world databases feature massive, nested schemas, thousands of columns, and specific dialects like BigQuery or Snowflake that require multi-step reasoning to navigate.

Current agentic approaches—where an LLM acts as an iterative problem solver—can adapt to these complexities but are notoriously inefficient. These systems frequently suffer from redundancy, re-exploring the same schema for every new question; instability, where early exploration errors derail the entire reasoning path; and high latency due to long, expensive interaction trajectories.

The AgentSM Framework

AgentSM (Agent Semantic Memory) addresses these inefficiencies by providing agents with a "long-term memory" of database interactions. Rather than treating past runs as mere logs, AgentSM stores and retrieves structured reasoning trajectories to guide future queries.

The dual-agent architecture of AgentSM, featuring a Planner Agent for high-level strategy and a Schema Linking Agent for fine-grained exploration.

Core Components

  • Dual-Agent Architecture: The system splits responsibilities between a Planner Agent, which handles high-level strategy and SQL generation, and a Schema Linking Agent, specialized in fine-grained data exploration.
  • Trajectory Synthesis & Retrieval: To "prime" the memory, the system uses an LLM to generate synthetic questions for a database. An agent solves these offline, and the resulting trajectories—the specific steps taken to find the answer—are stored in a Trajectory Store.
  • Structured Representation: Trajectories are stored in an interpretable Markdown format with semantic headers. This allows the LLM to "read" past experiences without getting lost in verbose debugging noise.
  • Composite Tools: To minimize hallucinations and reduce turns, AgentSM bundles common tool sequences (e.g., reading a schema followed by external documentation) into single "composite tools."
The Trajectory Synthesis pipeline, showing how synthetic questions and database schemas are used to generate raw trajectories for the semantic memory store.

Experimental Evaluation

The framework was primarily evaluated on Spider 2.0, a benchmark designed to emulate real-world enterprise environments with long contexts, massive schemas, and multiple SQL dialects.

Key Results

  • State-of-the-Art Accuracy: AgentSM reached 44.8% accuracy on the Spider 2.0 Lite leaderboard, outperforming the previous baseline (SpiderAgent) by 14.1%.
  • Efficiency Gains: The system reduced average trajectory length by 25% and total token usage by 35%.
  • Reduced Latency: AgentSM was significantly faster than baselines, averaging 247 seconds per query compared to 363 seconds for SpiderAgent, primarily due to taking fewer "turns" to reach an answer.

Insights and Future Directions

A critical insight from this research is that exploration is 80% of the battle. In standard agents, the vast majority of steps are spent simply trying to understand the database. By "remembering" these steps, AgentSM allows the agent to skip the orientation phase and jump straight to solving the query. Furthermore, the authors found that structure beats raw data; providing agents with structured Markdown trajectories led to a massive jump in accuracy compared to raw logs.

Despite these gains, challenges remain. Performance is lower on highly specialized databases (like GitHub repositories) and complex business logic in Snowflake. Future work will explore finer-grained retrieval at the schema element level and unified memory sharing across multiple agents.

Summary updated

Abstract

Recent advances in LLM-based Text-to-SQL have achieved remarkable gains on public benchmarks such as BIRD and Spider. Yet, these systems struggle to scale in realistic enterprise settings with large, complex schemas, diverse SQL dialects, and expensive multi-step reasoning. Emerging agentic approaches show potential for adaptive reasoning but often suffer from inefficiency and instability-repeating interactions with databases, producing inconsistent outputs, and occasionally failing to generate valid answers. To address these challenges, we introduce Agent Semantic Memory (AgentSM), an agentic framework for Text-to-SQL that builds and leverages interpretable semantic memory. Instead of relying on raw scratchpads or vector retrieval, AgentSM captures prior execution traces-or synthesizes curated ones-as structured programs that directly guide future reasoning. This design enables systematic reuse of reasoning paths, which allows agents to scale to larger schemas, more complex questions, and longer trajectories efficiently and reliably. Compared to state-of-the-art systems, AgentSM achieves higher efficiency by reducing average token usage and trajectory length by 25% and 35%, respectively, on the Spider 2.0 benchmark. It also improves execution accuracy, reaching a state-of-the-art accuracy of 44.8% on the Spider 2.0 Lite benchmark.
BibTeX
@misc{biswal2026agentsm,
  author = {Asim Biswal and Chuan Lei and Xiao Qin and Aodong Li and Balakrishnan Narayanaswamy and Tim Kraska},
  title = {{AgentSM: Semantic Memory for Agentic Text-to-SQL}},
  year = {2026},
  eprint = {2601.15709},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2601.15709},
}
Figure