This article is published in English.
Practical notes: Building LEPA Support Agent with LangGraph
Operable walkthrough of Practical notes: Building LEPA Support Agent with LangGraph: contracts, checks, and drop-in code slots for teams shipping this pattern.
Use this as an operator-facing rebuild of the ideas in “Building LEPA Support Agent with LangGraph”: clear stages, ordered code slots, and recovery notes that survive a handoff. The Overview stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline.
What you wanted the first graph to do
For the What you wanted the stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
User message
↓
Notice who is speaking (teacher / admin / unknown)
↓
Classify the topic (grades, login, …)
↓
Too vague? Ask a clarifying question
↓
Otherwise continue toward docs + an answer
Project setup (kept intentionally boring)
For the Project setup kept intentionally stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
PRJ-02/
├── app/
│ ├── state.py # SupportState
│ ├── graph.py # StateGraph wiring
│ ├── agents/ # intake, knowledge, support
│ ├── nodes/ # classify, ask_clarification
│ └── tools/ # search_knowledge (next article)
├── knowledge/ # LEPA support Markdown
├── api/ # FastAPI (later article)
└── tests/
State: the object that travels through the graph
For the State the object that stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness. For the State the object that stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline.
messages # conversation turns (add_messages reducer)
user_role # teacher / admin / unknown
issue_category # grades, authentication, …
clarification_needed # should we ask for more detail?
clarification_question # what we ask
retrieved_documents # doc snippets (later step)
final_answer # what we return to the user
conversation_summary # reserved for later — unused in v1
messages: Annotated[list, add_messages]
{"user_role": "teacher"}
{"issue_category": "grades", "clarification_needed": False}
Nodes: one job each
When working through the Nodes one job each stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
(state) → partial update
Intake
When working through the Intake stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
Classify
When working through the Classify stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node. When working through the Classify stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline.
Ask clarification
The Ask clarification stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
Knowledge + support
The Knowledge support stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
Edges: how control moves
The Edges how control moves stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
Normal edges
The Normal edges stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
graph.add_edge(START, "intake")
graph.add_edge("intake", "classify")
graph.add_edge("knowledge", "support")
graph.add_edge("support", END)
When this node finishes, always go there next.
Conditional edges
The Conditional edges stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
def route_after_classify(state: SupportState) -> Literal["clarify", "continue"]:
if state.get("clarification_needed"):
return "clarify"
return "continue"
graph.add_conditional_edges(
"classify",
route_after_classify,
{
"clarify": "ask_clarification",
"continue": "knowledge",
},
)
"help" → clarify → ask_clarification → END
"How do I enter grades?" → continue → knowledge → support → END
START and END
The START and END stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
START = where the runtime begins
END = where this run stops
START → intake → classify → …
…
ask_clarification → END
support → END
The full topology (as built)
The The full topology as stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
START
→ intake
→ classify
→ conditional
├─ clarify → ask_clarification → END
└─ continue → knowledge → support → END
How a request moves through the graph
The How a request moves stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
Clear question
The Clear question stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
User: "Why aren't grades showing?"
↓
intake → user_role = unknown (unless they said teacher/admin)
↓
classify → issue_category = grades, clarification_needed = False
↓
route → "continue"
↓
knowledge → search docs (next article)
↓
support → final_answer
↓
END
Vague question
User: "help"
↓
intake
↓
classify → unknown + clarification_needed = True
↓
route → "clarify"
↓
ask_clarification → asks which LEPA area
↓
END
compile() and invoke(): the runtime moment
return graph.compile(checkpointer=checkpointer)
from langchain_core.messages import HumanMessage
from app.graph import app_graph
result = app_graph.invoke(
{"messages": [HumanMessage(content="How do I enter grades?")]}
)
print(result["final_answer"])