What is BetterContext?
API Guide
Quickstart
Comparison
Agents, skills & MCP
How it works?
Experience Engine
Focus Mode
Memory Graph
Files & Folders
Token Usage
Overview
API keys
Invite team member
Tools connection
Usage & Analytics
Ingestion
General
Benchmarking
Billing and Invoice
Security & Compliance
Use cases
From other providers
Upgrade BetterContext
Concepts Copy
How it Works?
A technical deep dive into BetterContext's end-to-end architecture—from continuous ingestion to causal graph synthesis and closed-loop prompt optimization.
BetterContext acts as a high-performance cognitive intermediary between your organization's tools and your autonomous AI agents. Rather than dumping raw text into stateless prompt windows, BetterContext executes a 5-stage contextual pipeline.
Stage 1: Multi-Modal Ingestion & AST Parsing
When files, tickets, or pull requests are updated, BetterContext ingests them incrementally:
- Codebases: Tree-sitter parsers extract Abstract Syntax Trees (ASTs), class hierarchies, function signatures, and cross-file import graphs.
- Documentation: Markdown, OpenAPI specs, and PDFs are segmented along semantic headings, retaining metadata and author lineage.
- Workplace Activity: Slack discussions, PR reviews, and Linear tickets are captured as chronological event streams.
Stage 2: Causal Knowledge Graph Construction
Extracted entities are not stored as isolated embedding vectors; they are linked into a structured Directed Acyclic Graph (DAG):
• Nodes represent code modules, architectural concepts, team owners, and operational policies.
• Edges represent causal dependencies (e.g.
depends_on, regulates, authored_by, deprecates).• Confidence Decay: Every edge possesses a temporal half-life ($e^{-\lambda t}$). Undocumented or stale modules naturally decay in relevance over time.
Stage 3: Synergistic Context Packing
Standard top-$K$ vector retrieval creates severe redundancy (e.g., retrieving 5 near-identical paragraphs). BetterContext employs Submodular Information Maximization:
The selection algorithm evaluates candidate context nodes to maximize information synergy while penalizing mutual redundancy. An agent receiving 2,000 tokens gets diverse, orthogonal, and complementary context covering implementation details, security rules, and testing standards.
Stage 4: Prompt Injection & Sandbox Execution
Synthesized context is compiled into an optimized prompt harness and injected directly into the agent runtime via REST or MCP. Granular Access Control Lists (ACLs) verify that the calling agent has authorization to view every cited node.
Stage 5: Closed-Loop Telemetry & Experience Capture
When the agent completes its task, BetterContext tracks the real-world outcome:
- Did the pull request pass CI unit tests?
- Did the human developer accept or rewrite the agent's suggestion?
- Did the production deployment succeed?
Successful interventions strengthen causal edge weights, while rejected attempts trigger de-biasing, creating an organization brain that gets smarter with every single prompt.
Next Steps
Powered By BetterContext