Implementing Context Graphs for Agent Decision Traces
AI Engineergo watch the original →
the gist
Context graphs improve agent reasoning by linking semantic knowledge with structural decision traces, allowing agents to query past precedents alongside current data.
Enhancing Agent Reasoning with Context Graphs
Standard RAG setups often fail to provide agents with the necessary reasoning history to make consistent decisions. A context graph addresses this by storing three distinct layers of memory: short-term conversation history, long-term entity relationships, and reasoning traces. By embedding these traces into a vector space, agents can perform hybrid searches that combine semantic similarity with structural similarity, allowing them to surface past decisions that share the same causal logic as the current query.
Rapid Scaffolding and Implementation
Developers can initialize a full-stack context graph application using the uvx create-context-graph command. This tool generates a boilerplate project including a backend, frontend, demo data, and an MCP server. The underlying neo4j-agent-memory package automates the ingestion of unstructured data through a multi-stage pipeline:
- Extraction: Uses a spaCy to GLiNER to LLM fallback pipeline to identify entities and relationships.
- Deduplication: Merges redundant entities to maintain a clean graph ontology.
- Integration: Supports major agent frameworks including Pydantic AI, LangGraph, Crew, and Google ADK.
The tool ships with 22 built-in domains, such as healthcare and financial services, but also supports custom domain definitions where the system generates an ontology schema based on user descriptions.