Skip to content

Put AI inside a business workflow ​

The real problem ​

When an employee resigns, Northwind's HR manager must read the letter, judge whether the person is a flight risk for the team, and decide on a retention conversation. Today that is manual and slow. Letting an AI "handle it" end to end would be unsafe: HR must approve, and the path must be auditable.

The answer is not a free-running agent. The workflow engine keeps the path (steps, approvals, conditions); each AI step does one bounded thing and returns fields that the workflow's conditions can test. The model suggests; the workflow decides and a human approves.

The AI steps ​

AI steps are workflow service tasks. In the Workflow Designer they are under Add task > AI.

Task typeDoesPayload (required in bold)Returns
ai.promptRuns a library promptcode, label (default prod) or version, values, profileCodetext, token counts, version
ai.classifySame, but the prompt answers in JSONas ai.prompteach JSON field of the answer, plus text
ai.retrieveSearches a knowledge baseknowledgeBase, query, mode, topK, thresholdhits, count, context
ai.ragRuns a RAG pipelinepipelineCode, question, labelanswer, citations, citationCount
ai.agentRuns an agentagentCode, intentstatus, finalResponse, executionId
ai.guardrailChecks (and can mask) texttext, checks, blockedTerms, action, maxLengthpassed, findings, text

Any payload value may read an earlier step with ${context.<taskKey>.<field>}. The token must be the whole value: text around it, such as "Notice for ${context.grade}", is not substituted. Task keys and field names use letters, digits and underscores only (no hyphens). A whole-value token keeps its type (a number stays a number). A step that fails stops the workflow with a clear message rather than passing on an empty answer.

Designer path: the resignation flow ​

  1. Create a prompt exit-risk whose user text is Reason given: {{reason}}\nReturn JSON: {"risk":"low|medium|high","summary":"..."} (Prompts).
  2. In the Workflow Designer, add a service task analyse of type ai.classify and fill the payload: code exit-risk, values reason = the letter text from the earlier step.
  3. Add a condition after it: context.analyse.risk == "high".
  4. High risk goes to a human task "Retention conversation" assigned to the HR manager, showing context.analyse.summary. Low and medium go straight to the normal exit checklist.
  5. Optionally add an ai.guardrail step first to mask personal data before the text reaches the model.
  6. Publish and run a test instance. Open the instance and read the analyse output: risk, summary, text.

Developer path ​

The same step in a workflow file (see Use AI Studio from your plugin):

json
{
  "taskKey": "analyse",
  "stage": "review",
  "kind": "service",
  "taskType": "ai.classify",
  "payload": {
    "code": "exit-risk",
    "label": "prod",
    "values": { "reason": "${context.get_letter.text}" }
  }
}

A grounded answer step:

json
{ "taskKey": "policy", "kind": "service", "taskType": "ai.rag",
  "payload": { "pipelineCode": "hr-qa", "question": "${context.question}" } }

The worker that runs service tasks needs the AI platform address: start it with --aiBaseUrl https://your-erp (the platform adds the tenant and instance itself).

How to verify ​

  1. Run an instance with a clearly high-risk letter; the flow reaches the human task with the summary shown.
  2. Run one with a neutral letter; it skips the human task.
  3. Break the prompt on purpose (label it to a version that does not answer JSON). The analyse step fails with the prompt code and reason; nothing downstream runs.

Common mistakes ​

  • Letting the AI decide the route with free text. Have it answer in JSON fields and test those fields in a condition.
  • No human step for a consequential outcome. Keep approvals for anything that affects a person.
  • Passing the whole record to the model. Pass only the field it needs; mask personal data with ai.guardrail.
  • Calling a version number. Use a label so you can fix the prompt without editing the workflow.

Not built ​

Workflow templates that come pre-wired with AI steps.

Next ​

Evaluations and guardrails - trust the AI step before you release it.