Skip to content

Build with an AI Assistant

An AI assistant can write a working Custom Behavior, Custom Step, Custom Event, function, gizmo or Intuitive AI script in minutes, if you give it the right text. It works the same way in Claude, ChatGPT, Copilot, Cursor and Gemini.

This page gives the workflow in five steps: paste the primer, paste the surface block, state a precise goal, review the result with six checks, and test it on a non-production tenant.

At a glance

  • You paste The AI Assistant Primer, then the Copy this into your assistant block from the surface page.
  • You write One precise goal with exact field, bucket and variable names.
  • You check The six checks, then a test on a non-production tenant.
  • For API code Add the spec block for each action, from your tenant's OpenAPI spec.

The workflow

graph TD
  A["Paste the primer"] --> B["Paste the surface block"]
  B --> C["State a precise goal"]
  C --> D["Assistant drafts the code"]
  D --> E["Run the six checks"]
  E -->|fails| C
  E --> F["Test on a non-production tenant"]
  F --> G["Promote to production"]

Step 1: Paste the primer

Paste the AI Assistant Primer. It teaches the model the work item, every extension point, the chooser rules, the API rules and the six checks.

Fill in its Your tenant section first: content types, field names, workflows, global variables. The assistant uses those names instead of inventing them.

Step 2: Paste the surface block

Every extension point introduction ends with a Copy this into your assistant section. That block holds the full runtime contract for one surface:

  • every object and method, with its signature;
  • the rules and the gotchas;
  • one working example.

If you do not know the surface yet, state your goal first and ask the assistant which extension point fits. The primer tells it to name one and ask for the block.

Step 3: Give a precise goal

Name the exact bucket and key names, the field names, the thresholds, and what must happen on failure.

  • Not a goal "Flag big invoices"
  • A goal "Set Index.NeedsReview to Yes when Index.InvoiceTotal is over the ReviewLimit global variable"

Ask for the trade-offs too: "Where can this time out? What happens if the step runs twice? What happens when the field is empty?"

Step 4: Review with the six checks

Read the code against Six Checks Before You Trust Generated Code. Fix what fails, or tell the assistant which check failed and ask again.

You can also paste the review prompt from that page and let the assistant check its own work first.

Step 5: Test on a non-production tenant

  1. Use real sample documents.
  2. Check the result in the data, not only in the step status: open the work item and confirm each key you expected to change.
  3. Move the script to production the same way you move any configuration change.
  4. Keep the script and the prompt in source control, so the next change starts from what runs today.

Paste, or point it at a page

  • Paste (most reliable) The model reads exactly the text you gave it, and nothing else. Each surface block is written for a model: imperative, self-contained and short, with no "see above" and no links it would have to follow.
  • Point it at a page Every page on this site is also plain HTML, so an assistant that can browse (Claude Code, Cursor, ChatGPT with browsing) can read a page you link.
  • If you link Link the specific surface page, not the home page, and still check the result against the six checks.

The prompt template

Copy this template, fill in the brackets, and send it after the primer and the surface block.

Prompt template
I am building on KnowledgeLake. You have the AI Assistant Primer and the
[surface name] context block above.

Goal: [one or two sentences: what changes, for whom, and when]

Where it goes: [content type and field / workflow and step / class and subclass /
task layout]

Names to use (exact, case-sensitive):
- Reads: [bucket.key, field names, global variables]
- Writes: [bucket.key, event scopes and properties, task outputs]

Rules:
- [threshold, format or business rule]
- On failure: [fail the step / set a reason and route to an exception queue /
  show a validation message]

Before you write code: name the extension point and why, and list any name you
need that is not above. Then write the complete script with a header comment
(where it goes, what it reads, what it writes), the setup steps, a test plan for
a non-production tenant, and the result of the six checks. Tell me where it can
time out and what happens if it runs twice.

Worked goal statements

Each goal names the surface, the exact fields and the failure behavior. Change the names to match your tenant.

Custom Behavior

On the Invoice content type, attach a behavior to PaymentMethod. When it is Check, show and enable CheckNumber and make it required with the message "Enter the check number." Otherwise hide CheckNumber and clear it without firing its behaviors. Compare lowercased. Do nothing to CheckNumber when context.app is worker.

Custom Step

For each document, read Index.InvoiceTotal, which may contain $ and commas. Set the document's Index.NeedsReview to Yes when the total is over the ReviewLimit global variable, else No. On the work item, set Index.NeedsReview to Yes if any document needs review, and Index.BatchTotal to the sum with two decimals. A route reads the work-item value. Throw a clear error if ReviewLimit is not a number.

Custom Event

After the Approve step, write an event with scopes invoice, approved. Properties: vendor from Index.Vendor, invoiceTotal from Index.InvoiceTotal as written, documentCount as a string, and region from the Region global variable. Our Cosmos DB report groups by vendor. Missing values must be sent as empty strings, not left out.

Your own function

Write a C# Azure Function called by a Call External API step. Read the work item id from the WorkItemId header and return HTTP 400 if it is missing. Call V1_KWorkItemAPI/GetWorkItem, then for each document with Index.Vendor empty, set Index.Vendor from our vendor service (VENDOR_API_URL app setting) with UpsertDocumentMetadata. Check Success on every response. Return HTTP 500 with the API error text (Messages[].MessageKey) on any failure. The token is in the KnowledgeLakeApiToken app setting. I pasted the spec blocks for both actions.

Intuitive AI refiner

Write a Custom Condition (First Page Refiner) for the subclass "Tri-State Industrial Supply" of the Invoice class. Read the page text once with services.OcrService.GetPageOcr(state). Score it: the vendor name as whole words, case-insensitive, 0.6; the remit-to postal code 44114 on the same page, plus 0.3; the look-alike "Tri-State Industrial Services", minus 0.5. Clamp to 0 to 1 and call result.SetResult(score) once. With no page text, give no result.

Use it in your tool

The primer and the surface blocks are plain Markdown, so every tool can use them.

Paste the primer as your first message, then the surface block, then your goal. Start a new conversation for each new piece of work, so old context does not mix in. For API code, paste only the spec blocks you need.

Save the primer as CLAUDE.md at the root of the folder that holds your scripts. Claude Code reads it at the start of every session. Save each surface block as CLAUDE.md in that surface's subfolder (for example custom-step/CLAUDE.md). Claude Code also reads the file from each parent folder, so a session started in custom-step/ gets both.

Save the primer as .github/copilot-instructions.md in your repository. Save each surface block as a path-specific file, for example .github/instructions/custom-step.instructions.md, and set applyTo in its front matter to the folder that holds those scripts.

Save the primer as .cursor/rules/knowledgelake.mdc with alwaysApply: true in its front matter. Save each surface block as its own rule, for example .cursor/rules/custom-step.mdc, with globs set to that surface's files.

Keep a working script

Keep a working script for each surface next to the instructions. An assistant copies the shape of real, running code better than it follows a description.

API code: give it your tenant's spec

Every tenant serves its own OpenAPI spec. No sign-in is needed. Download it once and keep it next to your code:

Download the spec (PowerShell)
$tenant = "https://your-tenant.example.com"
Invoke-WebRequest -Uri "$tenant/api/OpenAPI/V2_JSON/V2_JSON?domain=$tenant" -OutFile openapi.v2.json
Download the spec (bash)
tenant="https://your-tenant.example.com"
curl -o openapi.v2.json "$tenant/api/OpenAPI/V2_JSON/V2_JSON?domain=$tenant"

The spec is large. Do not paste it whole: the assistant loses the part that matters. Search it by action name and paste only that block and the definitions it references:

Find one action in the spec
grep -n '"/V1_KWorkItemAPI/UpsertWorkItemMetadata"' openapi.v2.json
jq '.paths["/V1_KWorkItemAPI/UpsertWorkItemMetadata"]' openapi.v2.json
  • No match The action does not exist on your tenant.
  • Let it search An assistant that can run commands (Claude Code, Cursor, Copilot in agent mode) can do the search itself. Tell it to: "Search openapi.v2.json for each action name before you use it. Do not read the whole file."
  • Your spec only Use your own tenant's spec, not a copy from another tenant or a training kit. It matches the release your tenant runs.