# SQLite Integration for Long-Term Agent Memory

Category: Memory & Storage
Stack: Python, SQLite, Tool Calling, Schema Tracking

## Overview
Giving autonomous agents their own dedicated SQLite database to store structured facts, user preferences, and project states across sessions.

## The Problem
Agents lack structured relational memory, leading to repeated queries and lost historical insights across multi-day tasks.

## Production Rule
Equip coding agents with SQL read and write tools pointing to a local project database. Let the agent store findings in relational tables.

## Code / Specification
File: `agent_sqlite_tool.py`

```local database
import sqlite3

def query_agent_memory(query: str, params: tuple = ()) -> list[dict]:
    conn = sqlite3.connect("project_memory.db")
    conn.row_factory = sqlite3.Row
    cursor = conn.cursor()
    cursor.execute(query, params)
    rows = cursor.fetchall()
    conn.close()
    return [dict(row) for row in rows]
```
