AI4SIDS-Gov · AI Systems / LLM / RAG Integration · Month 1

Deliverable K1 — LLM/RAG/Agentic Architecture & Interface Specification

The LLM layer of the AI4SIDS-Gov platform architecture: how it works, how it connects to the platform and data services, what it depends on, and how K2–K7 will build it.

LLM Specialist
Submitted for acceptance · 29 November 2026

Summary. K1 specifies a single LLM layer for AI4SIDS-Gov, sitting inside the platform architecture already presented by the Engineer [R1]. It is assembled from components that already work in the project — the weather.ai.tt assistant, the staging-gov login and role model, and the DMU Reports checked-figures pipeline — so that it answers from approved documents and live data, shows where every number came from, and issues nothing without a person signing off.

4 / 4acceptance items delivered
8architecture decisions for approval
8interfaces specified
9dependencies registered (§4A)

1Acceptance evidence

TOR, Appendix I, §4: “Approved LLM/RAG/agentic architecture, interfaces, dependencies and implementation plan.”

Required outputWhere in this documentStatus
LLM/RAG/agentic architecture§3 Architecture, §4 Components reused, §5 Decisions D1–D8Delivered — decisions for approval
Interfaces§6 Interfaces I1–I8Delivered
Dependencies§7 Dependency registerDelivered
Implementation plan§8 Plan K2–K7, §9 RisksDelivered
Approval§11 Sign-off; open items in §10Awaiting Technical Supervisor

2Context

Position in the platform architecture

The Engineer has presented the overall AI4SIDS-Gov platform architecture [R1]. K1 is its LLM chapter: it does not choose the platform base, hosting or login system — those belong to the platform architecture — and it plugs into whichever base that architecture selects.

Responsibilities follow one layer each, so the backend is built once:

Platform (Engineer)logins, roles, audit trail, web app, releases
Data (Research Assistant)ingestion, data services, backups
LLM (LLM Specialist)assistant, RAG, tools, guardrails, evaluation

What the Ministry asked for

From the DMCU AI use case & data requirements assessment [R4]:

  • Most time-critical output: Situation Reports; each takes about 2 hours, and every section is repetitive.
  • Three-year goal: AI-assisted SitReps from the 14 regional corporations.
  • Sources: Survey123, ArcGIS, Google Forms, Excel — export and API available; hourly synchronisation preferred.
  • Data owner: the Ministry; access approved by ODPM and CEDMA; no data-sharing agreements yet.
  • Data includes personal, sensitive and confidential information.
  • Success: shorter reporting time, better decisions, coordination, adoption.

3Architecture

Click any box for the decision or interface behind it.

Design rules

4Components reused

Existing project code bases were reviewed [R7]. K1 reuses the strongest part of each and retires the rest.

weather.ai.tt LLM core — reuse

The Government assistant: one agent, seven read-only tools over live river and weather data plus a document library, and charts built straight from the data.

Kept, and gaps

Kept:

  • pydantic-ai agent with typed tools; Azure gpt-4.1; Qdrant with text-embedding-3-large.
  • Every tool result carries its source, observation time and age.
  • Charts and observation times are taken from the raw data, never from the model's wording.
  • Projections refuse rather than guess on stale, flat-lined or sparse data.
  • Personal-data routing that refuses rather than sends to the cloud; document ingestion with de-duplication; existing test suite.

Gaps: logins and roles, a record of each request, streaming, document approval, document metadata, keyword search, and an evaluation that scores correctness on the production model. Topic and personal-data checks exist but are off by default.

staging-gov logins & roles — reuse

A small, tested login and permissions layer: organisations, three roles, invite-only accounts, forced password change.

Kept, and gaps
  • Role and organisation are read from the database on every request, so a revoked user loses access at once.
  • A single require_role check per route — an approver role for sign-off (I7) is one addition.
  • Tests proving each role's allow/deny behaviour.
  • Gaps: no audit trail or migration history; the LLM path does not use the logins yet.

DMU Reports checked figures — port

Situation reports where every number is computed in code, cited and machine-checked before a person issues it.

Taken
  • Citation checker: every number in the text must match a cited fact; one retry, then “needs review”.
  • Quality targets adopted as K2/K5 pass marks: 100% on critical numbers, ≥95% citation accuracy, 0% critical hallucination.
  • Data-module interface (also available over MCP): candidate shared route for both systems to reach each other's data.
  • Ministerial reports and provisional hour briefings already exist; roles member · dmu · admin.

v1a prototype retire

Research prototype: a router sends questions to five specialist prompts, whose functions already exist as weather.ai.tt tools.

Carried forward
  • The off-topic refusal pattern.
  • 12 documents as a seed library for K2 — two operational (flood shelters list, emergency protocol by city), the rest research papers.
  • Not carried forward: the separate service, its shared conversation state, and the social-media agent, which uses simulated posts.
K1 itemReuseAdaptBuild new
Agent, tools, framework (D1, D3)weather.ai.tt agent + 7 toolsper-role tool lists—
Figures and citations (D5)source/time on every figure; data-built charts—citation checker (port from DMU Reports)
Models (D2, I8)Azure + local switchregistrymigration plan
Documents (D4, I6)Qdrant ingestionseed library of 12metadata, approval, keyword search, retrieval tests
Misuse controls (D6)topic + personal-data checksswitch on, every channelrate limits, cost alerts
Who is asking (I2)staging-gov rolesmerge with DMU Reports rolespass into the LLM layer
Request record (I5), sign-off (I7)——both

5Architecture decisions for approval

Each card states the proposed decision; options and evidence are behind the toggle.

D1 · Where the LLM layer lives

Proposed: the weather.ai.tt LLM core as one module, using the staging-gov login pattern, inside the platform base selected in the platform architecture [R1].
Options & evidence
Candidate baseBringsLacks
weather.ai.ttLLM core, live river/weather data, documents, deploymentLogins, request record
staging-govLogins, organisations, roles, testsLive data, usable LLM code
DMU ReportsReal users, checked reports, loginsLive river/weather data, document search

If DMU Reports remains a separate app, both reach the same LLM layer and each other's data through one defined interface; the DMU Reports data-module interface is the leading candidate.

D2 · Models

Proposed: remain on Azure gpt-4.1 for now; choose the migration target on evidence; keep the local model on hold; never switch providers silently.
Options & evidence
ModelStatusNote
Azure gpt-4.1In productionRoadmap item: move off it; data residency to confirm
AWS Bedrock nova-proOnly Bedrock model tested that completes the full tool loopCheaper options (nova-lite, llama4-maverick) failed
Local model (llamafile)On holdReported 8–10 minute replies and malformed output; needs GPU
Ollama / NVIDIA NIMUsed by DMU ReportsIncluded in the same registry

Changing the embedding model requires re-indexing every document, so it is planned with the chat-model move. If no approved model is available, the app falls back to data-only mode (readings and alerts without AI wording).

D3 · Agent framework

Proposed: pydantic-ai, as already used by weather.ai.tt; retire the v1a LangChain router.
Options & evidence
  • pydantic-ai: typed tools and structured outputs; already wired to Azure and the local model; tested.
  • LangChain (v1a): a second way of doing the same thing; its router shares one conversation state across all users.
  • Raw SDK: fewest dependencies, but tool calling and validation would be rebuilt.

Prompts move out of the code into versioned files, so wording changes are reviewed and re-tested.

D4 · Document search (RAG)

Proposed: keep Qdrant; build a retrieval test set first; then add document metadata, an approval step and keyword + meaning search; add a re-ranker only if the tests require it.
Options & evidence
  • Today: meaning-only search; each chunk records file, display name, chunk number and page. Retrieval has not been tested against a real document library.
  • Add: owner, version, effective date, supersedes, approval status; search is filtered to approved, current versions.
  • Hybrid search catches station names and acronyms that meaning-only search misses.
  • Corpus: 12 seed documents; the approved Government sources (SOPs, policies, sample reports [R4 §13]) are a dependency.

D5 · Figures and citations

Proposed: keep the rule that figures come from data, and add the DMU Reports citation checker so no number in the written answer goes unchecked.
Detail
  • Built: source and observation time on every tool result; charts from data; projections refuse on poor data.
  • Added: every number in the text must match a cited fact; one retry, then “needs review”.
  • Each figure carries a status — raw, provisional, validated or authoritative. SitRep figures use validated records; emergency reports from unvalidated data are tagged Provisional.
  • Past a staleness threshold the answer says the data is out of date instead of quoting it.

D6 · Misuse controls

Proposed: switch on and complete the existing checks, apply them to every channel, and add rate and cost limits.
Detail
  • Topic scope: exists; off by default; currently lets requests through if the check itself fails — fail-open vs fail-closed is an item for confirmation (§10).
  • Personal data: detected before the model and refused rather than sent to the cloud; with the local model on hold, “on” means “refused”.
  • Uploaded documents: held for approval before indexing; tested with instruction-bearing attack documents every release.
  • Every channel — including the public chatbot — passes the same checks.
  • Tools: read-only; per-role lists once logins exist. Cost: rate limits, per-user limits, budget alert.

D7 · K4 decision-support workflow

Proposed: add live river and weather data and the relevant procedures to the DMU Reports ministerial situation report — checked by the citation checker and signed off by DMU.
Options & evidence

Directly serves the Ministry's stated goal of AI-assisted SitReps from the 14 corporations, and its most time-critical, ~2-hour task [R4].

OptionForAgainst
Hydro-met + procedures in the ministerial SitRep (proposed)Combines documents and live data as the TOR requires; builds on a workflow with real users; new capability; a path to ODPM.Needs DMU Reports access and interface agreement.
New national briefingClear value.DMU Reports already produces ministerial reports and hour briefings.
Corporation SitRep draftingClear need.Already exists in DMU Reports.
River exceedance noteSimple.Little document use; weaker TOR fit.

D8 · RAG, not model training

Proposed: “building an SLM from documents” is delivered as search-and-cite over approved documents (RAG), not as training a model.
Rationale

RAG gives current, auditable answers with sources. Training a model is outside the TOR's role boundaries and would need a Clause 8 amendment.

6Interfaces

Agreements between the LLM layer, the platform and the data services. Shapes are draft contracts; endpoint names are illustrative.

I1 · Assistant chat — web app ↔ LLM layer · Platform builds the screen · Month 2

Extends today's response (reply, sources, charts, observations, provider used) with structured figures, a trace id, streaming and a request time limit.

POST /api/v1/assistant/chat
{ "conversation_id": "uuid", "message": "Is the Caroni rising?", "channel": "web" }

200 (streamed: token · fact · citation · done)
{ "answer": "markdown",
  "facts": [ { "label": "Caroni at Piarco", "value": 3.42, "unit": "m",
               "observed_at": "…-04:00", "source": "wra:station/…",
               "status": "provisional" } ],
  "citations": [ { "source_id": "doc-017", "title": "…", "version": "…",
                   "page": 12, "chunk_id": "…" } ],
  "tools_used": ["get_wra_station_history"], "provider": "azure:gpt-4.1",
  "refused": false, "trace_id": "…" }
I2 · Who is asking — Platform → LLM layer · Month 3

Every request carries the user's identity and role, read from the database on each request (staging-gov pattern); DMU Reports roles fold into the same list.

{ "user_id": "…", "org_id": "…",
  "role": "admin | dmu | org_admin | member | approver", "session_id": "…" }
I3 · Data services — Data → LLM layer · mid-Month 2

Read-only endpoints for the LLM tools. Every response states when the data was observed, where it came from and its status.

GET /api/v1/data/river/stations
GET /api/v1/data/river/readings?station=…&from=…&to=…
GET /api/v1/data/weather/alerts/latest
GET /api/v1/data/weather/forecast
GET /api/v1/data/sitreps/{id}/facts?status=validated

every response: { "data": …, "as_of": "…", "source": "…", "status": "…" }
I4 · Tool contract — inside the LLM layer · Month 3

Typed inputs, a time limit, one retry, a cache matched to the data's refresh rate (river 30 min, weather 2 h), and a structured error the model can explain instead of guessing.

ok:    { "data": …, "as_of": "…", "source": "…", "status": "…" }
error: { "code": "timeout | unavailable | stale | forbidden",
         "retry_after_s": 30, "message": "No river data since 14:30" }
I5 · Request record — LLM layer → platform audit trail · Month 3

New. One record per request: who asked, which model answered, what the checks decided, which tools ran, what was cited, how long it took. Serves auditing (K4) and monitoring (K5).

{ "trace_id", "user_id", "role", "channel", "provider",
  "topic_check": "pass|block", "personal_data": "none|found→local|found→refused",
  "tools": [ { "name", "ms", "status" } ], "citations": [ "chunk_id" ],
  "tokens_in", "tokens_out", "latency_ms", "cost_estimate", "prompt_version" }
I6 · Document intake — Data pipeline + LLM metadata · Month 2

Documents arrive through the existing S3 → SQS → Dagu path; nothing is searchable until it carries these fields and is approved.

required: source_id, title, owner, version, effective_date,
          supersedes (optional), approval_status, data_class
I7 · Sign-off workflow — LLM layer ↔ platform screen · Month 4

New. Fixed states; only an approver can approve or issue; every step goes to the request record with the draft-to-final changes. Mirrors DMU Reports' “needs review”.

draft → in_review | needs_review → approved | rejected → issued
approve/issue: role = approver · issued = read-only
I8 · Model registry — LLM layer · specified here, built Month 2

Replaces today's fixed two-option setting with one list of every model the system may use and what data it may receive.

{ "id": "azure:gpt-4.1", "max_context": …, "tool_calling": true,
  "data_classes": ["public", "internal"] }
{ "id": "local:<model>", "tool_calling": true,
  "data_classes": ["public", "internal", "personal"], "enabled": false }

7Dependency register

Registered under TOR §4A; any slippage is notified in writing to the Technical AI Lead and Project Manager.

NeededFromByUnblocks
Model hosting approved for Government data; data residencyPI / MinistryMonth 2K2
Approved knowledge sources (SOPs, policies, sample reports)Supervisor / DMCUMonth 2K2
Data-sharing agreement for Ministry dataPI / Ministry (ODPM & CEDMA approve access)Month 3K3, K4
Data services contract v1 (I3)Research Assistantmid-Month 2K3
Test environment + automated checksEngineerMonth 2K2 demo
Logins, roles and audit trail (I2, I5)Engineermid-Month 3K4
DMU Reports code access and data-module interfaceDMU Reports developerMonth 2D5, K4
Model migration target and embedding planTechnical AI Lead / PIMonth 2D2, K2
Local model: revive or dropTechnical teamMonth 2personal-data routing

8Implementation plan

DeliverableTimingOutput
K1Month 1This specification — submitted
K2Month 2Retrieval test set; document metadata and approval; RAG answers with citations; evaluation report against the adopted pass marks
K3Month 3LLM tools over the data services (I3, I4) with validation, failure handling and freshness rules
K4Month 4Ministerial SitRep enriched with live data and procedures; citation check; sign-off (I7); request record (I5)
K5Months 5–6Quality, guardrail, failure/security and observability evidence across releases
K6Month 7Integrated code, documentation and runbooks; handover to the Research Assistant, who continues to Month 18
K7Month 8Capacity-building workshop, run jointly with the platform workshop

9Risks

Wrong or out-of-date numbers in an answer — high

Figures from data (D5), citation checker on every answer, refusal past a staleness threshold, figure checks on every release.

Document answers untested on real documents — high

Retrieval test set first (D4); no quality claims until it passes on the approved library.

A planted document steers the assistant — high

Approval before indexing (D6), read-only tools, attack documents in every test run.

Personal data reaches a cloud model — high

Detection before the model; refusal while the local model is on hold; tested in both configurations.

No data-sharing agreement in place — medium

Development uses fictional or exported test data until the agreement exists; registered as a dependency (§7).

Model provider or credits change — medium

Model registry (I8) keeps providers swappable; data-only fallback.

Cost spike during a major event — medium

Rate and per-user limits, budget alert, bounded data per request.

Duplicate backends — medium

One layer per role as set out in the platform architecture [R1]; one application, one database, one migration history.

10Items for confirmation

  1. Which model hosting is approved for Government data, and where must the data stay?
  2. Who supplies and approves the knowledge sources?
  3. Is DMU Reports part of AI4SIDS-Gov with a shared login, or a connected app?
  4. K4 workflow: live data and procedures in the ministerial SitRep (proposed), or another?
  5. Confirm that “building an SLM from documents” means RAG.
  6. Migration off Azure gpt-4.1: target and timing.
  7. Topic check: may it let requests through when it fails, or must it block?
  8. Access to the DMU Reports code; formal retirement of the v1a prototype.

11Acceptance

Submitted as Deliverable K1 under the Terms of Reference, Appendix I, for technical acceptance and certification for payment.

Technical supervision & acceptance
Technical Supervisor · date
Certification for payment
Principal Investigator · date

References

  • R1 AI4SIDS-Gov platform architecture, presented by the Engineer (P1)
  • R2 Terms of Reference, AI Systems / LLM / RAG Integration Specialist, deliverables K1–K7
  • R3 AI4SIDS Technical Team — Proposed Meeting and Platform Development Priorities, 6 November 2026
  • R4 AI4SIDS-Gov Government AI Use Case & Data Requirements Assessment — DMCU, Ministry of Rural Development & Local Government
  • R5 DMCU Platform — Technical Summary of Work to Date, 30 September 2026
  • R6 Technical onboarding and handover session notes
  • R7 Code review of the AI4SIDS-Gov repository (main and branches) and AI4SIDS repository (staging-gov), November 2026