Skip to content

A-02 Database Agent

Open source, Apache-2.0

81.5% right answers on 184 held-out questions, up from 48.4%

agentMCP toolsSQLmulti-turnread-only

Questions about a music store, answered only through three read tools on a live SQLite server. A fifth of the albums, artists and customers in the test never appeared in training.

The base model wandered, calling more and more tools until it ran out of turns. Thirty steps of reinforcement learning took it from 48.4% to 81.5%, and taught it to commit to an answer.

The weights are a LoRA adapter on top of Qwen/Qwen3.5-2B. Load both with transformers and peft.

  1. Install

    Terminal window
    pip install -U transformers peft accelerate
  2. Load and ask

    run.py
    from transformers import AutoModelForCausalLM, AutoTokenizer
    from peft import PeftModel
    base = "Qwen/Qwen3.5-2B"
    tok = AutoTokenizer.from_pretrained(base)
    model = AutoModelForCausalLM.from_pretrained(base, torch_dtype="auto", device_map="auto")
    model = PeftModel.from_pretrained(model, "superbird-labs/a-02-database-agent")
    SYSTEM = open("system_prompt.txt").read() # the prompt below
    messages = [{"role": "system", "content": SYSTEM},
    {"role": "user", "content": "your input here"}]
    ids = tok.apply_chat_template(messages, add_generation_prompt=True,
    enable_thinking=False, return_tensors="pt").to(model.device)
    out = model.generate(ids, max_new_tokens=512, do_sample=False)
    print(tok.decode(out[0][ids.shape[-1]:], skip_special_tokens=True))

The exact system prompt is on the model card.

shape of the answer
list_tables() → describe_table("Track") → read_query("SELECT ...")
"The album 'Big Ones' is 73 minutes long."

Real cases from the held-out set, never seen in training.

How long is the album Big Ones?
How long is the album 'Big Ones' in whole minutes, rounded down?
✕ Before training
8 database calls.
Out of turns. No answer.

Keeps searching and never answers.

✓ After training, A-02
4 database calls.
"The album 'Big Ones' is 73 minutes long."

The right answer in half the calls.

How long is the album Faceless?
How long is the album 'Faceless' in whole minutes, rounded down?
✕ Before training
"216006 / 60 = 3600.1.
Rounding down gives 3600 minutes."

The database counts in milliseconds. It divides by 60 and answers 3,600 minutes, sixty hours.

✓ After training, A-02
"The album 'Faceless' is 47 minutes long."

Reads the units right.

Classical tracks in a playlist
How many classical tracks are in the playlist 'Classical 101 - Next Steps'?
✕ Before training
"There are 25 classical tracks in the playlist."

Off by one. The answer is 24.

✓ After training, A-02
"There are 24 classical tracks in the playlist."

Counts the right rows.

Base model Qwen/Qwen3.5-2B
Method GRPO with LoRA on the Surogate engine, multi-turn with real tools
Steps 40 run, step 30 kept
Batch 16 questions × 8 tries each
Turns up to 8 tool calls
Hardware one 48 GB L40S
Time 55 minutes to step 30

mcp-server-sqlite over the Chinook music-store database (MIT). 925 questions to train on, 184 held out. 20% of the names in the held-out set never appear in training.

1 for the right final answer (numbers to the cent, names ignoring case and spacing). A list of guesses scores 0.

Trained with the open-source Surogate engine (1.5.17 or later), kit mcp. Full kit notes: Surogate mcp kit.

Terminal window
CUDA_VISIBLE_DEVICES=0 surogate grpo-colocate \
--train examples/kits/mcp/train.yaml \
--infer examples/kits/mcp/infer.yaml \
--orch examples/kits/mcp/orch.yaml

The held-out score shows in the log as Avg@1= and the adapter lands in outputs/kits/mcp/. To point it at your data, read Retrain on your data.

48.4%base
69.0%step 10
78.8%step 20
81.5%step 30
77.7%step 40

Right answers on 184 held-out questions. Tool calls per question fell from 5.8 to 4.7, and running out of turns fell from 68 questions to 14. One run, one seed.

  • Score the skill, not the format. The first reward paid only for answer tags and scored the base model at 0% while it was finding most answers. The honest baseline is 48.4%.
  • A constant learning rate of 1e-4 made it call more and more tools until it ran out of turns. Half the rate with cosine decay held.
  • Checked outside the training run: 52.7% to 89.1%, 67 answers fixed, none broken.
  • Ask your own database in plain words. Point it at an MCP server over your data (SQLite, Postgres, an internal API) and retrain on your questions.
  • Analytics that shows its work. Every answer comes from tool calls you can log and replay, not from memory.
  • A template for agent training. A clean way to see reinforcement learning teach a small model to stop exploring and commit.

Open small models for every industry, free to run offline. Custom ones for companies.

superbirdlabs.com Custom models Hugging Face hello@superbirdlabs.com