Save a code rule's draft
PUT /v25-10-beta/agentic-logic/rules/{ruleId}/draft
Saves the draft of a code rule. The response is { draft }. A builder rule answers 400.
- source (string, required) — The rule source.
- dependencies (array, optional) — Must be empty: rules run with no npm packages.
- userTestSuite / generatedTestSuite (string, optional) — Omit to keep the stored suite; send "" to clear it.
- validationScenarios (array, optional) — Scenarios the publish checks run the rule against. Omit to keep the stored ones; send [] to discard them.
- graph (object, optional) — The rule graph for this source, checked against it at save time. When omitted, the stored graph is kept only if the source is unchanged.
- origin (chat or manual, optional) — Where the source came from. Omit to keep the stored value.
- autoAssist (boolean, optional) — Whether the save starts AI assistance. Defaults to true. Send false to only store the draft (see below). Applies to this call only; it is not stored on the rule.
Every save replaces the previous draft. Publish snapshots the draft, so an in-flight publish is not affected by a later save. Unless autoAssist is false, a save also:
- Regenerates the rule graph with AI when the saved draft has no graph.
- Regenerates the AI-generated validation scenarios when they no longer cover the source's attempt() branches. Scenarios you authored are kept.
The first save of a draft rule that has never had a publish job, and that does not send autoAssist: false, also starts a dry run of the publish checks. If the checks fail, an AI repair loop rewrites the draft and runs them again, within its attempt, time, and cost limits. Once the checks pass, the rule is published without any further call. If a rewrite changed what the rule does, the loop stops instead and leaves the rewritten draft for a person to publish.
Saving a draft does not stop a running repair loop. If you save while the loop is rewriting, the loop's rewrite is dropped, that attempt counts against its limit, and the loop decides its next step from your draft.
With autoAssist: false, the save starts neither the regeneration above nor the dry run, and it does not stop a repair loop that is already running. A later save without the flag still starts the dry run while the rule has never had a publish job. A later publish still works: with no graph the graph check passes with a note, with no scenarios the default scenario is used, and the AI test suite is generated at publish time.
A save that omits validationScenarios keeps the stored ones unchanged, so scenarios from an earlier save, including AI-generated ones, carry forward and may no longer match the new source's branches. While they do not, the scenarios listing reports pending until a save without autoAssist: false regenerates them, or a save sends a full generated set: sent scenarios replace the stored ones rather than adding to them.
Use the intelligems-access-token header. The token selects the organization; do not send orgId. The organization must have Agentic Logic enabled.
Rate Limit: 50 requests per 30s window, refilling 25 tokens every 30s.
Request
- Base URLhttps://api.intelligems.io
- AuthAPI key in header intelligems-access-token
- TypeScriptA function with typed inputs. Its response is checked against the schema.
Path parameters
Request body
Response
OK
Changes
No recorded changes to this operation across all 1 revision of this API.