counterfact-agent
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "counterfact-agent":https://skillpi.com/zh/skills/deepskill-3c166a14ea8f2ab6f29f56a5243bb3908bce94ae7a5f1576507501e06c2c746c。安装前核对上游来源和版本:https://skillhub.cn/skills/user_053d27d0/counterfact-agent。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
skillhub.cn
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
结合合成控制法与 LLM 叙事,提供双通道的政策分析能力。适用于需要同时利用对照性合成干预与语言模型叙事来评估或解构政策的场景。
介绍来源: third_party · user_053d27d0 · 1.0.0 参考来源
SkillPi 解读
- 输入和输出
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: counterfact-agent
description: >-
Counterfactual policy analysis combining quantitative Synthetic Control
Method (SCM) with qualitative LLM narrative reasoning. Dual-channel
analysis estimates the causal effect of an intervention, provides
mechanism-level explanations with confidence tags, and grades all
claims on an A/B/C/D evidence quality scale.
version: 1.0.0
tags:
- counterfactual
- causal-inference
- policy-analysis
- synthetic-control
- economics
- evidence
- research
trigger_phrases:
- "counterfactual analysis"
- "what if policy"
- "estimate policy effect"
- "synthetic control"
- "causal impact"
- "policy evaluation"
- "反事实分析"
- "政策效果评估"Overview
CounterfactAgent performs dual-channel counterfactual policy analysis. The quantitative channel implements the Synthetic Control Method (Abadie, Diamond & Hainmueller, 2010) using pure numpy/scipy -- donor pool construction, constrained weight optimization, counterfactual prediction, and placebo testing. The qualitative channel leverages an LLM to generate structured narrative reasoning about causal mechanisms, with explicit confidence tags (HIGH_CONF, MED_CONF, LOW_CONF, SPECULATIVE). All claims are graded on a 4-tier A/B/C/D evidence quality scale. The result is a unified analysis that is mathematically grounded where data allows and narratively rich where it does not.
Capability Boundaries
What this tool does:
- Frame a counterfactual policy event with an intervention time, treated unit, and outcome variable.
- Build a donor pool from comparable units with pre-intervention covariates and outcome series.
- Fit a synthetic control using
scipy.optimize.minimizewith non-negativity and sum-to-one constraints on donor weights. - Estimate the treatment effect as the gap between observed and synthetic outcomes over time.
- Run placebo tests by iterating the synthetic control over each donor unit.
- Generate structured LLM narrative explanations organized by mechanism type:
- Direct effects
- Spillover effects
- Equilibrium adjustments
- Heterogeneous responses
- Tag every narrative claim with one of 4 confidence levels:
- HIGH_CONF: Multiple independent sources corroborate; quantitative evidence available.
- MED_CONF: Supported by theory or partial evidence; reasonable inference.
- LOW_CONF: Plausible but speculative; limited direct evidence.
- SPECULATIVE: Theoretically possible; no direct evidence available.
- Grade all evidence claims on the A/B/C/D scale:
- Grade A: Well-verified, multiple strong sources, rigorous method.
- Grade B: Reasonable evidence, some corroboration, standard method.
- Grade C: Weak evidence, single source, unverified method.
- Grade D: Unsupported, speculative, or contradictory evidence.
- Produce a comprehensive
AnalysisResultwith both quantitative estimates and qualitative narratives, assembled by theReporter.
What this tool does NOT do:
- It is NOT a general-purpose causal inference library (no DiD, RDD, IV, etc.).
- It does NOT automatically fetch or construct donor pools from external data sources -- the user must provide or construct the donor pool.
- It does NOT run formal statistical hypothesis tests beyond placebo testing.
- It is NOT designed for real-time or streaming analysis.
- The LLM narrative is probabilistic and should be treated as a reasoning aid, not a substitute for domain expertise.
Trigger Conditions
Use this skill when the user:
- Wants to estimate the causal effect of a policy, event, or intervention.
- Asks "what would have happened if X had not occurred?"
- Needs a counterfactual analysis combining quantitative and qualitative approaches.
- Mentions phrases like "counterfactual analysis", "synthetic control", "causal impact", "policy evaluation", "what if", "反事实分析", or "政策效果评估".
- Provides time-series data and an intervention point for analysis.
Usage
Python API
from counterfact_agent import CounterfactEngine
engine = CounterfactEngine(model="qwen2.5:7b")
result = engine.analyze(
event_name="California Tobacco Control Program (1988)",
treated_unit=california_data,
donor_pool=other_states_data,
intervention_time=1988,
)
print(f"Estimated effect: {result.effect_estimate}")
print(f"Narrative confidence: {result.narrative.confidence}")
print(f"Evidence grades: {result.evidence.grades}")
Dual-Channel Architecture
-
Quantitative Channel (
synthetic_control.py):from counterfact_agent.synthetic_control import ( SyntheticControl, DonorUnit, SyntheticControlResult ) sc = SyntheticControl() result: SyntheticControlResult = sc.fit(treated, donor_pool) # result contains: weights, counterfactual series, gaps, placebo results -
Qualitative Channel (
narrative.py):from counterfact_agent.narrative import NarrativeGenerator, MechanismNarrative generator = NarrativeGenerator(llm_client, model_name) narrative: MechanismNarrative = generator.generate(event_context, sc_result) # narrative contains mechanism-level explanations with confidence tags -
Evidence Grading (
evidence.py):from counterfact_agent.evidence import EvidenceGrader, EvidenceGrade grader = EvidenceGrader(llm_client) report = grader.grade(narrative_claims) # report assigns A/B/C/D grades to each claim
Dependencies
- Quantitative: numpy, scipy, pandas
- LLM: OpenAI-compatible endpoint (default: Ollama)
- The Synthetic Control implementation is pure Python/numpy/scipy -- no LLM required for the math.
Output Example
An AnalysisResult contains:
- Event Frame: Intervention time, treated unit, outcome variable, event description.
- Synthetic Control Weights: Which donor units contributed to the synthetic control and their weights.
- Treatment Effect Estimate: Gap between observed and synthetic counterfactual trajectories.
- Placebo Test Results: Treatment effect compared against placebo effects from each donor.
- Mechanism Narratives: Structured explanations with:
- Mechanism type (direct, spillover, equilibrium, heterogeneous)
- Narrative text
- Confidence tag (HIGH_CONF / MED_CONF / LOW_CONF / SPECULATIVE)
- Supporting evidence citations
- Evidence Grades: Each narrative claim assessed as A, B, C, or D quality.
- Confidence Discussion: Aggregate confidence assessment with limitations and caveats.
FAQ
Q: How much data do I need for the Synthetic Control? A: The method requires a treated unit with pre- and post-intervention outcome data, plus a donor pool of comparable units. More pre-intervention periods and more relevant donor units improve the fit. The implementation handles missing data gracefully but will warn you.
Q: What happens when quantitative data is insufficient? A: When the donor pool is sparse or pre-intervention periods are too few, the engine falls back to qualitative narrative reasoning. The confidence tags make this transparent -- you will see MED_CONF, LOW_CONF, or SPECULATIVE instead of HIGH_CONF.
Q: Is the LLM narrative scientifically valid? A: The narrative is an LLM's structured reasoning about causal mechanisms. It is explicitly tagged with confidence levels and should be treated as a reasoning aid, not as definitive causal proof. Cross-reference with domain expertise.
Q: Can I use this for non-economic counterfactuals? A: Yes. The quantitative channel is domain-agnostic (it only needs time-series data). The qualitative channel can reason about any domain. The evidence grading system is also domain-independent.
Q: How is this different from just asking an LLM "what if"? A: Unlike pure LLM reasoning, CounterfactAgent runs actual mathematical synthetic control where data is available. The LLM is used to explain mechanisms behind the estimated gap, not to hallucinate the gap itself.
当前收录版本
1.0.0
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 高价值/高频刚需。直接解决用户明确的核心任务痛点,或显著提升日常高频场景的效率(如自动化任务、信息聚合、内容生成等)。
亮点
- 触发词精准完整,覆盖多种变体,边界清晰。
亮点
- Phase/步骤清晰,有出口条件,含端到端示例,frontmatter完整,单文件≤500行。
亮点
- 工具来源明确,参数正确,覆盖主要异常,不可逆操作有确认机制。
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。