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.

FRAME 01 · MULTI-MODAL INGESTION & CAUSAL KNOWLEDGE GRAPH 01 · Ingestion Tree-sitter AST Syntax OpenAPI & Markdown PR Reviews & Slack Chronological Streams INGEST 02 · Causal Graph Multi-Relational DAG Code & Policy Ontology Temporal Half-Life Decay w(t) = w0 · 2^(-Δt/t_half) LINKED DE-CONFOUND FRAME 02 · CAUSAL GATE & SUBMODULAR PROMPT INJECTION 03 · Context Packing Submodular Maximization Zero Vector Redundancy Orthogonal Diversity <2k Optimal Token Floor OPTIMAL 04 · Prompt Inject Universal MCP Hook Claude Code & Cursor CLI Granular Node ACLs Deterministic Prompts INJECTED EXECUTE FRAME 03 · CLOSED-LOOP TELEMETRY & CAUSAL INVARIANT TUNING 05 · Closed-Loop Real-World Outcome Track CI Unit Test Results Senior Dev PR Feedback Weight Update (Δw) FEEDBACK Continuous Feedback Synthesis • Reinforces high-utility patterns • Penalizes & decays hallucinated context • Sub-300ms Autonomous Habit Tuning Closed-Loop Recall: Δw = η · (1 - y) Habit Tuning

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):

Node & Edge Ontology:
• 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

Was this page helpful?

Powered By BetterContext