← Back to Blog

How to Run an AI SQL Database Agent with OE Runtime

Query your PostgreSQL database in plain English. OE Runtime connects directly to your database, explores the schema, runs safe SELECT queries, and explains the results in plain language — no SQL knowledge required.

🗃
Step 1
Explore Schema
List all tables, fetch column names and data types, and count rows in each table.
Step 2
Analyze Key Data
Fetch recent rows, group by status/category columns, and identify NULL value counts.
Step 3
Report
Produce a plain-English database summary with schema, sample data, quality observations, and suggested queries.

The Agent YAML

Create a file called agent.yaml inside a sql-databases/ directory:

name: Database Analyst
description: Query a SQL database and summarize results in plain English
instructions: |
  You are a database analyst with read access to a SQL database.
  Run SELECT queries to explore the schema and answer data questions.
  Always explain results clearly in plain English.
  Do not run INSERT, UPDATE, DELETE, or DROP statements.
  Complete all steps fully before writing your report.
steps:
  - name: Explore Schema
    content: |
      Run the following queries one at a time:
      1. List all tables in the database
      2. For each table, fetch the column names and data types
      3. Count the rows in each table
  - name: Analyze Key Data
    content: |
      From the largest table found:
      - Fetch the 5 most recently created rows (use created_at or id DESC if available)
      - Calculate row counts grouped by any status or category column if one exists
      - Identify any columns with NULL values and count how many rows are affected
  - name: Report
    content: |
      Produce a database summary in plain English:
      - Tables found and their row counts
      - Schema of the largest table (column names and types)
      - Sample of 5 recent records
      - Data quality observations (nulls, unexpected values)
      - Suggested queries for further analysis
connectors:
  - connection_name: My Database
    connection_type: postgresql

The Config File

Create oe-config.json in the same directory:

{
  "llm": {
    "provider": "openai",
    "model": "gpt-4o",
    "apiKey": "YOUR_OPENAI_API_KEY"
  },
  "server": {
    "enabled": false,
    "port": 3333,
    "apiKey": "your-secret-api-key"
  },
  "connectors": [
    {
      "connection_name": "My Database",
      "connection_type": "postgresql",
      "host": "localhost",
      "port": 5432,
      "database": "mydb",
      "user": "postgres",
      "password": "YOUR_DB_PASSWORD"
    }
  ]
}

Replace host, database, user, and password with your PostgreSQL connection details. For cloud databases like Supabase, Neon, or RDS, use the provided connection string values. Always use a read-only database user when running analytical queries.

Download OE Runtime

OE Runtime — Direct Downloads

Run the Agent

Windows

# Run the agent
oe-runtime-win.exe sql-databases/agent.yaml --config sql-databases/oe-config.json

macOS

# Make executable (first time only)
chmod +x oe-runtime-macos

# Run the agent
oe-runtime-macos sql-databases/agent.yaml --config sql-databases/oe-config.json

Linux

# Make executable (first time only)
chmod +x oe-runtime-linux

# Run the agent
oe-runtime-linux sql-databases/agent.yaml --config sql-databases/oe-config.json

macOS Gatekeeper: On first run, macOS may block the binary. Go to System Settings → Privacy & Security → click "Allow Anyway" next to oe-runtime-macos.

Running as an API Server

Add --serve to start OE Runtime as an HTTP server on port 3333:

oe-runtime-win.exe --serve --config sql-databases/oe-config.json

Then send a request:

curl -X POST http://localhost:3333/run \
  -H "Content-Type: application/json" \
  -d '{"yaml": "sql-databases/agent.yaml", "params": {}}'

Or import the Postman collection (download above) to test all endpoints visually.

Use Cases

Build your own agents with OE Runtime

Download OE Runtime and run any AI agent locally or as a server — no cloud required.

Get OE Runtime →