causal-inference
FreeRuns bundled scriptsNot checkedAdd causal reasoning to agent actions. Trigger on ANY high-level action with observable outcomes - emails, messages, calendar changes, file operations, API…
by sundial-org★ 676 GitHub starsAbout this skill
Causal Inference
A lightweight causal layer for predicting action outcomes, not by pattern-matching correlations, but by modeling interventions and counterfactuals.
Core Invariant
Every action must be representable as an explicit intervention on a causal model, with predicted effects + uncertainty + a falsifiable audit trail.
Plans must be causally valid, not just plausible.
When to Trigger
Trigger this skill on ANY high-level action, including but not limited to:
| Domain | Actions to Log |
|---|---|
| Communication | Send email, send message, reply, follow-up, notification, mention |
| Calendar | Create/move/cancel meeting, set reminder, RSVP |
| Tasks | Create/complete/defer task, set priority, assign |
| Files | Create/edit/share document, commit code, deploy |
| Social | Post, react, comment, share, DM |
| Purchases | Order, subscribe, cancel, refund |
| System | Config change, permission grant, integration setup |
Also trigger when:
- Reviewing outcomes — "Did that email get a reply?" → log outcome, update estimates
- Debugging failures — "Why didn't this work?" → trace causal graph
- Backfilling history — "Analyze my past emails/calendar" → parse logs, reconstruct actions
- Planning — "Should I send now or later?" → query causal model
Backfill: Bootstrap from Historical Data
Don't start from zero. Parse existing logs to reconstruct past actions + outcomes.
Email Backfill
# Extract sent emails with reply status
gog gmail list --sent --after 2024-01-01 --format json > /tmp/sent_emails.json
# For each sent email, check if reply exists
python3 scripts/backfill_email.py /tmp/sent_emails.json
Calendar Backfill
# Extract past events with attendance
gog calendar list --after 2024-01-01 --format json > /tmp/events.json
# Reconstruct: did meeting happen? was it moved? attendee count?
python3 scripts/backfill_calendar.py /tmp/events.json
Message Backfill (WhatsApp/Discord/Slack)
# Parse message history for send/reply patterns
wacli search --after 2024-01-01 --from me --format json > /tmp/wa_sent.json
python3 scripts/backfill_messages.py /tmp/wa_sent.json
Generic Backfill Pattern
# For any historical data source:
for record in historical_data:
action_event = {
"action": infer_action_type(record),
"context": extract_context(record),
"time": record["timestamp"],
"pre_state": reconstruct_pre_state(record),
"post_state": extract_post_state(record),
"outcome": determine_outcome(record),
"backfilled": True # Mark as reconstructed
}
append_to_log(action_event)
Architecture
A. Action Log (required)
Every executed action emits a structured event:
{
"action": "send_followup",
"domain": "email",
"context": {"recipient_type": "warm_lead", "prior_touches": 2},
"time": "2025-01-26T10:00:00Z",
"pre_state": {"days_since_last_contact": 7},
"post_state": {"reply_received": true, "reply_delay_hours": 4},
"outcome": "positive_reply",
"outcome_observed_at": "2025-01-26T14:00:00Z",
"backfilled": false
}
Store in memory/causal/action_log.jsonl.
B. Causal Graphs (per domain)
Start with 10-30 observable variables per domain.
Email domain:
send_time → reply_prob
subject_style → open_rate
recipient_type → reply_prob
followup_count → reply_prob (diminishing)
time_since_last → reply_prob
Calendar domain:
meeting_time → attendance_rate
attendee_count → slip_risk
conflict_degree → reschedule_prob
buffer_time → focus_quality
Messaging domain:
response_delay → conversation_continuation
message_length → response_length
time_of_day → response_prob
platform → response_delay
Task domain:
due_date_proximity → completion_prob
priority_level → completion_speed
task_size → deferral_risk
context_switches → error_rate
Store graph definitions in memory/causal/graphs/.
C. Estimation
For each "knob" (intervention variable), estimate treatment effects:
# Pseudo: effect of morning vs evening sends
effect = mean(reply_prob | send_time=morning) - mean(reply_prob | send_time=evening)
uncertainty = std_error(effect)
Use simple regression or propensity matching first. Graduate to do-calculus when graphs are explicit and identification is needed.
D. Decision Policy
Before executing actions:
- Identify intervention variable(s)
- Query causal model for expected outcome distribution
- Compute expected utility + uncertainty bounds
- If uncertainty > threshold OR expected harm > threshold → refuse or escalate to user
- Log prediction for later validation
Workflow
On Every Action
BEFORE executing:
1. Log pre_state
2. If enough historical data: query model for expected outcome
3. If high uncertainty or risk: confirm with user
AFTER executing:
1. Log action + context + time
2. Set reminder
Install causal-inference in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
FAQ
What does the causal-inference skill do?
Add causal reasoning to agent actions. Trigger on ANY high-level action with observable outcomes - emails, messages, calendar changes, file operations, API calls, notifications, reminders, purchases, deployments. Use for planning interventions, debugging failures, predicting outcomes, backfilling historical data for analysis, or answering "what happens if I do X?" Also trigger when reviewing past actions to understand what worked/failed and why.
How do I install the causal-inference skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the causal-inference skill run scripts?
Yes, this skill bundles executable scripts. Review the source before installing.
Related skills
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
by Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
by Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
by Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
by Anthropic