A clinical agent that only reads the chart is a demo. The useful ones propose changes: a reconciled medication list, a care gap order, a corrected problem entry. Once an agent can write to the record, the design question becomes how it is stopped.
This post is for engineers and technical leads building clinical agents on HL7 FHIR. It walks through a LangGraph design with narrow FHIR read tools, a draft step that produces an exact payload, a human approval node that pauses the graph, and a write step that sends only what a clinician approved.
How do you build a clinical AI workflow with LangGraph and FHIR?
Building an agent on FHIR data?
Our FHIR and SMART on FHIR team builds the read tools, scopes and write paths that clinical agents need.
A clinical AI workflow in LangGraph is a graph of nodes that share state: tools read FHIR resources, a model drafts a proposed change, an approval node pauses for a clinician, and a write node sends the approved payload. Agnotic Technologies places the human approval node before every write, so the model never changes the record on its own.
The graph structure makes the control points explicit. Reviewers can see where data comes in, where the model acts and where a person decides.
Why use a stateful graph instead of a single agent loop?
A stateful graph fits clinical work because the steps, checks and pause points are fixed by design, not chosen by the model at run time. A free agent loop decides its own next step, which is hard to review and harder to audit.
LangGraph describes itself as a low-level orchestration framework and runtime for long-running, stateful agents, in which workflows are defined as graphs of shared state, nodes and edges.
In practice, the model chooses within a node, such as which resources to summarize, while the edges between nodes are code. The path from draft to write always passes through approval, whatever the model outputs.
Which clinical tasks suit this pattern?
The pattern suits tasks where the agent gathers evidence, proposes a specific structured change and a clinician can judge it quickly. It suits poorly any task where the decision itself needs a full clinical assessment.
- Good fit: medication list reconciliation drafts, care gap orders proposed for signature and problem list clean-up.
- Good fit: draft referral letters or prior authorization packets assembled from chart data.
- Poor fit: diagnosis, dosing decisions or anything a reviewer cannot verify from the evidence shown.
If a reviewer would need to redo the agent's work to check it, the approval step adds delay without adding safety. Pick tasks where checking is much faster than doing.
What goes in the graph state?
The graph state holds what every node needs and what the audit needs, and nothing more. Keep references to FHIR resources rather than copies of whole records where possible.
- Task: the request, the patient reference and who or what started the run.
- Evidence: ids and versions of the FHIR resources the tools read.
- Proposal: the exact FHIR payload the model drafted, plus its explanation.
- Decision: approve, edit or reject, the reviewer and the time.
- Run metadata: model and prompt versions, tool call log and errors.
State is persisted, so treat it as health data. Encrypt the checkpoint store, limit access, and set a retention period for finished threads.
FHIR read tools with narrow scopes
FHIR read tools should each answer one question with one query, using a token limited to read scopes for the resource types that task needs. A general search tool with broad access invites the model to pull far more than the task requires.
- One tool per query: active medications, recent lab results by code, current problem list.
- Read-only credentials: separate from the credentials the write node uses.
- Result limits: cap counts and date ranges, and return selected fields to the model.
- Versions: record each resource's version id so later steps can detect changes.
Write the tool descriptions for the model as carefully as the code. A vague description leads the model to call the wrong tool or to call one repeatedly, which costs time and widens what it reads.
Where does the human approval node sit?
The human approval node sits directly before the write node, on every path that can change the record. It shows the clinician the exact proposed payload, the evidence behind it and what will change.
LangGraph interrupts pause graph execution at a chosen point to wait for external input; when one is triggered, LangGraph saves the graph state through its persistence layer and waits until execution is resumed.
Because the state is saved, a run can wait hours for a clinician without holding resources. Use a durable checkpointer in production, and key each thread with an id that does not contain patient identifiers.
On resume, recheck the evidence versions. If a medication or result changed while the run waited, send the proposal back to the draft node instead of writing stale data.
How should the write step work?
The write step should send exactly the payload the clinician approved, once, with a record of who approved it. It should never call the model, and it should fail loudly when the server refuses the write.
- Exact payload: what the reviewer saw is what the server receives, including any edits.
- Idempotency: retries after a timeout must not create duplicates, so check before creating.
- Version checks: update only if the resource version matches the one reviewed.
- Provenance: record the approving clinician, the agent run and the time with the change.
Guarding against excessive agency
Excessive agency is the risk that an agent does more than intended because it has more tools, permissions or autonomy than the task needs. Graph design is the main defense.
OWASP defines excessive agency as the vulnerability that lets an LLM application take damaging actions in response to unexpected, ambiguous or manipulated model output, usually caused by excessive functionality, permissions or autonomy.
Give the model only read tools, keep write credentials in a node it cannot call, and validate every proposal against a schema and clinical rules before it reaches a reviewer. Content inside notes should be treated as data, never as instructions to the agent.
What fails in LangGraph clinical workflows?
Most failures come from treating a prototype graph as production. They show up as lost approvals, duplicate writes or stale proposals.
- In-memory checkpoints: pending approvals lost when the service restarts.
- Approving prose: the clinician approves a summary while the write node sends something else.
- Stale evidence: a proposal approved after the source record changed.
- Prompt stuffing: tools returning whole bundles that crowd the context and leak extra data.
- Retry duplicates: a timeout followed by a second create.
- Identifiers in thread ids: patient numbers appearing in logs and traces.
A worked example: a medication list reconciliation draft
After discharge, the agent reads the patient's active medication statements and the discharge medication list. The draft node proposes which entries to stop, start or change, as exact FHIR updates with reasons.
The graph pauses at approval. A pharmacist reviews the changes the next morning, removes one proposal and approves the rest.
On resume, the graph rechecks versions, finds nothing changed and writes the approved updates with provenance. The rejected item and its reason are stored for prompt evaluation.
Over several weeks, the clinical owner reviews the rejected proposals as a group. A cluster of rejections for one drug class leads to a prompt change and a new test case, both versioned before the next release.
Who owns what?
A clinical agent needs a clinical owner as well as an engineering owner. The clinical owner decides what the agent may propose and who may approve it.
- Clinical owner: allowed proposal types, approver roles and review of rejected proposals.
- Engineering team: graph design, tools, checkpointer, write node and monitoring.
- FHIR platform or EHR team: app registration, scopes and write permissions.
- Security and privacy: checkpoint storage, logging rules and model provider terms.
Agree a pause switch with the clinical owner. If rejection rates jump or a bad write slips through, the team should be able to stop new runs at once while pending approvals stay saved.
How do you test the graph?
Test each node in isolation, then whole runs against a FHIR test server with synthetic patients. Test the pause and resume path as carefully as the happy path.
- Node tests: tools return the right fields; the write node rejects unapproved payloads.
- Graph tests: every path to the write node passes through approval.
- Resume tests: restart the service mid-approval and confirm the run resumes.
- Change tests: modify a source resource while paused and confirm the proposal is redrafted.
- Adversarial tests: instructions hidden in a note must not change the agent's actions.
What are LangGraph FHIR workflow best practices?
Fix the path in graph edges, give the model read-only tools with narrow scopes, and put an interrupt-based approval node before every write. Store the exact payload and evidence versions in state.
Use a durable, encrypted checkpointer, recheck versions on resume, write idempotently with provenance, and test restarts and hidden instructions before go-live.
How Agnotic can help
Agnotic builds clinical agents on FHIR: LangGraph or equivalent orchestration, narrow read tools, approval steps that show exact payloads, safe write nodes with provenance, durable checkpoints and test suites for pause, resume and adversarial input. We work with your clinical owners on what the agent may propose.
Build a clinical AI agent with Agnotic
We design agents that read FHIR data, draft changes and wait for a clinician's approval.
Related reading on Agnotic
Agents, approvals and FHIR APIs.


