How AWS threat-designer decides its LangGraph agent is done: a deterministic validate node, not the model, and a quiet floor of 25 threats
Nothing the model says ends a threat-designer run. When the agent stops calling tools, it has not finished. It has only reached a plain Python function that decides whether it may finish.
Through a precondition buried in a tool, that function also rejects any catalog smaller than 25 threats (constants.py L124). I found that rule nowhere stated as a product requirement.
My claim is that this is the right design for deciding who controls the exit. It is also a crude way to define what "done" means. If you believe the model should orchestrate its own loop, you will disagree with the first half.
The model's "I'm done" only gets it as far as a plain-Python node
The project describes itself as "a LangGraph-based autonomous system that performs comprehensive security threat modeling using the STRIDE methodology" (threat-designer docs, L5). It pins langgraph>=1.2.4,<1.3.0 (requirements.txt L1).
The threats subgraph loops agent → tools → agent. A turn with no tool calls goes to validate. That node returns a Command, which sets the next route from inside the node.
It first rejects an empty catalog and a catalog that lacks coverage for the active methodology (L384–L396). Then it checks this:
# Check gap analysis was performed
if gap_tool_use == 0:
feedback = HumanMessage(
content="You have not performed gap analysis yet. Please call gap_analysis before finishing."
)
return Command(goto="agent", update={"messages": [feedback]})
Excerpt from AWS's threat-designer, Apache-2.0 (LICENSE); workflow_threats.py L398-L403.
The only clean exit is Command(goto="finalize", graph=Command.PARENT) (L420–L427). I checked the API by introspecting langgraph 1.2.17, which falls inside the pinned range: Command.PARENT == '__parent__'.
This is the shape the literature asks for. Huang et al. (2023) found that "LLMs struggle to self-correct their responses without external feedback." A model announcing it is done is exactly that kind of intrinsic self-assessment, and validate supplies the external feedback. Kambhampati et al. (2024) argue that LLMs "cannot, by themselves, do planning or self-verification" and belong inside loops with external verifiers. threat-designer has one hard-coded verifier and one model critic.
A 25-threat floor ships as a tool precondition, documented nowhere
The second LLM call, gap_analysis, is where the floor sits:
if threat_count < min_threats:
error_msg = (
f"Gap analysis requires at least {min_threats} threats in the catalog. "
f"Current count: {threat_count}. Please add more threats before performing gap analysis."
)
Excerpt from AWS's threat-designer, Apache-2.0 (LICENSE); tools.py L822-L826.
When it refuses, it counts no gap analysis. If the grading call itself fails, it returns a string "not Command, so state is not updated" (tools.py L1028–L1030). validate will not exit until a gap analysis is counted. So every run that reaches finalize had at least 25 threats at the moment the review ran.
One reversal is worth recording. An earlier version of this argument said the add-threats budget refills only after a successful gap analysis. The code disproves that: a refusal below the floor also refills it, with the comment "Reset tool_use counter so agent can continue adding threats" (tools.py L834–L845). The correction strengthens the reading: the loop is built to push the model toward the floor, not to ration it.
Tested vs read. I only read AWS's graph, because it needs Bedrock and DynamoDB. What I ran was a 39-line reduced graph: a stub model, one model node standing in for the model plus its tools, and a validate node with the same two rules.
It is not AWS's code. Writing 10 threats per turn, it produced (excerpted from one log line):
add_threats -> 10 | validate: no gap analysis yet | gap_analysis refused at 10 | ...
... add_threats -> 30 | validate: no gap analysis yet | gap_analysis ran at 30 | exit with 30 threats
The gate controls the exit, not the quality, and below the floor there is no exit
Here is the strongest objection, stated fairly. A fixed count is a crude proxy. A three-component diagram must still reach 25 threats (constants.py L124), and a model under pressure can write near-duplicates.
gap_analysis is itself an LLM judge, so the code guarantees only that a review happened, not that it was right. And a model that cannot reach 25 gets no graceful failure.
I concede all three points. The last one is the stakes. With zero threats per turn, my reduced graph raised GraphRecursionError and returned no catalog.
In threat-designer the loop is bounded by a recursion limit of 100 in the run config (agent.py L787–L791; LangGraph docs). If the model stops at 18 genuine threats on a small system, it does not get a short catalog. The loop runs until it hits that limit and the run raises.
The thesis survives because it is about control, not quality. The model's "done" is never enough. Padding remains a predicted failure. No production counts, size distributions, or duplicate rates are published, and I won't imply any.
Each alternative moves the cost somewhere else
- A plain ReAct loop that ends when no tool is called. It is the cheapest option. Its failure mode is the one Anthropic names: "the agent one-shotting an app or prematurely considering the project complete" (Anthropic (2025)). Pick it only when stopping early costs little.
- A router passed to
add_conditional_edges. The logic is the same, but routing and the feedback-message update live in two places. Pick it when you want routing inspectable on its own. - A coverage checklist. Anthropic's fix was a feature-requirements file, and threat-designer already checks methodology coverage. Coverage scales with the size of the system; a fixed number does not. The cost is that someone must maintain what "covered" means.
- A human interrupt before finalize. It catches what neither gate sees, at the cost of a person's time on every run.
As a decision rule: use coverage when system size varies widely, add a human when a wrong threat model is expensive, and keep a count only as a backstop.
Copy the gate only with four counters attached
- Share of runs that exit through
validateversus the recursion limit. validatebounces per run. The reduced graph's log shows these are countable straight from state.- Catalog size at exit. A pile-up at 25 to 30 on small systems is the padding signal, given the fixed minimum in constants.py L124.
- Duplicate threats per catalog.
The broader lesson is not about whether 25 is the right number (constants.py L124). In threat-designer, the most strictly enforced definition of "done" is a guard clause inside a tool, where nobody reviews it as a product decision. Before you trust your own agent's exit, read its tool preconditions. They are probably its real spec.
