Deep dive 6 of 27: Agentic Outcome: Strict State Serialization
Nov 19, 2026 · Michael Chang · Status in NurseOps Now: 🟡 partly built
Show definitions in ( ) · hover a highlighted word for its meaning, click it for details · open with ?defs=1 to show definitions
Part of: Remembering the right things: state management in NurseOps Now, section Context and State Management (Intro) · All 27 solutions · ← Agentic Outcome: Hybrid Memory Systems · Token Counting Middleware →
Read in this order
- In plain words: what it is, without jargon
- The problem it solves: the problem, and the standard approach in my words
- How to implement it (ServiceApps): scenario, steps, code and real output
- In NurseOps Now: built or not, and where
- Trade-offs and Interview answer
In plain words
Serialization means saving the agent (an AI that chooses which tools to use to answer)'s full working state (everything the app must remember to continue correctly) (which step it's on, what's done, what it learned) to disk after every step, so it can pause, crash and resume exactly where it left off, without redoing or losing work.
In plain terms: a video game save point after every level, so a power cut doesn't send you back to the start.
The problem it solves
No external state (nothing saved outside the model, so everything is lost when the program stops): a crash or restart mid-task loses the progress, or worse, repeats a step that shouldn't run twice (like sending an email).
The standard approach (in my words): implement strict state (everything the app must remember to continue correctly) serialization so agents (an AI that chooses which tools to use to answer) can pause, crash and resume without data loss.
How to implement it (ServiceApps)
Illustrative example: no ServiceApps (a company platform for IT tickets, HR requests and help-center articles) instance is connected, so the scenario and data are made up. The code is a self-contained sketch; it was run on that made-up data on Nov 19, 2026, and the output below is from that run.
The setting. ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist, an AI helper inside a company's ServiceApps (a company platform for IT tickets, HR requests and help-center articles) portal. Employees ask it IT and HR questions; it answers from knowledge-base (KB (knowledge base: a library of help articles)) articles, looks up the employee's own tickets (incidents (a ServiceApps ticket for something broken) like INC0012345) and requests, and keeps one conversation per employee and ticket.
The scenario. ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist runs a 4-step workflow (a fixed series of steps the app runs) on a ticket: triage, look up KB (knowledge base: a library of help articles), draft a reply, send it. It crashes during the draft.
Steps.
- Define the state (everything the app must remember to continue correctly) as a small, typed object (step, done, facts).
- Save it after every step, atomically (write a temp file, then rename).
- On restart, load the state (everything the app must remember to continue correctly) and continue from the saved step.
- Make steps that touch the outside world (sending) run once, after everything else is saved.
The code (Python):
import json, os, tempfile
from dataclasses import dataclass, asdict, field
@dataclass
class TicketWorkflow:
ticket: str
step: str = "triage"
done: list = field(default_factory=list)
STEPS = ["triage", "lookup_kb", "draft_reply", "send"]
path = os.path.join(tempfile.mkdtemp(), "INC0012345.json")
def save(s):
tmp = path + ".tmp"
with open(tmp, "w") as f:
json.dump(asdict(s), f)
os.replace(tmp, path) # atomic: never a half-written file
def load():
with open(path) as f:
return TicketWorkflow(**json.load(f))
def run(s, crash_at=None):
for name in STEPS[STEPS.index(s.step):]:
if name == crash_at:
raise RuntimeError(f"crashed during {name}")
s.done.append(name)
s.step = STEPS[STEPS.index(name) + 1] if name != "send" else "finished"
save(s)
return s
try:
run(TicketWorkflow("INC0012345"), crash_at="draft_reply")
except RuntimeError as e:
print("first run:", e)
s = load(); print("saved state:", s.step, s.done)
s = run(s); print("resumed: ", s.step, s.done)
Output (from running the code above):
first run: crashed during draft_reply saved state: draft_reply ['triage', 'lookup_kb'] resumed: finished ['triage', 'lookup_kb', 'draft_reply', 'send']
What to watch for.
- Save after the step, never before, and make each step safe to repeat if it might run twice.
- Version the state (everything the app must remember to continue correctly) format, so old saves still load after a code change.
- Don't save secrets or raw personal data in the state (everything the app must remember to continue correctly).
In plain terms: the workflow (a fixed series of steps the app runs) writes down 'done: triage, lookup' after each step, so after a crash it picks up at 'draft reply'.
In NurseOps Now
Partly built. AI Assist (the app's chat helper for staff questions) chat is checkpointed after every graph step by LangGraph (a tool for building AI workflows step by step)'s SqliteSaver and survives restarts (the parent post's demo). The case review workflow (a fixed series of steps the app runs) (review_graph.py) is not checkpointed mid-run: a crash reruns it from the start, which is safe because the case status only changes when it finishes. See Step 1.
Trade-offs
- Saving every step adds disk writes and a little latency (how long it takes to respond).
- Resuming is only safe if steps are idempotent (safe to repeat).
Interview answer
"I serialize the agent (an AI that chooses which tools to use to answer)'s state (everything the app must remember to continue correctly) after every step, atomically, so a crash resumes at the last completed step instead of starting over or repeating side effects. In LangGraph (a tool for building AI workflows step by step) that's a checkpointer (the code that saves a checkpoint after each step) keyed by thread (one saved conversation, here one per user and case) ID; for a custom workflow (a fixed series of steps the app runs) it's a small typed state (everything the app must remember to continue correctly) object written to disk."
All data in this post is made up. No real people, tickets or patient data.
← Back to all 27 solutions in the state management blog
Key terms
Every highlighted word in this post links here. Click ↩ Back to return to the spot you came from.
- agent
- An AI that chooses which tools to use to answer.Used in: In plain words, The problem it solves, Interview answer↩ Back to where you were
- AI Assist
- The app's chat helper for staff questions.Used in: In NurseOps Now↩ Back to where you were
- checkpointer
- The code that saves a checkpoint after each step.Used in: Interview answer↩ Back to where you were
- incident
- A ServiceApps ticket for something broken.Used in: How to implement it (ServiceApps)↩ Back to where you were
- KB
- Knowledge base: a library of help articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
- LangGraph
- A tool for building AI workflows step by step.Used in: In NurseOps Now, Interview answer↩ Back to where you were
- latency
- How long it takes to respond.Used in: Trade-offs↩ Back to where you were
- no external state
- Nothing saved outside the model, so everything is lost when the program stops.Used in: The problem it solves↩ Back to where you were
- ServiceApps
- A company platform for IT tickets, HR requests and help-center articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
- state
- Everything the app must remember to continue correctly.Used in: In plain words, The problem it solves, How to implement it (ServiceApps), Interview answer↩ Back to where you were
- thread
- One saved conversation, here one per user and case.Used in: Interview answer↩ Back to where you were
- workflow
- A fixed series of steps the app runs.Used in: How to implement it (ServiceApps), In NurseOps Now, Interview answer↩ Back to where you were