> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nika.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Support triage

> T2 chain · support: the overnight queue classified, first replies drafted, urgent ones escalated.

> **T2 chain · customer support**: one schema-typed call classifies the
> WHOLE queue (enums keep the categories honest), jq slices the urgent
> ones, and the escalation fires only when there's something to escalate.

## The job

It's 8:55. There are 40 tickets from overnight. Someone reads them all,
tags them, writes first replies, and pages on-call if anything's on
fire. This file does the reading, tagging and drafting (under a
sortable v7 batch id) and pages only when `urgent` is non-empty.

## The shape

```mermaid theme={"system"}
flowchart LR
  batch["batch · nika:uuid"]:::invoke
  queue["queue · nika:read"]:::invoke
  triage["triage · typed"]:::infer
  urgent["urgent · nika:jq"]:::invoke
  escalate["escalate · nika:notify"]:::invoke
  board["board · nika:write"]:::invoke
  queue --> triage
  triage --> urgent
  urgent --> escalate
  batch --> escalate
  triage --> board
  batch --> board
  classDef infer fill:#5b8cff22,stroke:#5b8cff,color:#5b8cff
  classDef invoke fill:#22d3ee22,stroke:#22d3ee,color:#22d3ee
```

## The file

```yaml support-triage.nika theme={"system"}
nika: support-triage

# The house seat — a THINKING model: the think block and the JSON both count
# against `max_tokens` (engine#428), so the triage ceiling below covers the
# reasoning AND the board, not the board alone.
model: ollama/qwen3.5:4b   # local · zero key · swap for groq/llama-3.3-70b-versatile (triage wants speed)

const:
  queue_path: "examples/fixtures/support-queue.json"

secrets:
  oncall_webhook:
    source: env
    key: ONCALL_WEBHOOK_URL
    egress:                       # sanction the one send · the secret IS the URL
      - to: "nika:notify"
        host_from_self: true
permits:
  tools: ["nika:jq", "nika:notify", "nika:read", "nika:uuid", "nika:write"]
  net:
    # `host_from_self:` above sanctions the FLOW (the secret may be the URL) —
    # it does not grant the capability. The host stays unknown at check, so it
    # is judged at RUN against this bound: name the escalation host here or the
    # send is refused mid-run, after the tokens are already spent.
    http: ["hooks.slack.com"]
  fs:
    read: ["examples/fixtures/support-queue.json"]
    # One board per batch id. `*` matches a single segment and never crosses
    # `/`, so the uuid can never steer the write out of out/ — `out/**` would
    # let it.
    write: ["out/triage-*.json"]

tasks:
  batch:
    invoke:
      tool: "nika:uuid"
      args: { version: v7 }

  queue:
    invoke:
      tool: "nika:read"
      args: { path: "${{ const.queue_path }}" }

  triage:
    with:
      queue: ${{ tasks.queue.output }}
    infer:
      # a reasoning model needs 16384 here, or a documented run.reasoning.effort: low
      max_tokens: 4000                 # think block + the whole queue in one call · a ceiling, not UNBOUNDED
      prompt: |
        Triage every ticket in this queue ·
        ${{ with.queue }}
        For each · classify category and urgency, draft a 2-sentence first reply.
      schema:
        type: object
        additionalProperties: false    # a deterministic shape across providers
        required: [tickets]
        properties:
          tickets:
            type: array
            items:
              type: object
              additionalProperties: false
              required: [id, category, urgency, first_reply]
              properties:
                id: { type: string }
                category: { type: string, enum: [billing, bug, how-to, account, other] }
                urgency: { type: string, enum: [low, normal, high, critical] }
                first_reply: { type: string }

  urgent:
    with:
      tickets: ${{ tasks.triage.output.tickets }}
    invoke:
      tool: "nika:jq"
      args:
        input: "${{ with.tickets }}"
        expression: 'map(select(.urgency == "high" or .urgency == "critical"))'

  escalate:
    with:
      urgent: ${{ tasks.urgent.output }}
      batch: ${{ tasks.batch.output }}
    when: ${{ size(with.urgent) > 0 }}
    invoke:
      tool: "nika:notify"
      args:
        channel: webhook
        target: "${{ secrets.oncall_webhook }}"
        message: "Urgent tickets in triage batch ${{ with.batch }} · ${{ with.urgent }}"
        severity: warning

  board:
    with:
      tickets: ${{ tasks.triage.output.tickets }}
      batch: ${{ tasks.batch.output }}
    invoke:
      tool: "nika:write"
      args:
        # A `.json` artifact takes ONE interpolated value as `content:` and
        # lets the engine serialize it. Typing `{ "tickets": ${{ … }} }` by
        # hand emits unquoted fields and the board stops being JSON.
        path: "out/triage-${{ with.batch }}.json"
        content: "${{ with.tickets }}"
        create_dirs: true

outputs:
  tickets:
    value: ${{ tasks.triage.output.tickets }}
    description: "The classified queue with drafted first replies"
```

## How it works

**1. Enums make classification honest**

`category` and `urgency` are schema enums: the model cannot invent
a « kinda-urgent » tier. Typed output means the jq filter downstream
can trust the values.

**2. jq slices, the model doesn't re-read**

`urgent` filters `urgency == "high" or "critical"` out of the typed
list: no second model call to ask « which ones were urgent? ».

**3. v7 uuids sort by time**

`nika:uuid version: v7` is timestamped: triage boards land on disk
already in chronological order.

## Constructs you just used

| Construct | Where | Reference |
| - | - | - |
| schema enums over a list | `triage` | [The 4 verbs](https://docs.nika.sh/concepts/verbs.md) |
| `nika:jq` post-filter | `urgent` | [Builtins](https://docs.nika.sh/reference/builtins.md) |
| `nika:uuid` v7 | `batch` | [Builtins](https://docs.nika.sh/reference/builtins.md) |
| conditional `notify` | `escalate` | [Workflows](https://docs.nika.sh/concepts/workflows.md) |

## Run it

> [!NOTE]
>
> **What it needs:** A local model ([Ollama](https://ollama.com) serving `qwen3.5:4b`) and the sample queue. `ONCALL_WEBHOOK_URL` matters only on the escalation path: the sample carries an outage ticket, so a real model opens that gate, and an unset variable then fails loudly (`NIKA-VAR-001`).

**1. Rehearse it**

```bash theme={"system"}
nika try support-triage
```

A mock model answers, the sample files come with it, and nothing is written in your folder. Before it runs, `nika try` names the hosts a step may reach: `may reach: hooks.slack.com — the mock replaces the model, not the network`.

**2. Get your own copy**

Save the file above as `support-triage.nika` in a new folder, then download the sample it reads:

```bash theme={"system"}
FIXTURES=https://raw.githubusercontent.com/supernovae-st/nika/v0.124.3/crates/nika-pack/pack/examples/fixtures
mkdir -p examples/fixtures
curl -fsSLo examples/fixtures/support-queue.json "$FIXTURES/support-queue.json"
```

**3. Check it, then run it**

```bash theme={"system"}
nika check support-triage.nika
nika run support-triage.nika --model mock/echo   # a mock model, no key
ollama pull qwen3.5:4b   # once, for the real run
nika run support-triage.nika
```

The run writes the board `out/triage-<batch id>.json`.

Any other model works: pass `--model <provider>/<name>` with its key, and cap a cloud model with `--max-cost-usd`.

## Make it yours

* Push the first replies as DRAFTS into your helpdesk via its API (`nika:fetch method: POST`): humans still hit send.
* Track sentiment over time: append each batch's stats to a CSV with `nika:write`.
* Speed matters at 9am: swap the envelope `model:` for a cataloged
  cloud seat and cap the run with `--max-cost-usd`.

> [card] [Next · Contract guard](https://docs.nika.sh/examples/contract-guard.md)
>
> The local inference example: a LOCAL model reads the contract, and a
> validate + assert pair refuses bad extractions.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.