TrustGraph
key conceptsintermediate

Understanding Context Graphs

Learn how context graphs provide the three-layer architecture that enables trustworthy, explainable AI through systems of intelligence, records, and temporal feedback.

10 min read
Updated 5/8/2026
TrustGraph Team
#context-graphs#knowledge-graphs#context-engineering#llm-context#ai-optimization#explainable AI

A context graph is a knowledge graph purpose-built for AI agents. While traditional knowledge graphs store facts as triples (subject-predicate-object), context graphs add three critical layers that transform static knowledge into dynamic, trustworthy intelligence for AI systems.

Context graphs differ from traditional knowledge graphs in their design goals and capabilities. For a detailed comparison, see our guide on Context Graph vs. Knowledge Graph.

This article explains the three-layer architecture that makes context graphs essential for modern AI systems built with TrustGraph (open source and available on GitHub).

The Three-Layer Architecture

Context graphs operate across three interconnected layers, each serving a distinct purpose in creating reliable, explainable AI systems.

Layer 1: System of Intelligence

The System of Intelligence provides the grounding knowledge foundation that agents use to complete requests. This layer stores facts as RDF triples using ontology-driven structures (RDF, OWL, SKOS) that give the graph semantic meaning.

Let's use Fred the cat as an example. In RDF Turtle format, we can define Fred as an entity with properties:

@prefix ex: <http://example.org/animals/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

ex:fred rdf:type ex:Cat ;
        rdfs:label "Fred" ;
        ex:hasColor "stripey" ;
        ex:hasLegs 4 ;
        ex:hasOwner ex:Mark .

ex:Cat rdf:type rdfs:Class ;
       rdfs:label "Cat" .

To load this knowledge into TrustGraph, save it as fred.ttl and use the CLI:

# Load Fred's data into the knowledge graph
tg-load-knowledge -i "fred-the-cat" -C default fred.ttl

For more details on RDF fundamentals, see our Knowledge Graph Basics guide.

The System of Intelligence enables semantic reasoning. Agents can traverse relationships, infer new knowledge from ontologies, and understand context beyond simple keyword matching. This grounding knowledge ensures agents have a reliable foundation for decision-making.

Layer 2: System of Records

The System of Records tracks how agents behave, how information is used, and how intelligence is added to the system. This layer provides the provenance, audit trails, and lineage tracking that make AI systems explainable and trustworthy.

When new information about Fred is observed, the System of Records captures not just the fact, but the metadata about where it came from, when it was observed, and who recorded it. In TrustGraph, this provenance information is stored in a named graph (urn:graph:source) linked to the system of intelligence context:

@prefix ex: <http://example.org/animals/> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

# Named graph for provenance (urn:graph:source)
GRAPH <urn:graph:source> {
  # The reified statement (treating the triple as an entity)
  ex:observation_001 rdf:type rdf:Statement ;
                     rdf:subject ex:fred ;
                     rdf:predicate ex:hasWeight ;
                     rdf:object "4.5"^^xsd:float ;
                     prov:wasDerivedFrom ex:vet_record_2026_05_08 ;
                     dcterms:created "2026-05-08T10:30:00Z"^^xsd:dateTime ;
                     prov:wasAttributedTo ex:dr_smith ;
                     ex:confidence 0.95 .
}

# The actual fact in the default graph
ex:fred ex:hasWeight "4.5"^^xsd:float .

To query provenance data in TrustGraph directly with the SPARQL query service, use tg-query-graph with the -g flag to specify the named graph and -C to specify the collection:

# Query provenance metadata from the source graph
tg-query-graph \
  -p "http://www.w3.org/ns/prov#wasDerivedFrom" \
  -g "urn:graph:source" \
  -C default

The System of Records tracks:

  • Agent behavior: Which agents accessed which knowledge, and when
  • Information lineage: The complete path from source documents through extraction to graph edges
  • Usage patterns: How often facts are queried, which relationships are traversed most frequently
  • Intelligence additions: When new knowledge enters the system and through which pipeline

This layer is essential for compliance, debugging agent behavior, and building trust in AI systems. For more on how TrustGraph implements this, see our Explainable AI guide.

Layer 3: Temporal Feedback Loop

The Temporal Feedback Loop continuously compares new interactions against the grounding System of Intelligence to make updates, score knowledge freshness, and prioritize future requests. This layer makes context graphs living, evolving systems rather than static databases.

When new information about Fred arrives, the system doesn't just append it—it evaluates freshness, detects conflicts, and updates confidence scores:

@prefix ex: <http://example.org/animals/> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

GRAPH <urn:graph:source> {
  # Original observation from May 8
  ex:observation_001 rdf:subject ex:fred ;
                     rdf:predicate ex:hasWeight ;
                     rdf:object "4.5"^^xsd:float ;
                     dcterms:created "2026-05-08T10:30:00Z"^^xsd:dateTime ;
                     ex:confidence 0.95 ;
                     ex:freshness 0.80 .  # Score decreased over time

  # New observation from May 15
  ex:observation_045 rdf:subject ex:fred ;
                     rdf:predicate ex:hasWeight ;
                     rdf:object "4.7"^^xsd:float ;
                     dcterms:created "2026-05-15T14:20:00Z"^^xsd:dateTime ;
                     ex:confidence 0.98 ;
                     ex:freshness 1.0 ;  # Latest data, highest freshness
                     prov:wasRevisionOf ex:observation_001 .
}

# The system updates the default graph with the latest value
ex:fred ex:hasWeight "4.7"^^xsd:float .

The Temporal Feedback Loop enables:

  • Automatic updates: When new information conflicts with existing knowledge, the system can flag contradictions or update facts based on confidence and recency
  • Freshness scoring: Each piece of knowledge receives a time-decay score, ensuring agents prioritize recent, relevant information
  • Query prioritization: Frequently accessed knowledge with low freshness scores triggers proactive updates
  • Continuous learning: The system learns from agent interactions which knowledge needs refreshing most urgently

You can view query-time traces that power the temporal feedback loop:

# View all query-time reasoning traces
tg-show-graph -g "urn:graph:retrieval" -C default

# List recent explainability sessions
tg-list-explain-traces -C default

Context Graphs in Practice

Complete Example: Fred the Cat

Let's walk through a complete scenario showing how all three layers work together when an agent answers the question: "How much does Fred weigh?"

Step 1: Agent Query (System of Intelligence)

The agent queries the context graph using TrustGraph's agent patterns. Here we'll use the react pattern, which provides reasoning and action capabilities:

# Ask the agent about Fred's weight
tg-invoke-agent \
  -q "How much does Fred weigh?" \
  -C default \
  -v

The -v flag shows the agent's thinking process, including which tools it uses and what knowledge it accesses.

Step 2: Provenance Tracking (System of Records)

Every query creates an explainability trace that captures which facts were used and where they came from:

@prefix ex: <http://example.org/animals/> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix tg: <http://trustgraph.ai/ns#> .
@prefix dcterms: <http://purl.org/dc/terms/> .

GRAPH <urn:graph:retrieval> {
  ex:query_789 rdf:type tg:Query ;
               tg:queryText "How much does Fred weigh?" ;
               tg:executedBy ex:agent_assistant_01 ;
               dcterms:created "2026-05-08T11:45:00Z"^^xsd:dateTime ;
               tg:used ex:observation_045 ;
               prov:wasDerivedFrom ex:vet_record_2026_05_15 ;
               tg:returnedAnswer "4.7 kg" .
}

View the full explainability trace:

# List all explainability sessions
tg-list-explain-traces -C default

# Show detailed trace for a specific query (using session ID from list)
tg-show-explain-trace \
  --show-provenance \
  -C default \
  "urn:trustgraph:question:a1b2c3..."

This creates an audit trail showing which facts the agent accessed and how the answer was derived. See the TrustGraph explainability CLI guide for the full query-time tracing workflow.

Step 3: Freshness Evaluation (Temporal Feedback Loop)

The system evaluates whether the returned knowledge is fresh enough. If freshness scores are low, the system flags the query for proactive updating.

Complete RDF Graph (All Three Layers)

@prefix ex: <http://example.org/animals/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix tg: <http://trustgraph.ai/ns#> .

# === DEFAULT GRAPH: System of Intelligence ===
ex:fred rdf:type ex:Cat ;
        rdfs:label "Fred" ;
        ex:hasColor "stripey" ;
        ex:hasLegs 4 ;
        ex:hasWeight "4.7"^^xsd:float ;
        ex:hasOwner ex:daniel .

# === NAMED GRAPH: System of Records ===
GRAPH <urn:graph:source> {
  ex:observation_045 rdf:type rdf:Statement ;
                     rdf:subject ex:fred ;
                     rdf:predicate ex:hasWeight ;
                     rdf:object "4.7"^^xsd:float ;
                     prov:wasDerivedFrom ex:vet_record_2026_05_15 ;
                     dcterms:created "2026-05-15T14:20:00Z"^^xsd:dateTime ;
                     prov:wasAttributedTo ex:dr_smith ;
                     ex:confidence 0.98 ;
                     ex:freshness 1.0 ;
                     prov:wasRevisionOf ex:observation_001 .
}

# === NAMED GRAPH: Temporal Feedback (Query Trace) ===
GRAPH <urn:graph:retrieval> {
  ex:query_789 rdf:type tg:Query ;
               tg:queryText "How much does Fred weigh?" ;
               tg:executedBy ex:agent_assistant_01 ;
               dcterms:created "2026-05-08T11:45:00Z"^^xsd:dateTime ;
               tg:used ex:observation_045 ;
               tg:returnedAnswer "4.7 kg" .
}

Agent Patterns with Context Graphs

TrustGraph provides multiple agent patterns that leverage context graphs for different use cases. There are currently 3 agentic patterns available: ReAct, Plan-then-Execute, and Supervisor. Here's how to invoke an agent:

# Use agent to answer questions about Fred
tg-invoke-agent \
  -q "What do we know about Fred the cat?" \
  -C default \
  -v

For more agent patterns, see the TrustGraph Agent Patterns documentation.

How Context Graphs Enable TrustGraph Features

Context graphs are the foundational architecture that powers TrustGraph's key capabilities:

Explainable AI

The System of Records creates complete audit trails from user questions through reasoning steps back to source documents. Every answer can be explained by tracing which knowledge was used and where it originated.

# View the provenance chain for any edge
tg-show-extraction-provenance \
  -C default \
  "urn:trustgraph:doc:fred-vet-records"

Learn more in our Explainable AI guide.

Agent Orchestration

The System of Intelligence provides grounding knowledge that prevents hallucinations. Agents query structured, semantically-rich context instead of relying solely on parametric knowledge, improving reliability and consistency.

Knowledge Freshness

The Temporal Feedback Loop ensures agents work with current information. Stale knowledge is automatically flagged, prioritizing updates for frequently-accessed facts that have aged.

Compliance and Governance

The System of Records tracks information lineage, agent behavior, and access patterns, enabling compliance with regulations like GDPR, HIPAA, and AI governance frameworks.

Getting Started with TrustGraph

Ready to build your own context graphs? Start with these resources.

Installation

TrustGraph uses Docker Compose for deployment. Follow the quick start process:

# Launch the configuration tool
npx @trustgraph/config

# Start TrustGraph services using Docker Compose
docker compose up -d

# Verify services are running
docker compose ps

For detailed deployment instructions, see the Docker Compose deployment guide.

Install CLI Tools

# Install the TrustGraph CLI
pip install trustgraph-cli

# Verify installation
tg-show-config

Basic Operations

# Load RDF triples into the knowledge graph
tg-load-knowledge -i "my-knowledge" -C default knowledge.ttl

# Query the graph for specific patterns
tg-query-graph \
  -s "http://example.org/animals/fred" \
  -C default

# Ask an agent a question
tg-invoke-agent \
  -q "What entities are in my knowledge graph?" \
  -C default

# View graph data
tg-show-graph --limit 100 -C default

# Export graph to Turtle format
tg-graph-to-turtle -C default > exported-graph.ttl

Learn More

Context graphs represent a fundamental shift in how we build AI systems—from opaque, static knowledge to transparent, evolving intelligence. By combining grounding knowledge, provenance tracking, and temporal awareness, context graphs enable AI agents that are reliable, explainable, and continuously improving.

Start building with TrustGraph on GitHub today.

Related Concepts