Causal Inference and Logic Trace Benchmark Scorer
Create an automated scoring script to evaluate agent reasoning over counterfactual logic problems and causal graphs.
Use this prompt to build a benchmarking tool that evaluates how well AI agents navigate complex causal DAGs, avoid spurious correlations, and execute counterfactual deduction.
Role: Staff Cognitive Systems Architect and Autonomous Agent Evaluator with deep expertise in Pearlian causal inference and formal logic.
Context
- Causal benchmark graph definitions: {{causal_graph_benchmark_set}}
- Agent execution trajectory logs: {{agent_execution_logs}}
- Counterfactual search depth parameter: {{counterfactual_depth_level}}
- Penalty coefficient for redundant reasoning loops: {{backtracking_penalty_factor}}
- Diagnostic export destination: {{scorer_output_directory}}
Task
Write a Python scoring script that analyzes agent execution logs from {{agent_execution_logs}}, evaluates the agent's causal graph traversal against {{causal_graph_benchmark_set}}, and calculates causal discovery and counterfactual reasoning efficiency scores.
Method
- Ingest causal directed acyclic graph (DAG) ground truth definitions from {{causal_graph_benchmark_set}} using NetworkX.
- Ingest agent action traces, tool calls, and deduction steps from {{agent_execution_logs}}.
- Map the agent's inferred causal links against true graph edges to identify true positives, false discovery, and inverted causal arrows.
- Trace counterfactual reasoning paths up to {{counterfactual_depth_level}} steps to evaluate intervention calculations (do-calculus consistency).
- Identify redundant reasoning loops, circular causal attributions, and unnecessary backtracking, applying {{backtracking_penalty_factor}}.
- Compute benchmark metrics: Structural Hamming Distance (SHD), Interventional Accuracy (IA), and Reasoning Efficiency Ratio (RER).
- Write consolidated benchmark reports and node-level error attribution data into {{scorer_output_directory}}.
Constraints
- The script MUST utilize deterministic graph matching algorithms rather than heuristic LLM-as-a-judge approximations.
- The script MUST NOT fail or crash when an agent log contains malformed JSON or interrupted execution traces.
- Output pure, executable Python script with no pseudo-code or missing method bodies.
- Include unit test fixtures directly within the script using the
unittestorpytestframework.
Output format
Provide the solution organized into four strict sections:
- Mathematical Formulation (Equations and criteria for SHD, Interventional Accuracy, and Efficiency scoring).
- Complete Python Scorer Script (Full script including graph parsers, log analyzers, and file writers).
- Sample DAG & Trace Fixture (A minimal working DAG JSON and sample agent reasoning log for testing).
- Verification & Validation Instructions (Commands to execute tests and interpret output files in {{scorer_output_directory}}).
Self-review
- Does the scoring script properly handle interventions at depth {{counterfactual_depth_level}}?
- Are backtracking and loop penalties scaled correctly using {{backtracking_penalty_factor}}?
- Are all outputs and logs properly directed to {{scorer_output_directory}}?
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.