This prompt is for platform engineers and AI infrastructure teams orchestrating complex agent workflows where multiple tools must be invoked, and the order of execution is non-trivial. The core job-to-be-done is to transform a user objective, a set of available tool definitions, and known data dependencies into a machine-readable, directed acyclic graph (DAG) of tool calls. Use this prompt when you need an explicit execution plan that defines dependency edges, a topological ordering, and groups of calls that can safely run in parallel. The ideal user is someone building an agent harness or execution engine who needs a reliable planning step before any tool is invoked, not someone building a simple, single-step chatbot.
Prompt
Dependency Graph Construction Prompt for Agent Workflows

When to Use This Prompt
Determine if your agent workflow requires a pre-execution dependency graph before invoking tools.
This prompt is a planning-only step. It does not execute tools, manage runtime state, handle errors from tool calls, or make decisions based on the results of a tool's execution. It assumes you have already defined your tool schemas, including their input and output signatures, and can provide them as structured input. You should not use this prompt when the execution order is already statically known, when there is only a single tool call, or when the dependencies are so simple that a topological sort is over-engineering. It is also inappropriate for workflows where the next tool depends on the dynamic content of a previous tool's output, rather than just its schema-defined fields; in that case, a sequential chaining prompt with intermediate results is a better fit.
Before using this prompt, ensure you have a clear, structured representation of each tool: its name, a description of its function, its required and optional input parameters with types, and its output schema. The prompt's effectiveness depends on the quality of these tool definitions. After generating the DAG, you must validate it programmatically: check for cycles, confirm that all declared input dependencies are produced by a preceding tool, and verify that parallel execution groups do not contain conflicting write operations on shared resources. For high-risk workflows, such as those mutating production infrastructure or financial data, the generated plan should be treated as a draft and reviewed by a human operator before execution. The next step is to feed this validated DAG into your execution engine, which will handle invocation, retries, and error propagation according to the plan's constraints.
Use Case Fit
Where the Dependency Graph Construction Prompt delivers value and where it introduces unnecessary complexity or risk.
Good Fit: Multi-Step Agent Orchestration
Use when: Your agent must execute 5+ tools with non-trivial dependencies. The prompt excels at producing a valid DAG, topological ordering, and parallel execution groups from a flat list of tool capabilities. Guardrail: Always validate the output DAG for cycles before execution, even if the prompt claims none exist.
Bad Fit: Single Tool Call or Independent Calls
Avoid when: The task requires only one tool or multiple tools with no shared state. Introducing a dependency graph adds latency and token cost without benefit. Guardrail: Use a lightweight tool selection prompt first. Only invoke graph construction if the selection returns multiple tools with declared input-output relationships.
Required Input: Tool Registry with I/O Signatures
Risk: Without explicit input and output schemas for each tool, the model hallucinates dependencies. Guardrail: Provide a structured tool manifest including parameter names, types, and return fields. The prompt should refuse to construct a graph if any tool's output schema is missing.
Operational Risk: Stale Dependency Assumptions
Risk: The prompt generates a static graph. If a tool's output changes during execution, downstream steps may receive stale or incompatible data. Guardrail: Pair this prompt with a runtime validation step that checks actual tool outputs against expected schemas before feeding them to dependent tools.
Operational Risk: Graph Complexity Explosion
Risk: For large tool registries, the model may produce an overly complex graph with false dependencies, reducing parallelism and increasing latency. Guardrail: Set a maximum node count and require the prompt to justify each dependency edge. Reject graphs that serialize independent calls without a clear data dependency reason.
Bad Fit: Real-Time User-Facing Latency Budgets
Avoid when: The end-to-end response must complete in under 2 seconds. Graph construction adds a non-trivial model inference step. Guardrail: Pre-compute and cache dependency graphs for common tool combinations. Use this prompt offline or at plan time, not in the hot path of a synchronous user request.
Copy-Ready Prompt Template
A reusable prompt that constructs a directed acyclic graph (DAG) of tool calls with explicit dependency edges, topological ordering, and parallel execution groups.
This prompt template is designed to be dropped into an agent orchestration layer. It instructs the model to analyze a set of available tool signatures and a user's high-level objective, then output a structured execution plan. The plan is not just a list of calls; it's a dependency graph that your executor can use to maximize parallelism while respecting data flow. The output includes explicit depends_on edges, a valid topological sort, and labeled parallel execution groups, which are essential for preventing race conditions and ensuring that downstream tools receive the correct, fully-resolved inputs from their upstream dependencies.
textYou are an agent execution planner. Your task is to construct a dependency graph for a set of tool calls required to fulfill a user objective. ## Available Tools [TOOLS] ## User Objective [OBJECTIVE] ## Constraints - Identify all tool calls needed to achieve the objective. - For each tool call, specify its required arguments. Use the output of a previous call as an argument by referencing its `call_id`. - Declare explicit dependencies using a `depends_on` field containing a list of `call_id`s. A call can only depend on calls that produce its required inputs. - The final graph must be a directed acyclic graph (DAG). Cyclic dependencies are invalid. - Group calls into parallel execution groups. Calls within the same group have no dependencies on each other and can run concurrently. - Calls in later groups depend on at least one call from a prior group. - If the objective cannot be fulfilled with the available tools, output an empty plan with a `feasibility` field set to `false` and a `reason`. - If the objective is ambiguous, output a `clarification_needed` field with specific questions before constructing a plan. ## Output Schema Respond with a single JSON object conforming to this structure: { "plan": { "feasibility": boolean, "clarification_needed": ["string"], "execution_groups": [ { "group_id": "string", "calls": [ { "call_id": "string", "tool_name": "string", "arguments": {}, "depends_on": ["call_id"], "reasoning": "string" } ] } ] } } ## Validation Rules (Self-Check Before Output) 1. Every `call_id` in a `depends_on` list must exist in a prior execution group. 2. No cycles: trace all `depends_on` paths; no call can ultimately depend on itself. 3. All required arguments for a tool must be provided, either as static values or as a reference to a prior call's output. 4. Parallel groups must be maximized: if two calls have no direct or transitive dependency, they should be in the same group. ## Examples [EXAMPLES] ## Risk Level [RISK_LEVEL]
To adapt this template, start by populating the [TOOLS] placeholder with a JSON array of your tool schemas, including names, descriptions, and parameter types. The [OBJECTIVE] is the user's natural language request. The [EXAMPLES] section is critical for teaching the model the expected output format and edge-case handling; include at least one example of a simple linear chain, one of a complex fork-join, and one where the objective is infeasible. The [RISK_LEVEL] placeholder should be set to "high", "medium", or "low" to adjust the model's caution. For high-risk workflows (e.g., database writes, financial transactions), the prompt should be followed by a strict validation layer in your application code that checks for cycles and missing dependencies before any tool is executed.
Prompt Variables
Inputs required to construct a reliable dependency graph. Each placeholder must be populated before the prompt is sent. Missing or malformed inputs are the most common cause of incorrect parallelization and cycle detection failures.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[TOOL_REGISTRY] | Complete list of available tools with their input schemas, output schemas, and declared side effects | {"tools": [{"name": "search_kb", "input_schema": {"query": "string"}, "output_schema": {"results": "array"}, "side_effect": "read"}]} | Validate JSON schema compliance. Reject if any tool is missing input_schema or output_schema. Check for duplicate tool names. |
[USER_OBJECTIVE] | Natural language description of the user's goal that the tool calls must collectively achieve | Find all open incidents related to payment-service and summarize their root causes | Must be non-empty string. Check for ambiguous verbs like 'handle' or 'process' that obscure intent. Flag if objective spans multiple unrelated domains without explicit grouping. |
[CONTEXT_STATE] | Current conversation state, prior tool outputs, and any pre-existing data available before execution begins | {"prior_results": {"list_services": ["payment-service", "auth-service"]}, "user_role": "oncall_engineer"} | Validate JSON structure. Check that referenced tool outputs exist in prior execution history. Flag if context references tools not in [TOOL_REGISTRY]. |
[CONSTRAINTS] | Operational constraints including max parallelism, timeout budgets, rate limits, and required sequencing rules | {"max_parallel_calls": 5, "total_timeout_ms": 30000, "rate_limit_per_second": 10, "required_sequence": []} | Validate numeric fields are positive. Reject if max_parallel_calls exceeds system capacity. Check that required_sequence only references tools in [TOOL_REGISTRY]. |
[OUTPUT_SCHEMA] | Expected structure for the dependency graph output including nodes, edges, parallel groups, and topological order | {"nodes": [{"tool_name": "string", "id": "string"}], "edges": [{"from": "string", "to": "string", "dependency_type": "data|side_effect|resource"}], "parallel_groups": [["id1", "id2"]]} | Validate against JSON Schema. Reject if edges reference node IDs not present in nodes array. Check that parallel_groups are non-overlapping partitions. |
[FAILURE_MODE_PREFERENCES] | Instructions for how the graph should handle missing dependencies, ambiguous ordering, and tools with unknown side effects | {"on_missing_dependency": "sequential_fallback", "on_ambiguous_ordering": "ask_clarification", "on_unknown_side_effect": "treat_as_stateful_write"} | Validate enum values against allowed set: sequential_fallback, parallel_optimistic, ask_clarification, treat_as_stateful_write, treat_as_read. Reject unknown values. |
[CYCLE_DETECTION_RULES] | Thresholds and behavior for handling potential cycles in the dependency graph | {"max_cycle_depth": 3, "on_cycle_detected": "reject_and_report", "allow_self_referential_tools": false} | Validate max_cycle_depth is positive integer. Check on_cycle_detected is one of: reject_and_report, break_weakest_edge, ask_clarification. Reject if allow_self_referential_tools is true without explicit justification. |
Implementation Harness Notes
How to wire the dependency graph prompt into an agent orchestration engine with validation, retries, and execution safeguards.
The dependency graph prompt is not a standalone artifact—it is a planning step inside a larger agent execution loop. The typical integration pattern places this prompt after the agent has identified a set of candidate tool calls but before any tool executes. The prompt receives the proposed tool calls with their declared input requirements and output signatures, and it returns a directed acyclic graph (DAG) with topological ordering and parallel execution groups. The orchestration engine then consumes this DAG to schedule execution, respecting the dependency edges and parallelism constraints the prompt produces.
Validation is mandatory before execution. The output DAG must pass structural checks before any tool runs: (1) cycle detection—if the graph contains a cycle, reject the plan and re-prompt with the cycle explicitly called out; (2) missing dependency resolution—every input referenced by a tool must appear as an output of a preceding tool or be available from the initial context; (3) staleness propagation—if tool C depends on tool B's output, and tool B is in a parallel group with tool A that also writes to the same resource, flag the read-after-write hazard. Implement these checks as deterministic code in the harness, not as additional LLM calls. A failed validation should trigger a structured error payload back to the prompt with the specific violation, requesting a corrected graph. Limit re-prompt attempts to a configurable retry budget (typically 2–3) before escalating to a human operator or falling back to a safe sequential execution mode.
Model choice and tool integration. This prompt benefits from models with strong reasoning capabilities and structured output support. Use a model that supports JSON mode or function calling to enforce the DAG schema directly, reducing post-hoc parsing errors. The prompt's [TOOLS] placeholder should be populated from your tool registry's canonical schemas—never hand-write tool descriptions for this prompt; use the same schemas the model will see at execution time to avoid signature mismatches. Wire the prompt output into your execution engine's scheduler: parallel groups map to concurrent execution with a Promise.all or equivalent fan-out, while sequential edges map to await chains. Instrument each tool call with the DAG's node ID so trace logs can reconstruct whether a failure was a planning error (wrong dependency edge) or an execution error (tool returned unexpected shape). For high-stakes workflows, insert a human approval gate after graph generation but before execution, displaying the planned DAG as a visual or tabular summary for operator review.
Expected Output Contract
Defines the structure, types, and validation rules for the dependency graph output. Use this contract to parse, validate, and integrate the model's response into your orchestration engine.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
graph | object | Top-level object must contain nodes and edges arrays. Reject if missing or not an object. | |
graph.nodes[] | array of objects | Each node must have a unique id string. Reject if any id is duplicated or missing. | |
graph.nodes[].id | string | Must match the exact tool name from the provided tool registry. Reject on unknown tool names. | |
graph.nodes[].arguments | object | Must conform to the tool's input schema. Validate required fields and types per tool definition. | |
graph.edges[] | array of objects | Each edge must reference valid node ids in source and target. Reject dangling references. | |
graph.edges[].source | string | Must be a node id present in graph.nodes[].id. Reject if source node does not exist. | |
graph.edges[].target | string | Must be a node id present in graph.nodes[].id. Reject if target node does not exist. | |
graph.edges[].output_mapping | object | If present, keys must be target argument names and values must be valid JSONPath expressions into the source node's output schema. Reject on invalid paths. |
Common Failure Modes
Dependency graph construction fails in predictable ways. These are the most common production failure modes and how to guard against them before execution.
Undetected Circular Dependencies
What to watch: The model produces a dependency graph with cycles (Tool A depends on Tool B, which depends on Tool A), causing infinite loops or deadlock at execution time. This happens when tools have bidirectional data requirements or when the model confuses logical ordering with data dependency. Guardrail: Add a post-generation cycle detection pass using a topological sort validator. Reject any graph that fails the sort and feed the cycle details back into a repair prompt with explicit instructions to break the cycle by re-evaluating dependency edges.
Phantom Dependencies on Non-Existent Outputs
What to watch: The model declares that Tool C depends on a field from Tool B, but Tool B's output schema does not include that field. This creates a broken execution chain where Tool C receives a null or hallucinated input. Common when tool schemas are large or when the model infers relationships from tool names rather than actual input-output contracts. Guardrail: Validate every dependency edge against the declared output schemas of upstream tools. Reject edges where the required field is absent. Include tool output schemas inline in the prompt rather than relying on tool names alone.
False Parallelization of Write-After-Write Conflicts
What to watch: The model marks two tools as parallel-safe when both write to the same resource (e.g., updating the same database row, modifying the same file). Parallel execution produces a last-writer-wins race condition with unpredictable results. The model often misses these conflicts when tools operate on different resource identifiers that resolve to the same underlying entity. Guardrail: Include a resource-level conflict detection rule in the prompt: if two tools mutate the same resource type with overlapping identifiers, they must be sequenced. Add a post-generation check that flags any parallel group containing multiple write operations to the same resource.
Stale Data Propagation Across Execution Groups
What to watch: The model constructs a graph where a downstream tool reads data that an upstream tool in a different parallel group is simultaneously modifying. The read completes before the write, producing a result based on stale state. This is a read-after-write hazard that the model fails to detect because it treats parallel groups as fully independent. Guardrail: Add explicit read-after-write consistency rules to the prompt: if Tool X writes a resource and Tool Y reads the same resource, they cannot be in different parallel groups unless the read is explicitly tolerant of stale data. Include staleness tolerance annotations in the output schema.
Missing Dependency on Clarification or User Input
What to watch: The model builds a complete execution graph assuming all required inputs are available, but some tools require user-provided values that haven't been collected yet. The graph proceeds to execution with placeholder or null arguments, causing downstream failures. This happens when the model treats user input as already present rather than as a dependency that must be resolved. Guardrail: Include a pre-execution gate that checks whether all leaf-node tool inputs are satisfied by available context. If any required input is missing, insert a clarification step as a dependency before the tool that needs it. Flag unresolved inputs in the graph output.
Over-Sequencing from Spurious Dependency Inference
What to watch: The model serializes tools that could safely run in parallel because it infers dependencies from semantic relatedness rather than actual data flow. For example, it sequences two independent API calls because they both relate to the same entity, even though neither consumes the other's output. This increases latency and underutilizes parallel execution capacity. Guardrail: Add a parallel-safety justification requirement to the prompt: for any tool pair marked as sequential, the model must cite the specific output field from the upstream tool that the downstream tool consumes. If no such field exists, default to parallel. Validate justifications against schemas.
Evaluation Rubric
Use this rubric to test the quality of a generated dependency graph before integrating it into an agent execution engine. Each criterion targets a specific failure mode in production orchestration.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Cycle Detection | Output explicitly states 'no cycles detected' or returns an empty cycle list when the graph is acyclic | A circular dependency is present but the output reports a valid topological order or fails to flag the cycle | Inject a known cyclic dependency (A→B, B→C, C→A) and assert the output contains a cycle error |
Missing Dependency Handling | Every tool input that references another tool's output has a corresponding dependency edge declared | A tool call references [PREVIOUS_OUTPUT] or a specific field from another tool but no edge exists in the graph | Provide a tool set where Tool B requires Tool A's output but the dependency is not explicitly declared; check that the graph infers or flags it |
Topological Order Validity | Every tool appears in the execution order after all tools it depends on | A tool is listed before a tool it requires output from, violating the partial order | Parse the output execution order and verify for each edge (U→V) that U appears before V in the sequence |
Parallel Group Correctness | Tools with no direct or transitive dependencies are grouped into the same parallel execution batch | Two tools with a dependency edge are placed in the same parallel group, or independent tools are unnecessarily sequenced | Check each parallel group: for any pair (A, B) in the same group, assert no path exists from A to B or B to A in the graph |
Stale Data Propagation Flag | When a tool's input depends on a value that may be modified by a parallel write, the output includes a staleness warning | A read-after-write hazard exists but the graph marks the group as parallel-safe without annotation | Create a scenario where Tool A writes a resource and Tool B reads it; assert the output either sequences them or adds a staleness warning |
Dependency Edge Completeness | All declared dependencies are represented as edges; no phantom edges exist for tools that are actually independent | An edge is listed between two tools that have no input-output relationship, causing false sequencing | Compare the set of output edges against the declared input-output mappings; assert no edge exists without a matching field reference |
Output Schema Compliance | The output strictly matches the specified [OUTPUT_SCHEMA] with all required fields present and correctly typed | The output is missing required fields (e.g., 'execution_order', 'parallel_groups') or uses incorrect types | Validate the output against the [OUTPUT_SCHEMA] using a JSON Schema validator; assert no schema violations |
Graceful Handling of Ambiguous Dependencies | When a dependency is underspecified, the output includes an 'assumptions' block or flags the ambiguity instead of guessing silently | An ambiguous dependency is resolved without documentation, producing a plausible but potentially incorrect ordering | Provide a tool set where Tool B needs 'user_id' but both Tool A and Tool C produce a 'user_id'; assert the output surfaces the ambiguity |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Add strict output schema validation using the [OUTPUT_SCHEMA] placeholder with required fields: dag.nodes, dag.edges, dag.parallel_groups, dag.topological_order. Include a validation_errors array in the output for the model to self-report issues.
Add retry logic: if validation fails, feed the error message back into the prompt with [PREVIOUS_OUTPUT] and [VALIDATION_ERRORS] placeholders. Include a max_retries constraint of 2.
Add logging: capture the raw prompt, model response, validation result, and final DAG in structured logs keyed by [REQUEST_ID].
Watch for
- Silent format drift where the model drops
parallel_groupson complex graphs - Stale data propagation when a tool's output is consumed by multiple downstream tools but one path is delayed
- Missing human review gates for graphs that include state-mutating tools

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us