Manage tools as code
Keep your Tool definitions in your repository — reviewed, versioned in git, and converged to the platform at deploy time. This is the Tool counterpart of managing Agents as code and managing Flows as code: the same ensure protocol, applied to saved Tools.
Define the tool
defineTool is a pure, local constructor. It validates the definition shape and returns the canonical definition object. The definition surface is the tool’s name, description, type, parameters schema, and config — the same fields you set when creating a tool in the dashboard.
Accepted toolType values are external, custom, graphql, mcp, local, flow, and subagent. The tool’s identity is its name plus your account scope (organization, or personal); which environment you converge is decided by the credentials you run with.
Renaming a definition does not rename the tool. ensure will create a new tool under the new
name and leave the old one in place (it never deletes). Treat the name as the stable identity.
flow and subagent tools reference an account-scoped flow or agent ID in their config. Those
IDs belong to one environment, so a definition carrying one is not portable across environments
the way an external or custom tool is.
Converge at deploy time
ensure is hash-first: in the steady state (nothing changed) it sends one tiny probe request carrying only the name and a content hash, and writes nothing. When the content differs, it creates or updates the saved tool.
The content hash covers the tool’s type, description, parameters schema, and config (the name is identity, not content). The contentHash in every response is computed by the server over its canonical, normalized form; the SDK echoes the server’s hash on later probes.
Tools have no version snapshots (unlike Agents and Flows), so there is no publish option and no
versionId on the result. ensure converges the live tool definition directly.
Detect drift in CI
changedKeys names what would change (toolType, description, parametersSchema, and config.<key> per changed config entry). For a one-line PR gate, expectNoChanges throws when the plan is anything but none:
To make the apply step act only on the exact state the dry run saw, bind them with expectedRemoteHash:
Conflicts with dashboard edits
The platform records where each tool write came from. If someone edits an ensure-managed tool in the dashboard (or via the API), the next ensure fails with a 409 conflict by default, surfaced in the SDK as a ToolEnsureConflictError with code: 'external_modification'. In the dashboard, an ensure-managed tool shows a Managed in code badge, and saving an edit warns you first.
You have two remediation directions:
- Repo wins. Re-run with
onConflict: 'overwrite'. The dashboard edit is overwritten in the saved tool. - Dashboard wins. Absorb the edit into your repo with
pull, review it as a git diff, and commit or revert:
What ensure does and does not manage
ensure converges the tool definition: its name, description, type, parameters schema, and config (validated with the same custom-tool-code and {{secret:KEY}} reference rules as tool creation). It does not manage which agents or flow steps reference the tool, and it never deletes or renames tools.
Wire protocol (direct API use)
If you are not using the TypeScript SDK, the protocol is one endpoint: POST /v1/tools/ensure.
- Probe with
{ "name": "...", "contentHash": "<sha-256>" }. A match returns{ "result": "unchanged" }; a miss returns a normal 200{ "result": "definitionRequired" }— retry with the fulldefinitionincluded. - The server recomputes the canonical hash over any submitted definition and returns it on every response. Echo the server’s hash in later probes.
- Conflicts are 409s (
external_modification,remote_changed); a submittedcontentHashthat disagrees with the server’s recompute over the definition is a 422 (content_hash_mismatch). OmitcontentHashon full requests to avoid it entirely.
GET /v1/tools/pull?name=... returns the canonical definition plus provenance (contentHash, lastModifiedSource, updatedAt).
Next steps
- Manage agents as code — the same protocol for Agent definitions
- Manage flows as code — the same protocol for Flow definitions
- Creating external tools — the dashboard tool-building surface