Wish
Nakthong
03 / 07

Thai RAG Agents

A multi-agent question answering system on Google's Agent Development Kit, with a trace of every call and an evaluation set that I ran twice.

Back to projects
  • 17 / 20

    answers judged correct, in both runs

  • 17 / 17

    answerable questions carrying citations after one instruction change, up from 10

  • 3 / 3

    unanswerable questions refused

01

The problem

Some questions need more than one lookup, such as which of two provinces is closer to Bangkok. A single retrieve-then-answer pass handles these badly, and when it fails I want to see which step went wrong.

02

Replay a real run

Five questions from the second evaluation run, played back step by step from the saved results: the questions the agents wrote for search, the passages they collected, the answer with its citations, and the judge's verdict. Two of the five are misses, because those are the runs that show the most.

Or ask your own question: "Ask it yourself" runs the agents live on Cloud Run, with every Gemini call going through my LLM gateway (rate limits, PII redaction, prompt-injection checks, cost log, traces), and plays the run back the same way. A live run has no reference answer, so it has no verdict.

  1. Question

    จังหวัดพระนครศรีอยุธยากับจังหวัดกาญจนบุรี จังหวัดไหนอยู่ใกล้กรุงเทพมหานครมากกว่า

    Which is closer to Bangkok, Ayutthaya or Kanchanaburi?

Step 1 of 8: Question

10 model calls, 8,192 tokens, 28.5 s on this run. Recorded on 11 October 2026 in evaluation run 2 with Gemini 2.5 Flash, played back from the saved results: nothing here calls a model. Passages are from Thai Wikipedia (CC BY-SA 4.0).

03

What I built

  • A coordinator that splits a question into one sub-question per place.
  • A researcher that searches the articles with the hybrid retriever from Thai RAG and writes findings with citations.
  • A fact checker, a separate agent that sees only the draft and the collected passages, and verifies the draft before it is returned.
  • Sub-agents used as tools instead of hand-offs, so the coordinator can call the researcher several times before it writes the draft. All agents share one list of sources in the session state, so the fact checker reads exactly the passages the researcher found.
  • A tracing plugin that records every model and tool call as a call tree, and 54 tests that use scripted models and need no API key.
Call tree of one traced run: the coordinator calls the researcher once for Nan and once for Sukhothai, each search returns 4 passages, then the fact checker returns OK. 10 model calls, 25.8 seconds.
One real run, traced. The coordinator split a comparison of two provinces' flowers into one researcher call per province, then the fact checker approved the draft.
04

How I measured it

  • 20 questions with reference answers taken from the articles: 8 single-fact, 8 comparisons that need two lookups, 3 unanswerable and 1 partly answerable.
  • Per question: were the right articles found, is the answer correct and faithful (judged by Gemini), were comparisons split across enough lookups, did the fact checker run, plus model calls and time.
  • Every run costs Gemini calls, so the command prints an estimate and refuses to start without an explicit flag.
First run against the second, after one change to the coordinator's instruction
Run 1Run 2
Answers judged correct17 / 2017 / 20
Answerable questions with a citation10 / 1717 / 17
Fact checker ran on answerable questions15 / 1717 / 17
Unanswerable questions refused3 / 33 / 3
Model calls / seconds per question7.7 / 19.68.1 / 22.0
Tokens117,029132,331
Run 1 results by question type: single 7 of 8, comparison 7 of 8, unanswerable 3 of 3, partial 0 of 1, overall 17 of 20. Expected articles found 100%, split into sub-questions 19 of 20, fact checker ran 15 of 20, answers with citations 10 of 17.
The first run broken down by question type. The table above compares it with the second run.
05

Results by question type

Run 2, the current instruction. Every expected article was retrieved for all 17 answerable questions, so the misses are not about finding the right article.

Second run, by question type
TypeQuestionsJudged correctFact checker ranModel callsSeconds
Single fact878 of 87.119.8
Comparison878 of 810.127.4
Not in the corpus33 (refused)0 of 3, nothing to check3.77.2
Half answerable101 of 113.040.3
All201717 of 208.122.0
06

Where it fails

The same three questions were missed in both runs. I read each one instead of tuning until the number went up.

The three misses, in both runs
QuestionWhat the agent answeredCause
Nakhon Ratchasima to Bangkok (reference 259 km)256 km by road, 264 km by rail, both from the passagesReference problem: the article gives 259 km in one section and about 256 km in another
Udon Thani or Nong Khai, which is fartherUdon Thani 564 km, Nong Khai not foundReal retrieval failure: the article says 615 km, but none of the 3 queries reached that passage
Nan or Yala, which is larger (Yala is not in the corpus)Nan 11,472.07 km², Yala not foundBorderline: the intended behaviour, likely failed on the judge's exact-number rule (article: 11,472.076)
07

What I found

  • Run 1 showed two process problems: only 10 of 17 answers cited a source, and the fact checker was skipped on two answerable questions. I tightened one coordinator instruction and ran again. Citations and fact-check use became complete at the cost of about 13% more tokens, and accuracy did not move, so I am not claiming the change made answers more correct.
  • Only one of the three misses is a real error of the system, and it is in retrieval: keyword search ranks the 615 km passage 2nd for a query worded "ห่างจากกรุงเทพมหานครกี่กิโลเมตร" but 27th, or not at all, for the "ระยะทาง..." wordings the researcher chose.
  • Faithfulness is left out of the headline. Run 1's 0.70 included a bug of mine, a citation parser that read only single references. Run 2 scored 15 of 17 judged answers, but the two numbers are not comparable.
08

Next steps and limits

  • Fix the Nong Khai miss in retrieval or in how the researcher words its queries, not in the coordinator.
  • One run per setup, so a one-question difference is within noise.
  • The same model family answers and judges, and Wikipedia text can contradict itself between sections.
Next / 04Tech stack