This prompt is for agent developers and AI cost engineers who need to order a set of required tool calls to minimize total execution cost while satisfying all data dependencies. Use it when your agent must call multiple tools with different per-call costs, and the order of execution affects the total bill. The core job-to-be-done is producing a sequenced call plan with cost rationale—not deciding which tools to call, not allocating a budget, and not decomposing a task into new subtasks. The ideal user already knows the exact set of tools required and needs the cheapest valid execution order.
Prompt
Cost-Optimized Tool Sequencing Prompt

When to Use This Prompt
Determine whether cost-optimized tool sequencing is the right solution for your agent's execution planning.
This is not a tool selection prompt. It assumes the set of required tools is already decided. If you need to decide which tools to call under a budget constraint, use the Cost-Aware Tool Selection System Prompt instead. If you need to decompose a task and assign per-step budgets, use the Budget-Conscious Agent Planning Prompt. This prompt also does not enforce spend caps, handle rate limits, or trigger human approval—those concerns belong to sibling prompts like Agent Spend Cap Enforcement Prompt and Budget-Aware Human Approval Trigger Prompt. The prompt produces a plan, not an execution trace; wiring it into a live agent requires additional harness logic for dependency validation, cost tracking, and mid-plan correction when tool outputs change the dependency graph.
Before using this prompt, confirm that you have: (1) a complete list of required tool calls with their per-call costs, (2) a dependency map showing which calls depend on outputs from which other calls, and (3) a clear understanding that the model will reason about ordering but will not execute the calls itself. The prompt works best when costs vary significantly across tools and when dependency chains create multiple valid orderings. If all tools cost the same or the dependency graph is strictly linear, the sequencing problem is trivial and this prompt adds unnecessary latency and token cost. Start by testing against a naive ordering baseline—such as topological sort without cost awareness—to measure whether the optimized plan actually reduces spend in your production traces.
Use Case Fit
Where this prompt works, where it fails, and what you must provide before using it in production.
Good Fit: Multi-Step Tool Pipelines
Use when: your agent must call 3+ tools with known cost-per-call and dependency constraints (e.g., search → fetch → summarize). Guardrail: provide a complete tool manifest with per-call cost estimates and required input/output schemas.
Bad Fit: Single-Tool or Zero-Shot Tasks
Avoid when: the agent only calls one tool or the task requires no tools at all. The sequencing overhead adds latency and token cost with no benefit. Guardrail: route single-tool tasks to a lightweight function-calling prompt instead.
Required Input: Tool Cost Manifest
What to watch: the prompt cannot estimate costs without explicit per-tool cost metadata. Missing or stale cost data produces sequences that look optimal but waste money. Guardrail: validate the cost manifest against your billing dashboard before every run; cache it with a TTL.
Required Input: Dependency Graph
What to watch: the model may reorder calls that have hidden data dependencies, producing broken pipelines. Guardrail: provide an explicit dependency map (tool B requires output field X from tool A) and validate the plan against it before execution.
Operational Risk: Cost Drift
What to watch: actual tool costs change over time due to API pricing updates, volume tiers, or dynamic rate cards. A sequence optimized against stale costs becomes suboptimal. Guardrail: log actual per-call costs at runtime and trigger a re-plan if cumulative spend exceeds the plan by more than 15%.
Operational Risk: Dependency Violation
What to watch: the model may produce a sequence that looks valid but violates a dependency because it misunderstands field-level requirements. Guardrail: run a deterministic validator that checks each tool's required inputs are satisfied by prior outputs before any call executes.
Copy-Ready Prompt Template
A reusable prompt that orders tool calls to minimize total cost while satisfying all declared dependencies.
The following prompt template is designed to be dropped into an agent planning or orchestration step. It accepts a list of available tools with their estimated costs and dependencies, then produces a sequenced call plan with a clear cost rationale. The template uses square-bracket placeholders so you can inject tool metadata, constraints, and output schema requirements directly from your application layer without modifying the core instruction.
textYou are an agent planner optimizing tool call sequences for minimum total cost. ## AVAILABLE TOOLS [TOOLS] ## CONSTRAINTS - You must satisfy all declared dependencies before invoking a dependent tool. - You may invoke each tool at most once unless explicitly marked as repeatable. - Total estimated cost must stay within the budget cap: [BUDGET_CAP]. - If the budget cap cannot be satisfied, return a partial plan with the highest-priority tools and flag the shortfall. ## OUTPUT SCHEMA Return a valid JSON object with this structure: { "plan": [ { "step": <integer>, "tool": "<tool_name>", "estimated_cost": <number>, "depends_on": ["<tool_name>", ...], "rationale": "<why this tool at this step>" } ], "total_estimated_cost": <number>, "budget_remaining": <number>, "unresolved_dependencies": ["<tool_name>", ...], "warnings": ["<string>", ...] } ## PRIORITY RULES 1. Resolve dependencies before invoking dependent tools. 2. Prefer lower-cost tools when multiple tools satisfy the same dependency. 3. If a tool's output is required by multiple downstream tools, invoke it once as early as possible. 4. Flag any tool whose estimated cost exceeds the remaining budget at the point it would be invoked. ## RISK LEVEL [RISK_LEVEL] ## EXAMPLES [EXAMPLES] Now produce the cost-optimized sequence for the tools above.
To adapt this template, replace [TOOLS] with a structured list of tool objects, each containing at minimum a name, estimated_cost, and depends_on array. The [BUDGET_CAP] should be a numeric value in your cost unit. Set [RISK_LEVEL] to low, medium, or high to adjust the conservatism of the plan—high-risk contexts should produce plans that leave larger budget buffers and include explicit abort conditions. The [EXAMPLES] placeholder should contain one or two worked examples showing correct sequencing with cost trade-offs, which dramatically improves output reliability. After copying the template, validate that your tool list includes all dependency names referenced in depends_on arrays to prevent the model from hallucinating missing tools.
Prompt Variables
Required inputs for the Cost-Optimized Tool Sequencing Prompt. Each placeholder must be populated before the prompt is assembled and sent to the model. Missing or malformed inputs are the most common cause of invalid dependency ordering and budget overrun.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[TASK_DESCRIPTION] | Natural-language description of the goal the agent must accomplish using available tools | Generate a quarterly sales report from CRM data and email it to the regional director | Must be non-empty. Check for vague verbs like 'handle' or 'process' that hide dependency requirements. |
[AVAILABLE_TOOLS] | JSON array of tool definitions, each containing name, description, estimated cost in USD, required inputs, and outputs produced | [{"name": "crm_query", "cost_estimate_usd": 0.02, "inputs": ["date_range"], "outputs": ["sales_records"]}] | Validate JSON schema. Each tool must have a non-null cost_estimate_usd field. Outputs array must not be empty if the tool produces data consumed by other tools. |
[TOOL_DEPENDENCIES] | Explicit mapping of which tool outputs are required as inputs by other tools | {"email_send": ["report_generate"], "report_generate": ["crm_query"]} | Must form a valid DAG with no cycles. Validate that every referenced tool exists in [AVAILABLE_TOOLS]. Missing dependencies cause silent ordering failures. |
[COST_BUDGET_USD] | Maximum total estimated cost the agent may incur across all tool calls in the sequence | 1.50 | Must be a positive float. Null allowed if no budget cap exists. If set, the generated sequence total must not exceed this value. Validate post-generation. |
[RATE_LIMIT_WINDOW_SECONDS] | Time window in seconds for per-tool rate limit enforcement, or null if no rate limits apply | 60 | Must be a positive integer or null. If non-null, the generated sequence must not schedule more calls to a rate-limited tool than its limit within this window. |
[PRIORITY_OVERRIDE_TOOLS] | List of tool names that must be called regardless of cost, for correctness-critical operations | ["audit_log_write"] | Array of strings or null. Each entry must match a tool name in [AVAILABLE_TOOLS]. These tools bypass cost ranking but still count against the budget. |
[NAIVE_BASELINE_COST] | Total cost of a naive sequential execution of all tools in declaration order, used for comparison in the output rationale | 2.34 | Must be a positive float. Used to calculate cost savings in the output. If null, the prompt should still produce a sequence but skip baseline comparison language. |
Implementation Harness Notes
How to wire the Cost-Optimized Tool Sequencing Prompt into an application with validation, retries, and cost guardrails.
The Cost-Optimized Tool Sequencing Prompt is designed to be called before a multi-step agent execution loop begins. It takes a task description, a list of available tools with their estimated costs and dependencies, and returns an ordered plan. The application layer should treat this prompt as a planning step that runs once per task, not as a runtime decision-maker inside the execution loop. This separation keeps cost optimization logic out of the agent's step-by-step reasoning, where it can conflict with task completion goals.
To wire this into an application, first construct the input payload with three required components: the [TASK_DESCRIPTION], a [TOOL_CATALOG] array where each tool includes name, estimated_cost (in your chosen unit, such as USD or tokens), required_inputs, and produces_outputs fields, and a [CONSTRAINTS] block specifying the maximum total budget and any mandatory ordering rules. The model should return a JSON array of steps, each containing step_number, tool_name, estimated_cost, depends_on (an array of step numbers), and rationale. Validate this output before execution: check that all depends_on references resolve to earlier steps, that the sum of estimated_cost does not exceed the budget, and that every required input for a tool is produced by a prior step or provided in the initial context. If validation fails, retry once with the validation errors appended to the prompt as feedback. If it fails again, fall back to a naive dependency-respecting ordering and log the failure for review.
For production deployment, run this prompt on a fast, cost-efficient model such as GPT-4o-mini or Claude Haiku, since the planning step should be cheaper than the tool calls it optimizes. Log every plan alongside the actual execution trace, including real costs incurred, so you can compare planned versus actual spend and detect systematic underestimation. Set a hard circuit breaker: if the agent's cumulative tool spend exceeds 120% of the planned budget, pause execution and escalate for human review. This prompt is not a substitute for runtime rate-limit handling or tool error recovery—those belong in separate prompts that operate during execution. The sequencing prompt's job is to produce a cost-aware order before the first tool call fires.
Expected Output Contract
Fields, types, and validation rules for the cost-optimized tool sequencing plan. Use this contract to validate the agent's output before executing the tool call sequence.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
sequence_plan | Array of step objects | Must be a non-empty array. Each element must conform to the step object schema. | |
sequence_plan[].step_id | String | Must be unique within the sequence. Use a predictable naming convention like 'step_1', 'step_2'. | |
sequence_plan[].tool_name | String | Must match an available tool name from the [TOOL_REGISTRY] exactly. Case-sensitive check required. | |
sequence_plan[].arguments | Object | Must be a valid JSON object. Required parameters for the tool must be present. No extraneous parameters allowed unless specified by the tool schema. | |
sequence_plan[].estimated_cost | Number | Must be a positive float. Must match the cost model defined in [COST_MODEL] for the specified tool and estimated input size. | |
sequence_plan[].depends_on | Array of step_id strings or null | If not null, every referenced step_id must exist earlier in the sequence. Self-references are invalid. Circular dependencies are invalid. | |
total_estimated_cost | Number | Must equal the sum of all sequence_plan[].estimated_cost values. Must be less than or equal to [BUDGET_CAP] if provided. | |
cost_rationale | String | Must be a non-empty string explaining the key cost-saving decisions. Must reference specific trade-offs (e.g., 'Used cached lookup instead of live API call for step 3'). |
Common Failure Modes
Cost-optimized tool sequencing fails in predictable ways. These are the most common production failure modes and the guardrails that catch them before they cost you.
Dependency Violation in Sequence
What to watch: The model orders a cheaper tool call before a more expensive one whose output it requires, causing a silent dependency break. The sequence looks valid but fails at runtime because the prerequisite data doesn't exist yet. Guardrail: Parse the output plan into a directed graph and validate that every tool's required inputs exist as outputs from a preceding step. Reject plans with cycles or missing dependencies before execution.
Cost Estimate Drift from Reality
What to watch: The model's per-call cost estimates are hallucinated or based on stale pricing, so the "optimized" sequence is actually more expensive than naive ordering. Guardrail: Never trust model-generated cost numbers. Inject actual cost metadata from your tool registry into the prompt context and validate the final plan's claimed total against an independent cost calculation.
Parallelism Over-Optimization
What to watch: The model parallelizes tool calls that appear independent but share a rate-limited API key or contended resource, triggering 429s or queue delays that wipe out any cost savings. Guardrail: Include rate limit context and concurrency constraints in the prompt. Post-process the plan to serialize calls that hit the same rate limit bucket, even if they appear logically independent.
Cheapest-First Bias Without Accuracy Check
What to watch: The model always orders the cheapest tool first, even when a slightly more expensive tool would narrow the search space enough to eliminate several downstream calls entirely. Guardrail: Require the prompt output to include a one-sentence rationale for each sequencing decision. Run a comparison eval against a baseline that always uses the most accurate tool first and flag plans where cost savings are below a threshold but accuracy drops measurably.
Missing Abort Conditions on Cost Escalation
What to watch: The plan assumes every step succeeds at the estimated cost, but a single tool returning more data than expected cascades into unbounded downstream spend with no early exit. Guardrail: Add a cumulative cost checkpoint after each step in the harness. If actual spend exceeds the plan's estimate by more than a configured threshold, pause execution and request re-planning or human approval before continuing.
Stale Tool Registry Causing Wrong Cost Ranking
What to watch: A tool's cost profile changed since the prompt was written, or a cheaper alternative was added to the registry but the prompt's context still reflects the old state. The model optimizes against phantom costs. Guardrail: Build the tool list and cost metadata dynamically at runtime from a live registry, never hardcode them in the prompt. Add a freshness check that compares the registry version used in planning against the current version before execution begins.
Evaluation Rubric
Use this rubric to test the Cost-Optimized Tool Sequencing Prompt before deploying it into an agent harness. Each criterion targets a specific failure mode observed in production tool-sequencing systems.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Dependency Ordering | All tool calls are ordered so that every call's required inputs are produced by a preceding call or provided in [AVAILABLE_INPUTS]. No call depends on a later call's output. | A tool call references an input that has not yet been produced. The sequence would fail at runtime due to missing arguments. | Parse the output plan into a directed graph. For each call, verify that every input key exists in either [AVAILABLE_INPUTS] or a prior call's [OUTPUT_SCHEMA]. Flag any forward reference. |
Cost Minimization vs. Naive Baseline | The total estimated cost of the sequenced plan is less than or equal to the cost of a naive left-to-right execution of the same tool set. If equal, the plan provides a documented reason. | The sequenced plan costs more than the naive ordering. No explanation is provided for the cost increase. | Compute the sum of [COST_PER_CALL] for the naive order. Compare to the sum of the plan's estimated costs. If plan cost > naive cost, check for a rationale in the output. |
Budget Constraint Adherence | The total estimated cost of the plan does not exceed [MAX_BUDGET]. If the budget is insufficient, the output explicitly states which calls were deferred or dropped and why. | The plan exceeds [MAX_BUDGET] without acknowledgment. The output silently includes calls that push the total over the cap. | Sum the estimated costs of all included calls. Assert total <= [MAX_BUDGET]. If total exceeds budget, assert that the output contains a budget-exhaustion explanation and a deferred-call list. |
Parallelization Identification | Independent tool calls that share no data dependencies are marked as parallelizable. The output includes a parallelization group ID or note. | Two calls with no mutual dependencies are sequenced serially without a stated reason. The plan misses an opportunity to reduce latency. | Build a dependency matrix from the output. Identify pairs of calls with no path between them. Assert that each such pair is annotated with a parallel group marker or a justification for serial execution. |
Cost Estimate Grounding | Every estimated cost in the plan is derived from [COST_PER_CALL] values provided in the input. No fabricated or assumed costs are used. | A cost estimate appears that does not match any value in [COST_PER_CALL]. The model invents a cost for a tool not in the input. | Extract all cost numbers from the output. For each, verify it matches a value in the [COST_PER_CALL] mapping. Flag any cost that cannot be traced to the input. |
Fallback Specification | When a tool has a defined [FALLBACK_TOOL], the plan includes a conditional branch: if the primary call fails or exceeds a cost threshold, the fallback is invoked. | A tool with a [FALLBACK_TOOL] is included without any conditional logic. The plan assumes the primary call always succeeds. | For each call in the plan, check if the tool has a [FALLBACK_TOOL] entry. Assert that the output includes a conditional or a note explaining why the fallback is not needed. |
Output Schema Validity | The output is valid JSON matching the [OUTPUT_SCHEMA]. All required fields are present. No extra fields are added. | The output is missing required fields, contains malformed JSON, or includes hallucinated fields not in the schema. | Validate the output against the [OUTPUT_SCHEMA] using a JSON schema validator. Assert no validation errors. Assert no properties outside the schema. |
Rationale Completeness | Every sequencing decision that deviates from alphabetical, declaration, or naive order is accompanied by a one-line rationale referencing cost, dependency, or parallelism. | A non-obvious ordering choice is made with no explanation. The reviewer cannot determine why call B precedes call A. | Compare the output order to the naive order. For each deviation, assert that the output contains a rationale string in the corresponding step or a summary rationale section. |
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
Start with the base prompt and a hardcoded tool catalog containing cost_estimate and dependency_map fields for each tool. Use a simple JSON output schema: {"sequence": ["tool_name"], "rationale": "string"}. Skip formal validation; manually inspect a few plans for dependency ordering and obvious cost misses.
Prompt modification
Replace [TOOL_CATALOG] with a static list of 3-5 tools. Remove the [COST_BASELINE] and [BUDGET_CAP] placeholders. Add: If you are unsure about a dependency, state your assumption.
Watch for
- Plans that ignore declared dependencies
- Rationale that sounds plausible but doesn't match the sequence
- No cost comparison against a naive ordering

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