Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
dagYesCanonical DAG object.
languageYes
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden. It discloses that the tool returns a dagstudio_url, sanitizes identifiers via an identifier_map (though not in schema), and adheres to paper claims. This goes beyond basic behavior but leaves details like error handling unspecified.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with its main purpose but includes a lengthy second paragraph about paper fidelity that, while relevant, could be more concise. The identifier_map reference adds verbosity without clear payoff.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool has two parameters and no output schema, so the description needs to explain return values. It mentions dagstudio_url but does not specify the overall output structure (e.g., whether code and URL are returned together). The identifier_map ambiguity also leaves gaps in understanding how to use the tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema already provides a description for 'dag' and an enum for 'language', but the description adds little clarity. It introduces an 'identifier_map' that is not part of the input schema, potentially confusing agents about tool usage. With 50% schema coverage, the description does not compensate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Emit idiomatic Python (networkx.DiGraph) or R (dagitty DSL) source representing the DAG.' It uses a specific verb and resource, distinguishing it from siblings like parse_dagitty or analyze_dag.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear usage context ('Useful for handing the DAG to a downstream analysis pipeline') and includes a caution about preserving the paper's structural assumptions. However, it does not explicitly mention alternatives or when not to use the tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Black-Swan-Causal-Labs/dagstudio-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server