served

Articles ·

Give your agent its own SQLite database

An agent that can make an HTTP request can have durable, queryable storage in three calls. A practical guide, with the instructions and tool definition to paste in.

Agents are good at working things out and bad at remembering them. Notes in a text file work until there are a thousand of them. A SQLite database is the smallest step up that changes what the agent can do: it can filter, join, count and update, and what it stored on Monday is there on Friday.

Served gives an agent that database over plain HTTP. There is nothing to install and no client library. If the agent can run curl or call fetch, it can use it.

The short version

Create an API key on the dashboard, put it in the agent's environment as SERVED_KEY, and add this to its instructions:

You have durable storage in Served, a hosted SQLite service.
Read https://served.dev/llms.txt before first use.
The API key is in the SERVED_KEY environment variable.
Create a database per project, named after the project.
Look at the schema before writing: SELECT name, sql FROM sqlite_schema

That is enough for a coding agent with a shell. /llms.txt is one page of plain text describing every endpoint, with examples, written to be read by a model.

What the agent does

Three requests cover almost everything.

# once
curl https://api.served.dev/v1/databases \
  -H "Authorization: Bearer $SERVED_KEY" -d '{"name": "research"}'

# any SQL, sent as the request body
curl https://api.served.dev/v1/databases/research/query \
  -H "Authorization: Bearer $SERVED_KEY" \
  -d "CREATE TABLE IF NOT EXISTS findings (
        id INTEGER PRIMARY KEY, topic TEXT, note TEXT, source TEXT,
        found_at TEXT DEFAULT CURRENT_TIMESTAMP)"

# values as parameters, never pasted into the SQL
curl https://api.served.dev/v1/databases/research/query \
  -H "Authorization: Bearer $SERVED_KEY" \
  -d '{"sql": "INSERT INTO findings (topic, note, source) VALUES (?, ?, ?)",
       "args": ["pricing", "Plan B is cheaper above 20 seats", "https://example.com/pricing"]}'

A few details were chosen with agents in mind:

As a tool

If your agent uses function calling in place of a shell, one tool is enough. This is the definition in the JSON Schema form most model APIs accept:

{
  "name": "sql",
  "description": "Run SQL on a hosted SQLite database. Creates the database if it does not exist. Use ? placeholders and pass values in args. Returns columns and rows, or an error message to act on.",
  "input_schema": {
    "type": "object",
    "properties": {
      "database": {"type": "string", "description": "Lowercase name, e.g. research"},
      "sql":      {"type": "string"},
      "args":     {"type": "array", "description": "Values for the ? placeholders"}
    },
    "required": ["database", "sql"]
  }
}

Your side of the tool is two requests: POST /v1/databases with the name, which is harmless if it exists, then POST /v1/databases/{name}/query with the SQL and args. Hand the response body back to the model as it is, errors included.

If your framework builds tools from an OpenAPI description, there is one at /openapi.json.

Habits worth teaching it

And for you

The part that matters to the person supervising: at any moment you can download the agent's database as an ordinary file and open it yourself.

curl -o research.db https://api.served.dev/v1/databases/research/download \
  -H "Authorization: Bearer $SERVED_KEY"
sqlite3 research.db "SELECT topic, count(*) FROM findings GROUP BY topic"

You can see exactly what it has been writing down, with the tools you already have.

Served is hosted SQLite. Real SQLite behind an HTTP API, $3 a month, and the file is yours to download whenever you like.

Read the docs