FHIRAgentic AI

Agent on FHIR: How to Build FHIR AI Agents That Read, Reason, and Write Clinical Data

March 17, 202615 min readUpdated Oct 30, 2026
Written by
Dinesh Thorat
Dinesh Thorat

Digital Growth Lead

Writes about healthcare technology, interoperability, and AI-driven transformation across modern care systems.

Agent on FHIR: How to Build FHIR AI Agents That Read, Reason, and Write Clinical Data

FHIR AI agents connect to clinical data through an EHR's FHIR REST API, using a SMART on FHIR token that limits what they can see and change. The model never calls the API itself: it asks a tool layer, which checks the request, makes the FHIR call, logs it, and writes anything clinical back as a draft for a clinician to sign.

Updated October 2026. Specifications were checked on 30 October 2026.

This guide is for teams building agents on FHIR data: which resources to read and write, how scopes and tool calling work, where MCP fits, and how to mark AI output. If you need a team to build the connection, see our FHIR integration services. For the wider question of connecting an agent to an EHR by any route, including HL7 v2 feeds and work without an API, read how AI agents integrate with EHR systems.

How do healthcare AI agents connect to FHIR data?

Healthcare AI agents connect in five steps, and only the tool layer ever touches the FHIR server. Each step has a different owner, which is what makes healthcare agent data integration reviewable by a security team.

StepWhat happensWho controls it
1. RegisterThe app is registered with the EHR and asks for the smallest set of scopesEHR vendor and the customer's IT team
2. AuthorizeA clinician launches the app, or a backend service signs a JWT, and a token comes backThe EHR's authorization server
3. Choose a toolThe model asks for a named tool, such as get_active_medicationsThe model, limited to the tools you expose
4. Call FHIRThe tool layer checks policy, builds the FHIR search, and logs the callYour code
5. Return or writeTrimmed data goes back to the model, or a draft goes to the EHR for reviewYour code, then the clinician

This design also lets an agent integrate with existing systems without disrupting operations, because a read-only agent changes nothing in the EHR and a draft waits in a clinician's normal review step. Start read-only, then add one write at a time.

What FHIR gives an AI agent, and what it leaves out

FHIR gives an agent a common data model, a search API and a shared authorization pattern, so the same Observation search can work across vendors. It does not give you write access: the ONC certification criterion for standardized APIs, 170.315(g)(10), covers read services and specifically excludes write.

That split shapes every plan for FHIR and AI. Reads are the dependable part of a FHIR API for AI, while writes vary by vendor, resource and customer. Profiles differ too, so test against each real target and read its capability statement at GET /metadata. Oracle Health documents this check for its Millennium APIs, and Epic publishes per-resource API pages at fhir.epic.com.

Generative AI in FHIR healthcare work mostly takes three forms: summarizing a chart from FHIR data, drafting a note or task from it, and answering questions about it. A related use, turning old HL7 v2 messages into FHIR, belongs to the integration layer and needs the same testing. For retrieval over larger records, see our guide to a FHIR-native RAG pipeline, which covers how to prepare FHIR data for AI search.

What should a FHIR AI agent read?

A FHIR AI agent should read only the resources its task needs. That keeps the prompt small and supports HIPAA's minimum necessary principle. A medication reconciliation agent needs medications and allergies, and it has no use for every old note.

Clinical dataFHIR searchSMART v2 scope
Active medicationsMedicationRequest?patient={id}&status=activepatient/MedicationRequest.rs
AllergiesAllergyIntolerance?patient={id}&clinical-status=activepatient/AllergyIntolerance.rs
Lab resultsObservation?patient={id}&category=laboratory&date=ge2026-01-01patient/Observation.rs
Active conditionsCondition?patient={id}&clinical-status=activepatient/Condition.rs
Current encounterEncounter/{encounter_id}patient/Encounter.r
Recent notesDocumentReference?patient={id}&type=http://loinc.org|11506-3patient/DocumentReference.rs

Search support differs by server, so confirm each parameter in the capability statement. Sorting with _sort is one to check before you rely on it. Rate limits differ too. We could not find one published figure that holds across EHRs, so read the limit in your target's documentation, cache what rarely changes, and back off on a 429 response.

What can an AI agent safely write through FHIR?

An agent can safely write proposals that a person reviews: a preliminary note, a draft order or a task. Nothing should become active until a clinician approves it, and your target EHR must accept that write in the first place.

OutputResourceState to writeWhy
Clinical noteDocumentReferencestatus: current, docStatus: preliminaryR4 has no draft status here, so docStatus carries it
Order suggestionServiceRequeststatus: draft, intent: proposalStays a suggestion until a clinician acts
Medication suggestionMedicationRequeststatus: draft, intent: proposalThe highest risk here, so add it last
Work for staffTaskstatus: requested, intent: proposalSends the question to a person
Record of the AI's partProvenanceCreated with the outputRecords who or what made it, from which inputs

Here is an illustrative note write. The AIAST tag comes from the HL7 guide covered below.

POST /DocumentReference
{
  "resourceType": "DocumentReference",
  "meta": {
    "security": [{
      "system": "http://terminology.hl7.org/CodeSystem/v3-ObservationValue",
      "code": "AIAST",
      "display": "Artificial Intelligence asserted"
    }]
  },
  "status": "current",
  "docStatus": "preliminary",
  "type": {"coding": [{"system": "http://loinc.org", "code": "11506-3", "display": "Progress note"}]},
  "subject": {"reference": "Patient/{patient_id}"},
  "content": [{"attachment": {"contentType": "text/plain", "data": "{base64_encoded_note}"}}]
}

Which EHRs accept this varies, so check before you design around it. Our guide to clinical notes with FHIR DocumentReference compares EHRs on this write.

Keep these rules outside the model, in code it cannot change:

  • Give each tool one FHIR operation and its narrowest scope, for example patient/Task.c.
  • Take the patient ID from the launch context. Never accept it from the model.
  • Validate each resource before you send it. FHIR defines a $validate operation for this, if the server supports it.
  • Treat note text and retrieved documents as untrusted input. Nothing in them can widen what a tool may do, which is your main prompt-injection boundary.
  • Log the user, patient, scope, tool and result of every call.

Our guide to HIPAA compliant AI agent architecture covers BAAs, PHI flows and security review.

Which SMART on FHIR scopes and flow does an agent need?

Use SMART App Launch when a clinician is present, and SMART Backend Services when the agent runs with no user. App launch keeps the agent inside that user's and patient's context, while backend services give it its own identity, so its pre-approved scope list needs extra care.

SMART v2 scopes use the letters c, r, u, d and s for create, read, update, delete and search, so patient/Observation.rs means read and search. The older .read maps to .rs, and .write to .cud. Some servers still expect the older form, so check what yours supports.

Backend Services uses the client_credentials grant with a one-time signed JWT. The spec requires the iss, sub, aud, exp and jti claims, sets exp no more than five minutes ahead, and says clients should sign with RS384 or ES384. It also says expires_in should not exceed 300 seconds, so plan on signing often.

How do healthcare AI agents handle tool calling?

Healthcare AI agents handle tool calling in a loop: the model asks for a tool, your code checks the request and calls FHIR, and the trimmed result goes back until the model can finish. The model chooses what to ask for, and your code decides whether that happens.

Keep the tool parameters small. A well-formed tool has no patient_id parameter, because the tool layer already knows the patient. This illustrative definition shows the shape:

{
  "name": "get_active_medications",
  "description": "Return the current patient's active medications with RxNorm codes when present",
  "input_schema": {"type": "object", "properties": {}, "additionalProperties": false}
}

Drug interaction checks need a named source. Older agent examples called the NLM RxNorm interaction API, but NLM announced its discontinuation for about January 2024. Pick a maintained source your clinical team accepts, and let the model report what that source returned instead of judging interactions itself. That same rule covers trusted medication information in general.

What triggers a FHIR AI agent?

A FHIR AI agent is usually triggered in one of three ways: a CDS Hooks call during a clinical action, a clinician opening a SMART app, or a background event. The trigger decides how long the agent has and how it authenticates.

TriggerFitsTime budgetWatch for
CDS Hooks (2.0.1, trial use)A card during chart review or orderingThe spec says to respond on the order of 500 msMulti-step reasoning rarely fits, so precompute. The EHR decides whether to apply systemActions
SMART appA clinician working with the agentSet by your own screenYou own the interface, and the app must be registered with each EHR
FHIR-based AI triggers, such as R4 topic SubscriptionsBackground work on chart changesSet by your workflowThe backport is trial use and server support varies
HL7 v2 feedAdmissions, discharges and results where no FHIR event existsSet by your workflowNeeds an interface engine, covered by our HL7 integration services

For HL7 FHIR AI integration, a v2 feed and a FHIR API often work together: the feed says something happened, and the agent reads the detail through FHIR. AI note-taking systems integrate with FHIR, SMART on FHIR and EMR APIs in a similar way, with a SMART launch for patient context and a DocumentReference write for the draft note. Voice agents that integrate with Epic, athenahealth or other major EHRs follow the same pattern where those systems allow it.

Where does MCP fit with FHIR?

MCP is one way to expose FHIR tools to a model, and it sits above FHIR without replacing any part of it. It is an open protocol separate from HL7, so it has no bearing on FHIR conformance.

An MCP server can publish tools such as get_active_medications, translate them into FHIR calls, and return structured results. That lets several models share one tool set, and it can connect AI agents with trusted medication information through the same interface.

Three points from the 28 July 2026 specification matter in healthcare:

  • Authorization is optional in MCP, so a health data server has to turn it on and test it.
  • MCP servers must not accept or pass along tokens issued for other services. Keep the SMART token inside the server, separate from the token the MCP client presents.
  • The spec says MCP cannot enforce its consent principles at protocol level, and that tool descriptions from untrusted servers should be treated as untrusted. Approval and audit remain your code's job.

Research is early. An open-source MCP-FHIR framework from 2025 was evaluated on synthetic SMART sandbox data and its abstract reports no quantitative results, so treat it as a design example.

How do you test a FHIR AI agent?

Test retrieval and reasoning separately, on synthetic or de-identified records, before any real patient data is involved. FHIR-AgentBench, a public benchmark of 2,931 real-world clinical questions, found that retrieving data from complex FHIR resources and reasoning over it both substantially affect performance.

Your own test set should cover the wrong patient, an empty search, paged results, an expired token, a denied scope, a rejected write, a duplicate write after a retry, and a note containing instructions aimed at the model. Score whether each answer cites the right resources as well as whether it reads well.

How do you mark AI output in FHIR?

Mark AI output with the AIAST security label in meta.security, and add a Provenance record when readers need the detail. Both come from HL7's AI Transparency on FHIR guide, which you can pilot but which has not reached a final release.

As of 30 October 2026, the published edition is the 1.0.0 STU1 ballot, trial use, and it states that no official version has been published. NIST says organizations may pilot it and expects further revisions. The guide records how AI was involved. As NIST puts it, the guide does not evaluate AI systems, judge the data, or detect undisclosed AI use.

NeedWhat to use
Flag that AI influenced a resource or elementAIAST label on the resource, or an inline label on the element
Identify the model and versionThe guide's AI Device profile, referenced from Provenance
Link to model documentationA model card in DocumentReference
Record inputs, people and rolesThe guide's AI Provenance profile, built on core Provenance

Check that your EHR keeps these labels and accepts Provenance. If it does not, hold the same record in your own audit store and link it to the resource ID. AIAST alone does not say whether a clinician reviewed the output, so record the review separately.

What is the best agent-ready integration for HL7 FHIR in healthcare?

No product is the best agent-ready integration for every buyer, because the right one depends on which EHRs you must reach and which writes they accept. Judge any vendor, AI CDS platform or tool by what it can show on your own target systems.

AskGood evidence
Does it work with our EHRs?A run against each EHR's sandbox, with the resources and scopes listed
How does it connect AI to FHIR and clinical data securely?Least-privilege scopes, token handling, a BAA, a sample audit record
Which standards does it comply with?Named versions of FHIR R4, US Core and SMART, with test results such as Inferno
What happens on write?Draft states, the approval screen, Provenance and rollback
Will it perform?Integration effort, SDK and documentation quality, latency, uptime, streaming support and accuracy benchmarks on your data
Does it pay back?Measured results from a comparable site, with the method. Treat claims of proven ROI without one as unproven

This matters for procurement because AI CDS that supports FHIR-based data exchange can move with you across EHRs, while a custom feed often has to be rebuilt. Interoperability with major EHR ecosystems still has to be evaluated system by system.

Two common requests need plain answers. A voice agent cannot be guaranteed to behave deterministically, because the model output can vary. What you can control is the structured FHIR output, by validating it against a schema and a profile before anything is saved. For building a production-ready agent that can query EHR and claims data, expect separate sources, since claims may arrive as CARIN Blue Button ExplanationOfBenefit resources or X12 files, and the same patient may be modeled differently in each. Reconcile patient identity before the agent sees either set. If your FHIR data sits in Medplum or another FHIR server, the same governance and audit trail questions apply, and a development partner should be able to answer them on that server.

How do you build your first agent on FHIR?

Build one read-only workflow first, on synthetic data, and add a single draft write only after it passes tests. This order works with any healthcare AI agent framework, since the safety rules live in your tool layer.

  1. Pick one workflow with a named clinical owner.
  2. Stand up a test FHIR R4 server, such as HAPI FHIR, or use your EHR's sandbox. Load Synthea synthetic patients.
  3. Choose the trigger and request the smallest scopes.
  4. Write one tool per FHIR operation, and use MCP if several models or clients will share them.
  5. Run the test set above, then show the results to the clinical owner.
  6. Add one draft write with an approval step, an AIAST label and Provenance.
  7. Check every assumption in the customer's own environment, since scopes and profiles there can differ from the sandbox.

What we can show you

We are ISO 27001:2022 certified and we sign BAAs. Public work you can inspect includes a SMART on FHIR app run against Epic and Oracle Health developer sandboxes and an open-source headless EHR that passed 47 of 47 ONC (g)(10) SMART App Launch Standalone Patient App tests on 27 October 2026. That result covers the SMART group only, and it is not full (g)(10) certification. We have also built more than 350 Mirth Connect interfaces, which helps when an agent needs HL7 v2 events.

Planning an agent that reads or writes FHIR data? We can review your scopes, approval flow and write paths before you build. See AI agent development for healthcare or talk to our team.

Ready to scale?

Talk to our healthcare engineering team about building, integrating, and shipping faster.

Frequently Asked Questions

How do healthcare AI agents connect to FHIR data?

Through an EHR's FHIR REST API, using a SMART on FHIR token with limited scopes. The model asks a tool layer for named tools. That layer checks policy, makes the FHIR call, logs it and returns trimmed results.

Can an AI agent write orders directly to the EHR via FHIR?

Only if the EHR accepts that write for your app, and it should not place active orders on its own. Write ServiceRequest or MedicationRequest with status: draft and intent: proposal so a clinician reviews and approves it.

Which EHRs have the best FHIR support for AI agents?

Support changes by EHR version, resource and customer, so we do not rank them. Read each target's capability statement at /metadata , check its API documentation for create and update on each resource, and test in its sandbox. The ONC (g)(10) criterion covers read services, so certification does not tell you about write support.

How do I handle FHIR API rate limits for AI agents?

Read the limit in your target's documentation, because it varies. Cache data that rarely changes, ask for only the resources the task needs, use _include or batch requests where the server supports them, and back off on 429 responses.

What is the difference between MCP-FHIR and direct FHIR API calls?

With direct calls, your code or model must build FHIR queries. With MCP, a server exposes named tools, such as get_active_medications , and handles the query, paging and formatting. MCP is an abstraction above FHIR. Authorization is optional in MCP, so you must enable and test it.

Is HL7 AI Transparency on FHIR a final standard?

Not yet. As of 30 October 2026 the published edition is the 1.0.0 STU1 ballot, and it states no official version has been published. NIST says organizations may pilot it and expects further revisions.

How do you assess interoperability standards compliance (FHIR, HL7) for AI CDS?

Ask for the named versions of FHIR, US Core, SMART and CDS Hooks, test results such as Inferno reports, and a run against each of your EHR sandboxes. A vendor's statement that it supports FHIR shows intent, and only a test run shows it works with your systems.

What tools connect AI to FHIR and clinical data securely?

Usually a SMART on FHIR authorization flow, a tool layer or MCP server that enforces policy, and an audit log, all running on services covered by a BAA where PHI is involved. The security comes from scopes, patient checks and logging, so check those whichever product you choose.
Share