Skip to content

RheumAI architecture

Term Meaning
Normal chat The persistent flow of POST /api/chat.
Study route The stateless route POST /v1/study/rheumaai-reply. The BiobadamexAI study harness calls it.
Tool registry The code that finds and loads the tools in src/tools/.
Planner The PLANNING step. It selects the sources and the primary action.
Study pin A study context that forces all observable model calls to one provider and one model.
Fallback A second path that the code uses when the first path fails.
Clinician allowlist The list of clinicians with access. The monorepo API controls it.

Figure 1 shows the two flows. The two upper rows show normal chat. The dotted frame shows the study route.

System map: normal chat from the web app through the API to ethical review, and the stateless study route from the study harnessPreactWeb appsessions · uploadsExternal clientsrc/index.tsElysia APIPrivyAccessallowlist · legalConversationand request stateplannerPLANNINGToolsclinical + sourcesRetrievalDAG / RAG / graphREPLYor HYPOTHESISORVS+ PMID controlEthical reviewSupabasemessages · stateS3-compatibleStoragefilesLiteraturePubMed and othersStudy route · stateless, no writesBiobadamexAIStudy harness/v1/study/rheumaai-replyStudy routededicated bearerPLANNINGwith tool capallowlistToolsallowed onlyREPLY+ attributionresponse + turn telemetry
Figure 1. System map. Solid arrows are calls or writes. Dashed arrows are replies to the caller. The dotted frame contains the stateless study route.

The file paths in this section are relative to apps/bioagent/ in the monorepo poktalabs/pokta-care-monorepo.

The Preact client manages sessions, Privy authentication, uploads, chat requests and citations. The backend serves the client bundle. It uses a single-page-app fallback.

src/index.ts mounts the routes for chat, deep research, community, Telegram, directory, search, cryptography, configuration and study. It also mounts proxies to the monorepo API: profile (/api/me), legal acceptance, access request, audit, registry queue and care plans. It also mounts the conversation history and the WhatsApp coach. It also serves the client and the health endpoints.

POST /api/chat applies three guards before it runs the chat. requireAuth verifies the Privy session and returns 401 without a valid token. requireAllowlistedMedic calls GET /api/users/me on the monorepo API and returns 403 if the clinician is not on the clinician allowlist. requireLegalAccepted calls GET /api/legal/acceptance and returns 403 legal_acceptance_required if the clinician did not accept the current legal documents. The last two guards return 503 if they cannot reach the API. They never allow access by default. Then the route applies the IP block, the usage limits and the anti-bot protection.

Normal chat makes users, conversations, messages and request state in Supabase. Normal chat can write files to S3-compatible storage. The parsed content of each file goes into the request state. Thus /api/chat is not stateless.

The study route uses nil UUIDs. It does not send message identifiers or state identifiers. This design prevents writes. The study route accepts de-identified text. It can pin one provider and one model. It returns attribution, tool use, latency and token usage.

The tool registry finds the folders in src/tools/. It loads the index.ts module of each enabled folder. A TOOL_<NAME>_ENABLED variable can override the registration. The planner selects the sources and the primary action.

The tools are in these families:

  • Evidence: PubMed, Semantic Scholar, OpenScholar, local knowledge and the knowledge graph.
  • Clinical: clinical reasoning, lab interpretation, insurance summary and protocols.
  • Synthesis: REPLY, HYPOTHESIS, reflection and ethical review.
  • Infrastructure: files, data analysis and storage.

A folder does not prove that its tool loads. The tool registry logs each failure. Then it continues with the available tools.

The pipeline can combine embeddings, local graph retrieval and semantic search. DAG-RETRIEVAL reranks the documents for the question. If no useful evidence is available, some modes use a direct model response as a fallback.

The LLM library gives one interface for all providers. resilientChatCompletion does the fallbacks. A study pin can force all observable model calls to one provider and one model. The study pin also disables the fallback to a different model.

Aspect Normal chat Study route
Endpoint /api/chat /v1/study/rheumaai-reply
Persistence Yes No, by design
Files Yes Note text only
Session Persistent conversation One isolated request
Auth Privy session, clinician allowlist and legal acceptance A dedicated bearer token. The route is closed if the key is not set.
Tools The planner selects them Allowlist and cost ceiling
ORVS after the response Yes in the normal flow. Explicit comparison modes are available. This route has no explicit final ORVS call.
Output Conversational response Response, attribution and turn telemetry
  • Supabase keeps conversations, messages and state, and it does search.
  • S3-compatible storage keeps files, if the configuration enables it.
  • Configurable LLM providers.
  • PubMed, Semantic Scholar, OpenScholar and local corpora supply evidence.
  • Privy verifies the clinician session.
  • The monorepo API (MONOREPO_API_URL) confirms the clinician allowlist and the legal acceptance.
  • Railway deploys apps/bioagent at app.rheumai.xyz.