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

# AI in Workflows

> Add an AI step to classify, extract, summarize, or generate with structured output — and let the AI copilot draft a whole workflow from a prompt or explain a failed run.

# AI in Workflows

KnoxCall brings AI into workflows two ways: an **AI step** you drop into a graph like any other node, and an **AI copilot** that drafts workflows from a plain-language prompt and explains failed runs.

## The AI Step

The **AI** node runs an Anthropic model with **structured output** — you declare the shape you want and get back typed data, no prompt-parsing glue. Four operations:

| Operation     | What it does                                  | Key config                               |
| ------------- | --------------------------------------------- | ---------------------------------------- |
| **Classify**  | Picks one label from a list                   | `labels: [...]`                          |
| **Extract**   | Pulls named fields out of text into an object | `fields: [{ name, description, type? }]` |
| **Summarize** | Condenses text to a target length             | `maxLength` hint                         |
| **Generate**  | Free-form generation                          | `maxTokens` cap (default 1024)           |

**Example — classify an inbound message:**

```json theme={"dark"}
{
  "type": "ai",
  "data": {
    "type": "ai",
    "config": {
      "operation": "classify",
      "text": "{{trigger.data.message}}",
      "labels": ["billing", "technical", "sales"]
    }
  }
}
```

The `text` field (and other inputs) support `{{ ... }}` variables. Output is a structured object you reference downstream, e.g. `{{ai_1.label}}` for a classification result, or the extracted fields for an extraction.

### Model & Credentials

AI steps resolve Anthropic access **tenant-key-first**: if you've configured an Anthropic key under **Integrations**, it's used; otherwise the platform key is used. The model is centrally configured (default `claude-sonnet-5`) — you don't hard-code a model id in the node.

### Metering & Limits

* AI nodes count as **weighted operations (×3)** against your monthly operations quota.
* AI-token usage is metered against a monthly **AI-token budget** per plan tier.
* When either limit is reached, an AI step is blocked (recorded, not run) rather than silently overspending.

## The AI Copilot

Open the **AI** panel in the builder toolbar to draft a workflow from a description.

### Draft a workflow from a prompt

Describe what you want — for example:

> "When a GitHub issue is opened, classify it as bug or feature, and post a Slack message to the right channel."

The copilot returns a coherent, **auto-laid-out** graph (trigger → nodes → edges) that lands **unsaved** on your canvas. It goes through the same publish gate as a hand-built workflow: structural validation is enforced, and any per-node configuration gaps come back as **warnings** so you know exactly what to fill in (connections, secrets, endpoints) before publishing.

### Explain a run

On any finished execution, click **Explain** in the run log. The copilot reads the run's redacted step history and returns a plain-language explanation of what happened plus a **suggested fix** — for example, diagnosing an unreachable URL and pointing at the exact node to correct.

### Metering

Copilot calls are rate-limited and draw from the same AI-token budget as AI steps (each call reports its own token cost).

## Tips

* Start Extract/Classify with a few clear labels or fields; add more only if results are ambiguous.
* Use the copilot to scaffold, then refine node config by hand — it's a starting point, not a black box.
* Keep an Anthropic key in Integrations if you want AI usage billed to your own account.

## Next Steps

<CardGroup cols={2}>
  <Card title="Creating Workflows" icon="plus" href="/workflows/creating-workflows">
    Add an AI step to a graph
  </Card>

  <Card title="Templates" icon="grid-2" href="/workflows/templates">
    Start from a pre-built workflow
  </Card>
</CardGroup>
