run_plan
Executes a multi-step plan of tool calls in one request, handling loops, conditions, and pagination, then returns only the final result.
Instructions
Run a multi-step plan of tool calls in ONE call and get back only the final value. Use it when a job needs several calls, loops or conditions. Find tool names and their output shapes with list_tools first. Only read-only (or allow-listed) tools may run in a plan.
Plan = {"start": "", "steps": {"": , ...}, "input": , "limits": {"max_steps", "max_calls", "timeout_s"} (optional, can only lower)} Step ids: lowercase letters, digits, underscore. Each step result is stored under its id.
Step kinds (each step is exactly one): call {"call": "server.tool", "args": {...}} for_each {"for_each": "", "as": "item", "call": "server.tool", "args": {... "{{item.id}}" ...}, "parallel": 4, "max_items": 100} -> list of results, in the same order as the items Several steps per item: use "do": {"start": "", "steps": {...}} instead of call/args. The sub-plan sees outer results and the loop variable; its step ids are new and local; the item's result is its return (or last value). retry goes on its steps. Nest at most 2. Inside do, next/goto reach only its own steps; ids must not reuse an outer id or the loop variable. parallel and on_error apply per item; sub-steps count toward the limits. {"for_each": "s.ids", "as": "c", "do": {"start": "f", "steps": {"f": {"call": "mail.search", "args": {"q": "{{c}}"}, "next": "g"}, "g": {"call": "mail.get_thread", "args": {"id": "{{f[0].id}}"}}}}} paginate {"paginate": "server.tool", "args": {...}, "cursor_in": "", "cursor_out": "", "collect": "", "max_pages": 10} -> all collected items joined into one list return {"return": ""} ends the plan with this value Optional on call/for_each/paginate: "on_error": "stop" (default) | "skip" (skip: a failed call gives null, a failed for_each item gives {"error": ...}), "retry": 0-5 (default 0) tries a failed call again after 1 s, 2 s, 4 s ... (per item or page). Use retry for tools that fail for a short time; on_error applies when the retries are used up. Do not retry errors that will not change (bad arguments, not found), or tools that write.
Flow: "next": "" or "next": [{"if": "", "goto": "", "wait_s": 0}, ..., {"else": ""}] A branch may point back to an earlier step (a loop); global limits stop runaway plans. No next and no return: the plan ends with the last step's value.
Expressions are JMESPath over {"input": ..., "": result, "": item}.
length(s1.items) == 0 s2[?total > 100].name s1.items[0].id
Literals: numbers and booleans in backticks (0, true), strings in single quotes ('draft').
In args, "{{expr}}" is replaced by the value (a whole-string template keeps its type).
Example:
{"start": "find", "steps": {
"find": {"call": "mail.search", "args": {"q": "invoice"},
"next": [{"if": "length(find.messages) == 0", "goto": "none"}, {"else": "read"}]},
"read": {"for_each": "find.messages", "as": "m", "call": "mail.get_thread",
"args": {"id": "{{m.thread_id}}"}, "parallel": 4, "retry": 2, "next": "out"},
"out": {"return": "read[].{subject: subject, from: from}"},
"none": {"return": "'no invoices'"}}}
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"plan": "<plan>"
},
"name": "run_plan"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| plan | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||