How Blockstate Fits Into Your Python AI Stack
Blockstate is an embedded transactional compliance execution enclave. High-level orchestrators (LangGraph, Microsoft Semantic Kernel, AutoGen, AWS Bedrock) manage open-ended concierge dialogue and invoke Blockstate via as_tool() whenever a workflow enters a regulated boundary requiring compile-time Lengauer-Tarjan dominator proofs, stage-scoped MappingProxyType tool gating, and RFC 8785 JCS SHA-256 audit ledgers.
Turn Latency, Memory Isolation & CI Verification Benchmarks
Measured on a 6-stage financial wire transfer workflow with 1 nested Pydantic v2 slot schema (7 leaf paths), 1 mid-flow FAQ digression, and 3 payment rail tools on Python 3.12.
| Benchmark Metric | LangGraph Alone | NVIDIA NeMo Guardrails (Colang 2.0) | PydanticAI (pydantic-graph) | Guardrails AI / Instructor | Blockstate (or LangGraph + Blockstate Enclave) |
|---|---|---|---|---|---|
| Compile-Time CFG Extraction (Zero Execution) | Not supported (requires runtime instantiation) | .co syntax parse only | mypy type check (~800ms) | Single-turn schema only | 7.1ms via ast.parse ([Blockstate E014]) |
| Lengauer-Tarjan Dominator Proof in CI | None | None | None | None | 8.4ms (<50ms budget for |V| ≤ 250) |
| Per-Turn Orchestration Overhead | 1,200ms to 2,800ms (serialised LLM routing hops) | 3,100ms to 5,800ms (multi-hop input/dialog/output rails) | 450ms to 1,400ms (LLM node transition call) | 350ms to 1,100ms (validator re-asking loop) | ≤5ms Core Statechart + <50ms Local ONNX Pass 1 |
| Edges Required for 6 Stages × 4 FAQ Tangents | 24+ manual bidirectional subgraph edges | 10+ concurrent Colang flow handlers | 24+ Union return annotations | No multi-turn state machine | 6 edges + allow_digressions=['faq'] on TaskStack |
| Memory-Boundary Tool Gating | Global ToolNode list | Action server string dispatch | Runtime prepare callback | No tool dispatch boundary | Ephemeral per-stage types.MappingProxyType |
Blockstate + LangGraph vs LangGraph Alone
LangGraph is an effective high-level orchestrator for open-ended multi-agent research, RAG retrieval, and general customer routing. However, implementing regulated transactional subflows (such as FCA SYSC 13.7 wire transfers or FNOL insurance claims) directly inside raw LangGraph nodes introduces three operational risks: global ToolNode exposure, O(N × M) subgraph wiring for user digressions, and the absence of compile-time dominator proofs.
# In raw LangGraph, ToolNode holds the union of all tools
# across the graph, and routing relies on runtime functions:
tools = [query_policy_handbook_rag, authorise_bacs_payout]
tool_node = ToolNode(tools)
workflow = StateGraph(ClaimStateDict)
workflow.add_node("agent", call_llm_with_all_tools)
workflow.add_node("tools", tool_node)
workflow.add_conditional_edges("agent", dynamic_router_fn)
# Risks in regulated workflows:
# 1. authorise_bacs_payout is present in ToolNode during intake.
# 2. dynamic_router_fn cannot be verified via ast.parse before runtime.
# 3. Handling an FAQ tangent requires manual state-saving edges
# from every collection node to the FAQ node and back.
from blockstate.adapters.langchain import as_tool
from my_enclaves import MotorInsuranceClaimAgent
# 1. Verify dominance in CI (<50ms) before deploying:
# $ blockstate verify my_enclaves.py --dominates "intake_claim -> [tier_auto_payout]"
# 2. Mount the verified Blockstate enclave inside LangGraph:
claim_enclave = as_tool(
agent_cls=MotorInsuranceClaimAgent,
name="motor_claim_enclave",
description="Governed FNOL motor claim enclave with TaskStack & PIIVault.",
)
# LangGraph handles concierge greeting; Blockstate enforces
# MappingProxyType tool gating, TaskStack tangents & TurnLedger.
langgraph_concierge.bind_tools([claim_enclave])
When to Use Both Together via as_tool()
Use LangGraph as your top-level conversational router for open-domain intent triage, multi-document synthesis, and general customer assistance. Mount Blockstate via as_tool() for every regulated transactional boundary (identity verification, payment execution, policy modification, clinical triage, and claims adjudication) where MRM and CISO reviewers require mathematical dominance proofs and physical memory tool isolation.
Blockstate vs NVIDIA NeMo Guardrails (Colang 2.0)
NVIDIA NeMo Guardrails requires engineering teams to author dialogue flows in a proprietary domain-specific language (Colang .co files) and executes multi-hop LLM calls across input rails, dialogue rails, and output rails (adding 3 to 6 seconds of latency per turn). Blockstate is written in 100% standard Python 3.12+ with PEP 695 typing and Pydantic v2 models, executing its core statechart transitions in under 5 milliseconds.
# Requires maintaining separate .co DSL files outside Python typing:
flow wire transfer
user request wire transfer
await verify user kyc
if $kyc_verified
execute fps_payment_action
else
bot inform transfer blocked
# Limitations for regulated enterprise Python teams:
# - No mypy / pyright IDE autocompletion or Pydantic v2 leaf locking.
# - No Lengauer-Tarjan dominator verifier across fallback edges.
# - Multi-hop LLM rail evaluation adds 3,000ms to 6,000ms per turn.
# - No built-in RFC 8785 JCS SHA-256 hash-chained TurnLedger.
@Stage(name="step_up_mfa_kyc", tools=["verify_fido2_passkey"], max_turns=3)
@Guard(requires=("user_id",))
@Transition(targets=("faster_payments_uk", "fraud_lock"))
async def step_up_mfa_kyc(
self, slots: TransferDetails
) -> Transition["faster_payments_uk" | "fraud_lock"]:
verified = await self.tools.verify_fido2_passkey(
user_id=self.session["user_id"]
)
if not verified:
return Transition.to("fraud_lock")
return Transition.to("faster_payments_uk")
Blockstate vs PydanticAI (pydantic-graph) & LlamaIndex Workflows
Both pydantic-graph and LlamaIndex Workflows offer clean Python async execution for general agent pipelines, and Blockstate integrates with pydantic-ai-slim as an optional model adapter. However, general-purpose graph libraries rely on standard type checking or runtime event dispatch rather than zero-execution AST compilation, Lengauer-Tarjan dominator proofs, recursive PartialSlotModel Δ-hydration, or LIFO pushdown stacks.
| Requirement in Regulated Production | PydanticAI (pydantic-graph) | LlamaIndex Workflows | Blockstate (blockstate) |
|---|---|---|---|
Static Rejection of Dynamic Reflection (getattr) |
Permitted by Python runtime | Permitted by Python runtime | Halted at build time with [Blockstate E014] (BLK-AST-014) |
| Mathematical Precursor Dominance Proof | Checks node return types only; does not compute dominator trees | Event step decorators only; no dominator verification | Lengauer-Tarjan solver proves u dom v across all edges including on_breach |
| Progressive Multi-Turn Nested Pydantic Collection | Requires all fields in single turn or manual Optional boilerplate | Requires custom dict accumulation across events | Automatic recursive PartialSlotModel with UNSET sentinel & leaf locking |
| Mid-Flow Customer FAQ Digressions | Manual node edges back and forth | Manual event emission and state restoration | LIFO TaskStack pushes read-only child TaskFrame and pops cleanly |
Blockstate vs Guardrails AI, Instructor & Custom Python FSMs
Libraries such as Instructor and Guardrails AI solve single-turn structured output extraction and text validation. Blockstate solves the multi-turn statechart lifecycle: progressive leaf-level slot hydration across turns, volatile detokenisation inside validators, hardware-boundary tool gating per stage, distributed session lease fencing, and hash-chained turn auditability.
Where Single-Turn Validators & DIY FSMs Stop
- • Single-Turn Retry Loops: Instructor and Guardrails AI re-prompt the LLM within a single API call, which fails when missing fields must be collected from a human user across 4 conversational turns.
- • All-or-Nothing Validation: Standard Pydantic validation rejects an entire payload if 1 out of 5 user-supplied fields is malformed, discarding the 4 valid fields the user already typed.
- • DIY State Machine Drift: Custom Python
Enumstate machines quickly accumulate dynamic transition hacks, lack Lengauer-Tarjan CI verification, and expose raw PII to model APIs.
What Blockstate Provides Out of the Box
- ✔ Per-Leaf Preservation (
BLK-VAL-002): If a customer provides 4 valid fields and 1 invalid field in Turn 1, Blockstate locks the 4 valid leaves and re-prompts solely for the rejected leaf and remainingΔ. - ✔ Volatile Validator Detokenisation:
wrap_detokenising_validatorunwraps<VAULT:...>tokens in volatile RAM during@field_validatorexecution, immediately re-binds tokens, and scrubs PII from any raised exception message. - ✔ Distributed Concurrency & Auditability: Fenced session leases (
BLK-CON-409), Compare-And-Swap state writes (BLK-STO-002), and RFC 8785 JCS SHA-256TurnLedgerpersistence.