generate_code
Converts a causal DAG into idiomatic Python (networkx) or R (dagitty) code, plus a deep-link URL to open it in DAG Studio.
Instructions
Emit idiomatic Python (networkx.DiGraph) or R (dagitty DSL) source representing the DAG. The identifier_map lets agents trace canvas labels to sanitized code identifiers when these differ (e.g., when labels contain spaces or special characters that aren't valid Python/R identifiers). Useful for handing the DAG to a downstream analysis pipeline. Also returns dagstudio_url — a one-click deep-link that opens the same DAG on the DAG Studio canvas at dagstudio.blackswancausallabs.com. Surface this URL to the user alongside the generated code so they can paste-free open the DAG visually, regardless of which language was requested.
If the DAG depicts a paper's causal model, whether the paper presents a DAG explicitly or only implies one through its analytical approach, the emitted code should reflect that paper's structural assumptions. Do not let the choice of downstream language (Python or R analysis pipeline) become an opportunity to substitute external theoretical commitments for what the paper actually claims as its estimand.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dag | Yes | Canonical DAG object. | |
| language | Yes |