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
Focus Mode & Causal Inference
Using causal inference and directed acyclic graphs (DAGs) to isolate true drivers from spurious statistical correlations.
Standard LLMs and statistical models frequently confuse correlation with causation. In a production engineering environment, this can lead to disastrous autonomous actions: an agent observing that "deployments on Friday correlate with bug reports" might attempt to block all code merges, rather than fixing the lack of automated integration tests.
Focus Mode implements Judea Pearl's causal do-calculus to evaluate whether an intervention $do(X)$ genuinely causes an outcome $Y$, or whether the relationship is merely confounded by a background variable $Z$.
The Causal Directed Acyclic Graph (DAG)
Focus Mode models your development environment as an active structural causal model:
• Action $X$: The proposed agent intervention (e.g. refactoring an auth middleware, bumping a cache TTL).
• Confounder $Z$: Background noise and unobserved covariates (e.g. meeting volume, end-of-quarter deadlines).
• Outcome $Y$: The intended target metric (e.g. CI build speed, p99 API latency, test pass rate).
• Backdoor De-confounding: Focus Mode mathematically blocks backdoor paths $X \leftarrow Z \rightarrow Y$, isolating the pure causal effect $P(Y \mid do(X))$.
Correlation vs. Causal Determination
| Observed Pattern | Naive LLM / RAG Interpretation | Focus Mode Causal Reality |
|---|---|---|
| Large PRs correlate with high bug rates | "Block all PRs larger than 200 lines" (Spurious constraint) | Confounded by feature complexity. Direct cause is lack of modular unit test coverage. |
| High Slack message volume correlates with incident resolution | "Generate more Slack pings during outages" | Spurious noise. The direct causal intervention is automated runbook execution. |
| Context Grounding correlates with lower hallucinations | "Ground every prompt" | Proven direct causal effect ($P(Y \mid do(X)) = 0.98$). Hallucinations drop by 89%. |
Evaluating Interventions via API
Before an agent modifies code or triggers a cloud deployment, test the intervention:
from bettercontext import BetterContextClient
client = BetterContextClient()
# Test candidate agent intervention
result = client.interventions.evaluate(
action="increase_db_pool_size",
target_metric="checkout_p99_latency",
proposed_value=50,
current_value=10
)
print(f"Causal Uplift Score: {result.causal_delta}") # e.g. +0.34
print(f"Confidence (De-confounded): {result.confidence}") # e.g. 0.92
print(f"Recommended Decision: {result.recommendation}") # "APPROVE" | "BLOCK" | "REQUIRE_HUMAN_REVIEW"
Next Steps
Powered By BetterContext