Skip to main content
Use this endpoint when you want GridOS to build something complex — a multi-section financial model, a DCF analysis, a full operating forecast — without you manually calling apply after each step. The chain endpoint drives the full write loop automatically: it calls the agent, applies the result, reads back any formula values from the newly written cells, feeds those observations into the next prompt, and repeats until the agent signals completion or max_iterations is reached. Use POST /agent/chat + POST /agent/apply instead when you want to review each write before it lands.
On the first turn, the agent may emit a plan object describing the full build — sections, target ranges, and notes. The chain loop uses this plan to drive subsequent turns, writing one section at a time and retrying any section that has column-alignment warnings before advancing.

Request

string
required
The natural-language instruction describing the full task. Be as specific as possible — the agent uses this prompt on every iteration to understand the original goal.
integer
default:"10"
Maximum number of auto-apply steps. Must be between 1 and 10 (values above 10 are clamped). Each iteration corresponds to one agent call and one write to the sheet. The loop may stop before this limit if the agent signals completion.
array
Prior conversation turns, ordered oldest-first. Each element must have a role field ("user" or "assistant") and a content field (string). The chain manages its own internal history across iterations, but you can seed it with earlier context here.
string
default:"sheet"
Controls which cells the agent can see.
  • "sheet" — the entire active sheet (default)
  • "selection" — only the cells listed in selected_cells
array
A list of cell addresses in A1 notation that are currently selected in the UI, for example ["B2"]. Used as an anchor hint when scope is "selection".
string
Name of the sheet to target. Defaults to the active sheet when omitted.
string
The LLM model ID to use for every step in the chain. When omitted, GridOS selects the best available model.

Response

string
The name of the sheet that was written to across all iterations.
array
An array of step objects, one per iteration. Each step contains:
integer
Zero-based index of this step within the chain run.
string
The agent that handled this step (for example "finance" or "general").
string
The agent’s explanation of what it wrote in this step.
string
The cell address where data was actually written for this step, in A1 notation.
array
The 2-D array of values written in this step.
array
Formula cell results read back after the write. Each observation has:
  • cell — A1 address
  • value — the computed value after formulas evaluated
  • formula — the formula string if the cell is formula-driven, otherwise null
  • warning — a string describing a column-alignment issue if one was detected, otherwise null
boolean
true if the agent signaled that the task is fully complete on this step (by returning an empty-string grid). The chain stops immediately when this is true.
object | null
The chart object created during this step, or null if no chart was requested.
string | null
An error message if chart creation failed on this step, otherwise null.
object | null
A macro proposal from the agent on this step, or null. Proposed macros are not saved automatically.
object | null
The multi-section build plan, present only on the first step when the agent emits one. null on all subsequent steps.
integer
The total number of steps that ran. Equal to steps.length.
boolean
true if the loop ended before reaching max_iterations — either because the agent signaled completion or because there was no remaining work detected. false if the loop ran to the iteration limit.
The chain applies each write immediately and without user confirmation. For large financial models, review the completed sheet carefully and use POST /grid/cell or the clear endpoint to correct any cells that were written incorrectly.

Example

Request

Response (abbreviated — 2 of 3 steps shown)

terminated_early: true here means the loop finished before the 10-iteration cap — the agent signaled completion on step 3 (the COGS row), which is not shown in this abbreviated example. A completion_signal: true step is always the last entry in steps.