From monolithic workflow to state graph
Technical series · Article 1 of 3
In a tactical command and control (C2) system, an event is not a prompt to be responded to. It's a cycle: sense, orient, decide, act — and then check back to see if the situation has changed.
For years we have modeled these flows as linear pipelines: ingest → analysis → output. This works for reports. Does not work when the threat evolves while the workflow is still running, when operator approval is needed, or when two data sources contradict each other.
LangGraph is not "just another AI framework". It's a graph orchestration engine designed for stateful workflows, conditional branching, human interruptions, and exactly where you left off.
In this series I use a concrete use case — application workflows for a tactical C2 — to show how such a system is designed, implemented and brought into production.
The problem: why chains are not enough
A classic chain LangChain is sequential:
Evento → Classificazione → Tasking → RispostaIn tactical C2 it continually happens that:
- Classification changes while you are already allocating assets
- Need a human gate before high-impact actions
- Two parallel branches must converge (e.g. radar + video + open source intelligence)
- The workflow must pause waiting for ACK from an operator and resume hours later
- Every step must be auditable — who decided what, with what context
A graph solves this natively: nodes (functions/agents), edges (transitions), shared state (TypedDict), checkpoints (persistence).
Reference architecture
Scenario: Tactical Operations Center (TOC) receiving events from edge sensors, correlating them, assessing the threat, applying Rules of Engagement (ROE), and proposing tasking — with human approval required above a certain threshold.
flowchart TB
subgraph INGEST["Layer ingest"]
S1[Sensori edge]
S2[Feed AIS/GIS]
S3[Intelligence aperta]
end
subgraph GRAPH["LangGraph StateGraph"]
N1[Correlazione eventi]
N2[Classificazione minaccia]
N3[Validazione ROE]
N4[Allocazione asset]
N5[Gate operatore]
N6[Esecuzione tasking]
N7[Feedback loop]
end
subgraph STATE["Stato condiviso C2State"]
ST1[situational_picture]
ST2[threat_level]
ST3[roe_decision]
ST4[proposed_actions]
ST5[human_approval]
ST6[audit_trail]
end
subgraph PERSIST["Persistenza"]
CP[PostgreSQL Checkpointer]
LS[LangSmith traces]
end
S1 --> N1
S2 --> N1
S3 --> N1
N1 --> N2
N2 -->|LOW/MEDIUM| N4
N2 -->|HIGH/CRITICAL| N3
N3 --> N4
N4 --> N5
N5 -->|approved| N6
N5 -->|rejected| N7
N6 --> N7
N7 -->|nuovo evento| N1
N1 -.-> STATE
N2 -.-> STATE
N3 -.-> STATE
N4 -.-> STATE
N5 -.-> STATE
N6 -.-> STATE
GRAPH --> CP
GRAPH --> LSKey Point: Status is not a log. It is the contract between the nodes. Each node reads, updates and passes forward only what is needed.
Defining state: the heart of design
In LangGraph the state is defined with a TypedDict (or Annotated with reducer for accumulating fields):
from typing import Annotated, Literal, TypedDict
from langgraph.graph.message import add_messages
class Track(TypedDict):
track_id: str
source: str
position: tuple[float, float]
confidence: float
timestamp: str
class ProposedAction(TypedDict):
action_id: str
asset_id: str
action_type: Literal["MONITOR", "INTERCEPT", "ALERT_UPCHAIN"]
rationale: str
class C2State(TypedDict):
# Situational picture — merge con reducer custom
tracks: Annotated[list[Track], "merge_tracks"]
threat_level: Literal["LOW", "MEDIUM", "HIGH", "CRITICAL"]
roe_status: Literal["PENDING", "COMPLIANT", "NON_COMPLIANT", "ESCALATED"]
proposed_actions: list[ProposedAction]
human_approval: Literal["PENDING", "APPROVED", "REJECTED", "TIMEOUT"] | None
messages: Annotated[list, add_messages] # per agenti LLM
audit_trail: Annotated[list[dict], "append_audit"]
iteration: intThe choice of fields is not implementational. It's architectural:
trackswith reducer → new events merge without losing historyaudit_trailappend-only → each node records input/output/decisionhuman_approvalnullable → the graph knows when it is paused
Construct the graph
from langgraph.graph import StateGraph, START, END
def build_c2_graph():
graph = StateGraph(C2State)
graph.add_node("correlate", correlate_events)
graph.add_node("classify", classify_threat)
graph.add_node("validate_roe", validate_roe)
graph.add_node("allocate", allocate_assets)
graph.add_node("human_gate", human_approval_gate)
graph.add_node("execute", execute_tasking)
graph.add_node("feedback", update_situational_picture)
graph.add_edge(START, "correlate")
graph.add_edge("correlate", "classify")
graph.add_conditional_edges(
"classify",
route_by_threat_level,
{
"LOW": "allocate",
"MEDIUM": "validate_roe",
"HIGH": "validate_roe",
"CRITICAL": "validate_roe",
},
)
graph.add_edge("validate_roe", "allocate")
graph.add_edge("allocate", "human_gate")
graph.add_conditional_edges(
"human_gate",
route_after_approval,
{
"approved": "execute",
"rejected": "feedback",
"pending": END, # sospensione — riprende con checkpoint
},
)
graph.add_edge("execute", "feedback")
graph.add_edge("feedback", END)
return graphNotice three advanced patterns already here:
- `add_conditional_edges` — routing is not hardcoded into the node, it is a pure state function
- `END` on pending — the graph ends intentionally while waiting for the operator
- classify / validate_roe separation — compliance and threat assessment are distinct nodes, testable in isolation
Checkpointer: Pause and resume
In C2 you cannot lose context between one watch shift and the next.
from langgraph.checkpoint.postgres import PostgresSaver
checkpointer = PostgresSaver.from_conn_string(DB_URI)
app = build_c2_graph().compile(
checkpointer=checkpointer,
interrupt_before=["human_gate"], # pausa prima del gate umano
)
# Prima esecuzione — si ferma al gate
config = {"configurable": {"thread_id": "mission-alpha-042"}}
result = app.invoke(initial_state, config)
# Ore dopo — l'operatore approva via API
app.update_state(
config,
{"human_approval": "APPROVED"},
)
result = app.invoke(None, config) # riprende da dove erainterrupt_before + thread_id = long-running workflow without keeping processes in memory.
What changes compared to a generic orchestrator
| Appearance | BPMN Workflow /cron | LangGraph |
|---|---|---|
| Status | Often external to the engine | First-class, typed |
| LLM / agents | Ad hoc integration | Native node in the graph |
| Human-in-the-loop | Custom implementation | interrupt_before / update_state |
| Audits | Application log | Status + checkpoint + LangSmith |
| Branching | Often rigid | conditional_edges on function |
| Recovery | Manual reconstruction | Thread-scoped checkpoints |
Design decisions that matter
1. Small nodes, explicit state
One node = one responsibility. If classify_threat also does ROE and tasking, you lose testability and auditability.
2. LLM where judgment is needed, code where determinism is needed The geometric correlation of the tracks is code. The synthesis of the situational picture can be an agent. Critical ROE validation remains deterministic rule engine with LLM only for explanation.
3. Thread ID = mission / operation
One thread_id per operation, not per user. The checkpoint becomes the "mission folder".
4. Not everything goes through the graph High frequency ingest (e.g. 10 Hz from radar) remains on stream processing (Kafka, Flink). The graph activates on significant events or on OODA cycles at human frequency.
🔥 Takeaway
LangGraph for Tactical C2 is not "putting ChatGPT in the TOC". It's modeling decisions with state, branching, and accountability in a graph that can pause, resume, and be audited.
In the next article we go into operational detail: specialized agents, multi-agent routing, human-in-the-loop with timeout and automatic escalation.
