AgentContext.record_decision() stores every AI decision as a node in the knowledge graph, linked by causal edges to the decisions that preceded it and the outcomes that followed. Use it to build an auditable reasoning trail — one that lets you reconstruct, six months later, exactly which classification caused which escalation, and which policy was checked before it was recorded.
Decision tracking requires both a
VectorStore (for embedding-based precedent search) and a ContextGraph (for causal graph storage). Set decision_tracking=True on AgentContext — omitting either component raises RuntimeError at call time.Recording the First Decision
The most common entry point isAgentContext.record_decision(). It writes a Decision node into the graph, generates embeddings for hybrid similarity search, and returns a UUID you use to link subsequent decisions causally.
Decision dataclass that backs this node has the following fields — these are what get stored and searched:
Searching Precedents Before Deciding
Before making a significant call, the system should search past decisions for similar scenarios. This is how you prevent the same cluster being classified differently across two agent runs — the second agent finds the first agent’s decision and uses it as a prior.scenario and reasoning text (weight 0.7), and structural graph proximity via Node2Vec embeddings (weight 0.3). The result is a ranked list of Decision objects — the most similar past decisions float to the top regardless of how differently they were phrased.
Building a Causal Chain
Decisions rarely exist in isolation. A classification decision causes an escalation decision, which causes a containment decision. Linking them with causal edges lets you traverse the chain in either direction — upstream to understand what caused an outcome, downstream to see what an early decision triggered.Generating an Explainability Report
trace_decision_explainability gives you the full picture in one call: upstream causes, downstream effects, and total connection count. This is what you attach to a post-mortem or audit report.
trace_decision_causality on the graph directly:
Gating Decisions Against Policy
Before recording a high-stakes decision, check it against a versioned policy. ThePolicyEngine stores Policy nodes in the graph and gates Decision objects against their rules.
DecisionRecorder.record_approval_chain() with a graph database backend (for example Neo4j/FalkorDB). The in-memory ContextGraph examples used in this guide do not support approval-chain persistence via execute_query().
Generating a Decision Audit Report
At the end of a shift or incident,get_decision_insights produces a statistical summary of every decision in the graph — useful for shift handover notes and compliance reporting.
Domain Examples
- Defense — CTI/Threat
- Security — SOC/Incident
- Life Science — Clinical/Pharma
- Banking — Risk/Compliance
A CTI pipeline classifies threat clusters, records each classification with confidence and reasoning, links classification decisions to escalation decisions causally, and generates a daily audit report for the threat intelligence lead.
Persisting Decisions Across Restarts
When using the localContextGraph, save at the end of every session and load at the start of the next. All decision nodes, causal edges, and FAISS embeddings are restored.
Related Guides
- Context Graphs — how
ContextGraphstores decision nodes and causal edges - Distance Intelligence —
trace_decision_causality()annotates causal chains with confidence decay and distance bands - Provenance — W3C PROV-O audit trail that wraps decision records in standards-compliant provenance
- MCP Server — expose decision recording and precedent search to LLM agents via the
record_decisionandfind_precedentstools - Change Management — checkpoint decision state with
flush_checkpoint()for versioned snapshots
