AI INVESTIGATOR / 06 / MCP + API CONTRACTS / 2026

Investigator API: controlled causal investigation.

Engine-neutral MCP/API façade для investigation lifecycle, hypotheses, evidence, causal links, external analysis runs и routing. DoWhy, pgmpy, EconML и Qwen 30B остаются behind adapters/policy и не получают прямого права менять canonical verdicts.

Главное правило: любой causal conclusion должен быть воспроизводим через canonical IDs, evidence refs, scope, assumptions и analysis refs. Внешние engine IDs никогда не становятся canonical.

1. Roles & permissions

RoleReadCreate investigationModify hypothesesRun analysisClose investigation
Writerscoped readNONONONO
ResearcherYESrequest/start scopedappend evidence / suggestNO direct engineNO
Investigator serviceYESYESYES by policyYESpropose/close by policy
SkepticYESNOreview findingsNOreview only
Experimentscoped readNOreturns experiment evidenceown execution onlyNO
HumanYESYESYESYESYES
AdminYESmaintenancemaintenancemaintenancemaintenance
Запрещено: агентам выдавать прямые credentials к statistical/graph backends или canonical DB.

2. Public MCP/API surface

INVESTIGATION:
investigator.create
investigator.get
investigator.search
investigator.update_scope
investigator.start
investigator.pause
investigator.resume
investigator.close
investigator.reopen

HYPOTHESES:
investigator.add_hypothesis
investigator.update_hypothesis
investigator.list_hypotheses
investigator.link_alternative
investigator.set_causal_role

EVIDENCE:
investigator.add_evidence_ref
investigator.add_counterevidence_ref
investigator.attach_dossier_evidence
investigator.list_evidence

GRAPH:
investigator.add_causal_link
investigator.update_causal_link
investigator.get_graph
investigator.get_timeline

ANALYSIS:
investigator.run_causal_analysis
investigator.run_bayesian_analysis
investigator.get_analysis_run

ROUTING:
investigator.request_research
investigator.request_experiment
investigator.request_skeptic_review

OUTPUT:
investigator.get_verdict
investigator.export_context
investigator.export
investigator.import

3. Investigation lifecycle contracts

create

{
  "dossier_id": "dos_...",
  "question": "Why did behavior change after firmware 3.2?",
  "type": "VERSION_REGRESSION",

  "scope": {
    "product_id": "...",
    "firmware": "3.1..3.2",
    "environment": {...},
    "time_range": {...}
  },

  "seed_claim_refs": [...],
  "seed_event_refs": [...],
  "idempotency_key": "..."
}

Output

{
  "investigation_id": "inv_...",
  "status": "DRAFT",
  "revision": 1
}

Scope update

expected_revision required

scope widening after analysis:
→ marks affected analysis runs STALE_SCOPE
→ does not silently reuse them

4. Hypothesis operations

add_hypothesis

{
  "investigation_id": "...",
  "statement": "Firmware 3.2 introduced scheduler regression.",
  "role": "ROOT_CAUSE",
  "origin": "QWEN|HUMAN|RESEARCHER|RULE",
  "scope": {...},
  "idempotency_key": "..."
}

Status changes

investigator.update_hypothesis({
  "hypothesis_id": "...",
  "new_status": "WEAKENED",
  "reason": "Counterevidence E17 contradicts expected behavior.",
  "evidence_refs": ["ev_17"],
  "expected_revision": 4
})

Constraint

`SUPPORTED`, `WEAKENED` и `REJECTED` переходы требуют evidence/reason. Qwen proposal сам по себе не достаточен.

5. Evidence contracts

Attach evidence

{
  "hypothesis_id": "...",
  "evidence_ref": "dossier_ev_...",
  "direction": "SUPPORTS",
  "class": "VERSION_HISTORY",
  "scope": {...},
  "independence_group": "vendor_release_notes",
  "reliability": "HIGH",
  "notes": "..."
}

Counterevidence

Counterevidence использует тот же canonical evidence object, но direction = `WEAKENS`/`CONTRADICTS`. Это не отдельная менее важная коллекция.

Validation

evidence exists
scope compatible or caveat explicit
source/provenance resolvable
no duplicated independence inflation

6. Causal graph contracts

add_causal_link

{
  "investigation_id": "...",
  "from_ref": "factor_A",
  "relation": "CONTRIBUTES_TO",
  "to_ref": "outcome_Y",

  "mechanism": "...",
  "support_refs": [...],
  "counter_refs": [...],

  "scope": {...},
  "confidence_class": "MEDIUM",
  "origin": "INVESTIGATOR_POLICY"
}

Allowed relations

CAUSES
CONTRIBUTES_TO
TRIGGERS
ENABLES
MEDIATES
CONFOUNDS
CORRELATES_WITH
PRECEDES

Guard

`PRECEDES` или `CORRELATES_WITH` нельзя автоматически upgrade в `CAUSES` без отдельной evidence-backed mutation.

7. External analysis runs

run_causal_analysis

{
  "investigation_id": "...",
  "engine": "DOWHY",
  "analysis_type": "ROOT_CAUSE_ATTRIBUTION",
  "graph_revision": 8,
  "data_ref": "...",
  "target_ref": "...",
  "candidate_refs": [...],
  "assumptions": [...],
  "config": {...}
}

run_bayesian_analysis

{
  "investigation_id": "...",
  "engine": "PGMPY",
  "network_ref": "...",
  "observations": {...},
  "priors_ref": "...",
  "config": {...}
}

AnalysisRun

{
  "analysis_run_id": "iar_...",
  "engine": "dowhy",
  "engine_version": "...",
  "status": "COMPLETED",

  "input_hash": "...",
  "graph_revision": 8,
  "assumptions": [...],
  "random_seed": 42,

  "result_ref": "...",
  "warnings": [...],
  "reproducibility_ref": "..."
}

Critical boundary

AnalysisRun не меняет final verdict автоматически. Он создаёт `MODEL_RESULT` evidence signal.

8. Routing contracts

Researcher request

{
  "investigation_id": "...",
  "gap_id": "...",
  "question": "Find independent evidence whether scheduler changed in 3.2.",
  "required_evidence": ["release_notes","issue","commit"],
  "priority": "HIGH",
  "scope": {...}
}

Experiment request

{
  "investigation_id": "...",
  "hypothesis_refs": ["hyp_1","hyp_2"],
  "discriminating_question": "Does toggling scheduler mode reproduce the failure?",
  "constraints": {...},
  "expected_observations": {...}
}

Skeptic review

{
  "investigation_id": "...",
  "causal_claim_refs": [...],
  "verdict_ref": "...",
  "review_focus": [
    "causal_overstatement",
    "scope",
    "alternatives",
    "counterevidence"
  ]
}

9. State machines

Investigation

DRAFT
→ ACTIVE
→ WAITING_RESEARCH
→ ACTIVE
→ WAITING_EXPERIMENT
→ ACTIVE
→ REVIEW
→ CLOSED

ACTIVE/WAITING/REVIEW
→ PAUSED

CLOSED
→ REOPENED
→ ACTIVE

AnalysisRun

QUEUED
→ RUNNING
→ COMPLETED

or:
→ FAILED
→ CANCELLED

graph/scope changed:
COMPLETED → STALE_SCOPE
or STALE_GRAPH

10. Error contract

INVESTIGATION_NOT_FOUND
HYPOTHESIS_NOT_FOUND
EVIDENCE_NOT_FOUND
INVALID_SCOPE
SCOPE_MISMATCH
REVISION_CONFLICT
INVALID_STATE_TRANSITION
MISSING_PROVENANCE
INVALID_CAUSAL_RELATION
INSUFFICIENT_ANALYSIS_INPUT
ENGINE_UNAVAILABLE
ANALYSIS_FAILED
STALE_GRAPH
STALE_SCOPE
PRIOR_NOT_DECLARED
PERMISSION_DENIED
ARCHIVED_DOSSIER
IDEMPOTENCY_CONFLICT
ROUTING_FAILED

Error object

{
  "error": "STALE_GRAPH",
  "message": "Analysis run used graph revision 8; current revision is 10.",
  "retryable": true,
  "trace_id": "..."
}

11. Audit & reproducibility

Audit events

INVESTIGATION_CREATED
SCOPE_UPDATED
INVESTIGATION_STARTED
HYPOTHESIS_ADDED
HYPOTHESIS_STATUS_CHANGED
EVIDENCE_LINKED
CAUSAL_LINK_ADDED
ANALYSIS_STARTED
ANALYSIS_COMPLETED
ANALYSIS_MARKED_STALE
RESEARCH_REQUESTED
EXPERIMENT_REQUESTED
SKEPTIC_REVIEW_REQUESTED
VERDICT_CREATED
INVESTIGATION_CLOSED
INVESTIGATION_REOPENED

Every numerical analysis stores

engine + version
input hashes
graph revision
scope revision
assumptions
priors
config
random seed
result ref
warnings

12. Definition of API Contracts Done

[ ] canonical investigation IDs
[ ] lifecycle API
[ ] scope revisioning
[ ] hypothesis CRUD/status
[ ] support/counterevidence
[ ] causal link API
[ ] no automatic correlation→cause
[ ] DoWhy run contract
[ ] pgmpy run contract
[ ] analysis reproducibility
[ ] stale graph/scope handling
[ ] Researcher routing
[ ] Experiment routing
[ ] Skeptic routing
[ ] permissions
[ ] idempotency
[ ] optimistic concurrency
[ ] audit
[ ] vendor/model IDs external only
[ ] no direct permanent knowledge mutation
Следующий документ: `AI_investigator_7_evidence_graph_и_scoring.html` — canonical evidence graph, support/attack edges, independence, hypothesis scoring, prior sensitivity, causal-chain scoring и rule-based verdict resolver.