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:

Causal Architecture Components:
• 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))$.
FRAME 01 · EXOGENOUS CONFOUNDER ENVIRONMENT (Z) Confounder Z Meeting Volume Spikes Quarter-End Deadlines Team Reorganization Spurious Coincidences CONFOUNDER Spurious Correlation Danger • Standard RAG confuses coincidence with cause • Leads agents to cite obsolete/random code • Backdoor Path Must Be Severed BACKDOOR (SEVERED) CONDITION ON Z FRAME 02 · INTERVENTIONAL CORE: P(Y | do(X)) Action X (Context) Grounded Source Files Interface Contracts Negative Constraints Verified AST Elements ACTION Causal Gate: P(Y|do(X)) do-Calculus Operator Cuts All Backdoor Edges Isolates Direct Causal Effect Zero Spurious Confounding VERIFIED OUTCOME FRAME 03 · DETERMINISTIC AGENT OUTCOME (Y) Outcome Y (Success) Zero LLM Hallucinations 100% CI Unit Test Pass Preserved Invariants Clean Task Completion OUTCOME Pearl Backdoor Proof • P(Y|do(X)) = Σ_z P(Y|X, z) P(z) • Unbiased estimation of true causal utility • Backdoor Path Remains Blocked Interventional Backdoor Criterion Enforced

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

Was this page helpful?

Powered By BetterContext