# Detect Intent

> Detects user intent from text input and extracts relevant parameters for downstream routing.

Source: https://docs.sommatic.ai/en/nodes/ai.intent/

- Slug: `ai.intent`
- Family: AI
- Version: 1.0.0
- Status: Available
- Execution: async

Detects user intent from text input and extracts relevant parameters for downstream routing.

This operator classifies input text against a configurable intent catalog, producing a primary intent, confidence score, extracted parameters, and routing hints for workflow orchestration.

**Operations**
- **Intent Detection:** Matches text against a catalog of named intents with descriptions and examples.
- **Parameter Extraction:** Extracts key-value slot parameters relevant to the detected intent.
- **Routing:** Provides routing hints to guide downstream workflow branching.

**Use Cases**
- Chatbot message routing based on user intent (e.g., "book_appointment", "check_status", "complaint").
- Email triage and automatic categorization by purpose.
- Command Center input classification for explicit vs. inference-assisted execution.
- Multi-channel intake routing with confidence-based human review escalation.

## Configuration

- `llm_provider_id` (string, optional): The `id` of a `LlmProviderModel` record (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend: `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` for sync mode, or `POST /chat/conversation/execute/stream-ephemeral` (SSE) for stream mode. The backend resolves endpoint + api-key + deployment from the record and routes to the correct adapter.
- `invocation_mode` (string, optional): Transport for the LLM call. `sync` blocks until the full response arrives. `stream` consumes tokens via SSE (required for long generations). Default `sync`. Default: `sync`. Allowed values: `sync`, `stream`.
- `timeout_ms` (integer, optional): Maximum time to wait for the invocation to complete (or idle timeout between chunks in stream mode). Default 30000 for sync, 600000 for stream.
- `intents` (array<object>, optional): Define the intents to detect. Each needs a name and description. Default: `[]`.
- `allow_multiple` (boolean, optional): Allow detecting multiple intents in a single input. Default: `false`.
- `confidence_threshold` (number, optional): Flag as needs_review when confidence falls below this threshold. Default: `0.7`.
- `knowledge_resource_id` (string, optional): Load intent catalog from a Knowledge Resource instead of inline config.
- `language` (string, optional): Output language code (e.g., "en", "es"). Default: `en`.

Its configuration shows the shared execution settings, but this node does not apply retries (`retryOnFail`, `maxTries`) yet. `continueOnFail` is not applied by any node.

## Output ports

- `detected` (default): Detected
- `unknown`: Unknown
- `error`: Error

## Input contract

- `text` (string, required): The text input to analyze for intent.
- `context` (string, optional): Optional conversation or session context.
- `channel` (string, optional): Optional channel identifier (chat, email, api, etc.).

## Output contract

- `primary_intent` (string, optional): The detected primary intent name or "unknown".
- `confidence` (number, optional): Confidence score (0-1) for the primary intent.
- `all_intents` (array<object>, optional): Probability distribution across all catalog intents.
- `parameters` (object, optional): Extracted key-value parameters relevant to the intent.
- `routing_hint` (string, optional): Suggested next action or routing target.
- `needs_review` (boolean, optional): True when confidence is below the threshold.

## In expressions

What a later node can read from this node's output with `$("Detect Intent").item.json.<path>` (write your node's label instead of `Detect Intent`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `detected`, from the output shown in Ports.

- `$("Detect Intent").item.json.primary_intent` (string) = `"track_order"`: The detected primary intent name or "unknown".
- `$("Detect Intent").item.json.confidence` (number) = `0.92`: Confidence score (0-1) for the primary intent.
- `$("Detect Intent").item.json.all_intents` (array) = `[…] (3)`: Probability distribution across all catalog intents.
- `$("Detect Intent").item.json.parameters` (object) = `{…}`: Extracted key-value parameters relevant to the intent.
- `$("Detect Intent").item.json.routing_hint` (string) = `"order-status-flow"`: Suggested next action or routing target.
- `$("Detect Intent").item.json.needs_review` (boolean) = `false`: True when confidence is below the threshold.
- `$("Detect Intent").item.json.parameters.order_id` (string) = `"4521"` (Not suggested by the editor)
- `$("Detect Intent").item.json.raw` (null) = `null` (Not suggested by the editor)
- `$("Detect Intent").item.json.port` (string) = `"detected"` (Not suggested by the editor)


## How it works

Detects the user's intent in `text` against an intent catalog (inline and/or from a knowledge resource) and routes to `detected` or `unknown`, with extracted parameters.

1. Merges the upstream payload with the node config (config wins) and reads `text`, `context` and `channel`; throws `Missing 'text'` when `text` is empty.
2. Collects intents from `intents` (items need `name`) and adds those in `content.structured_data.intents` of `knowledge_resource_id` whose name is not already present (case-insensitive). Fails when none remain.
3. Sends a classifier system prompt with the catalog, the threshold and a strict JSON format; the user message joins `Channel:`, `Context:` and `text`; `temperature: 0`.
4. Parses the answer as JSON. `primary_intent` is matched case-insensitively to the catalog; any other value becomes `unknown`. Every catalog intent missing from `all_intents` is added with confidence 0.
5. `needs_review` is the model's value or, when missing, `confidence < confidence_threshold`. Routes to `detected` unless the intent is `unknown`.

## In a workflow

### Node

```json
{
  "node_id": "node-detect-intent",
  "label": "Detect intent",
  "operator_slug": "ai.intent",
  "operator_version": "1.0.0",
  "config": {
    "text": "{{ $json.message }}",
    "channel": "chat",
    "intents": [
      {
        "name": "track_order",
        "description": "The user wants to know where an order is",
        "examples": "where is my order, tracking number"
      },
      {
        "name": "cancel_order",
        "description": "The user wants to cancel an order"
      },
      {
        "name": "refund",
        "description": "The user asks for money back"
      }
    ],
    "allow_multiple": false,
    "confidence_threshold": 0.7,
    "language": "en",
    "llm_provider_id": "wf-llm-provider-xxxx",
    "invocation_mode": "sync"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "primary_intent": "track_order",
    "confidence": 0.92,
    "all_intents": [
      {
        "intent": "track_order",
        "confidence": 0.92
      },
      {
        "intent": "cancel_order",
        "confidence": 0.05
      },
      {
        "intent": "refund",
        "confidence": 0.03
      }
    ],
    "parameters": {
      "order_id": "4521"
    },
    "routing_hint": "order-status-flow",
    "needs_review": false,
    "raw": null,
    "port": "detected"
  },
  "port": "detected"
}
```

## Output ports (behaviour in the code)

### `detected`

The primary intent is a catalog intent, whatever its confidence. Check `needs_review` for low confidence.

```json
{
  "primary_intent": "track_order",
  "confidence": 0.92,
  "all_intents": [
    {
      "intent": "track_order",
      "confidence": 0.92
    },
    {
      "intent": "cancel_order",
      "confidence": 0.05
    },
    {
      "intent": "refund",
      "confidence": 0.03
    }
  ],
  "parameters": {
    "order_id": "4521"
  },
  "routing_hint": "order-status-flow",
  "needs_review": false,
  "raw": null,
  "port": "detected"
}
```

### `unknown`

The model answered `unknown`, no intent, or a name outside the catalog.

```json
{
  "primary_intent": "unknown",
  "confidence": 0.2,
  "all_intents": [
    {
      "intent": "track_order",
      "confidence": 0.1
    },
    {
      "intent": "cancel_order",
      "confidence": 0.05
    },
    {
      "intent": "refund",
      "confidence": 0.05
    }
  ],
  "parameters": {},
  "routing_hint": null,
  "needs_review": true,
  "raw": null,
  "port": "unknown"
}
```

### `error`

`text` or the catalog is missing, the model call failed or the answer was not JSON.

```json
{
  "error": "Model did not return valid JSON output"
}
```

## Behaviour in the code

- `confidence_threshold`: Does not change the port: a low-confidence catalog intent still goes to `detected`. It only sets `needs_review` when the model omits it.
- `text, context, channel`: Not in the config schema (it is in the input contract), but read from the config first and then from the upstream payload.
- `timeout_ms`: Stream mode only: idle timeout between chunks, default 600000. In sync mode it is not applied to the request.
- `execution`: Declared but ignored: neither the worker nor the engine reads `retryOnFail`, `maxTries`, `waitBetweenTries`, `continueOnFail`, `alwaysOutputData` or `timeout_ms` from this block.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Missing 'text'` | `error` | No `text` in the config or the upstream payload. |
| `No intents found. Provide intents in the config or link a Knowledge Resource with an intent catalog.` | `error` | Neither `intents` nor the resource provides an intent with a `name`. If there are no inline intents and the resource fetch fails, that fetch error is returned instead. |
| `Model did not return valid JSON output` | `error` | The answer could not be parsed as a JSON object. |
| `[AiIntent] Missing 'llm_provider_id' in node config (LlmProviderModel.id, e.g. 'wf-llm-provider-*'). The legacy 'model_id' alias is no longer supported — update the node config to use 'llm_provider_id'.` | `error` | `llm_provider_id` is empty or not a string. Pick an LLM provider record with chat capability. |
| `LLM Invocation Error: <backend message>` | `error` | The backend rejected the call: unknown or inactive provider record, provider error, quota or content filter. Check the provider record and the backend logs. |
| `LLM Invocation Error: empty response from backend (<transport error>)` | `error` | Sync mode: the HTTP call to the backend failed (network error, non-2xx status or timeout). Long prompts often hit the request timeout; switch to `invocation_mode: "stream"`. |
| `RemoteApiService.stream: idle timeout after <timeout_ms>ms` | `error` | Stream mode: no chunk arrived within `timeout_ms`. A failed stream request shows `RemoteApiService.stream: HTTP <status> — <body>` instead. |

## Notes and limits

- The model is asked for `reasoning`, but it is not returned. `parameters` is passed through from the model as an object.
- The worker returns its fields at the top level instead of inside `data`, so the engine stores the whole return value as the node output: `port` and `raw` appear in `$json` next to the result fields.
- `raw` is the provider's raw response in sync mode and `null` in stream mode.
- The model call goes through the Sommatic AI backend, which resolves the provider record named by `llm_provider_id` (endpoint, credentials, deployment); the orchestrator never holds provider keys. `invocation_mode: "sync"` (default) waits for the full answer; `"stream"` reads it as server-sent events and joins the chunks.
- `timeout_ms` only takes effect in stream mode, as the idle time allowed between chunks (default 600000). In sync mode the value is logged but not applied to the HTTP request, so the platform's default request timeout governs.
- In stream mode the backend endpoint does not apply sampling settings, so the fixed `temperature: 0` only takes effect in sync mode.
- The knowledge resource is read from the backend on every run (10 s timeout). A resource whose status is not `active` is used anyway, with a warning in the log.
- No automatic retries: the engine does not honour `execution.retryOnFail`, `maxTries` or `waitBetweenTries` for this node; a failed call goes straight to `error`.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "ai.intent",
  "name": "Detect Intent",
  "category": "ai",
  "version": "1.0.0",
  "description": "Detects user intent from text input and extracts relevant parameters for downstream routing.\n\nThis operator classifies input text against a configurable intent catalog, producing a primary intent, confidence score, extracted parameters, and routing hints for workflow orchestration.\n\n**Operations**\n- **Intent Detection:** Matches text against a catalog of named intents with descriptions and examples.\n- **Parameter Extraction:** Extracts key-value slot parameters relevant to the detected intent.\n- **Routing:** Provides routing hints to guide downstream workflow branching.\n\n**Use Cases**\n- Chatbot message routing based on user intent (e.g., \"book_appointment\", \"check_status\", \"complaint\").\n- Email triage and automatic categorization by purpose.\n- Command Center input classification for explicit vs. inference-assisted execution.\n- Multi-channel intake routing with confidence-based human review escalation.",
  "capabilities": [
    "ai",
    "nlp",
    "intent",
    "classification",
    "routing"
  ],
  "knowledge_binding": {
    "enabled": true,
    "resource_types": [
      "intent_catalog"
    ],
    "field": "knowledge_resource_id",
    "label": "Intent Catalog"
  },
  "config_schema": {
    "type": "object",
    "properties": {
      "llm_provider_id": {
        "type": "string",
        "title": "LLM Provider",
        "description": "The `id` of a `LlmProviderModel` record (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend: `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` for sync mode, or `POST /chat/conversation/execute/stream-ephemeral` (SSE) for stream mode. The backend resolves endpoint + api-key + deployment from the record and routes to the correct adapter.",
        "x-ui-widget": "llm-provider-picker",
        "x-llm-provider-capabilities": [
          "chat"
        ]
      },
      "invocation_mode": {
        "type": "string",
        "title": "Invocation Mode",
        "description": "Transport for the LLM call. `sync` blocks until the full response arrives. `stream` consumes tokens via SSE (required for long generations). Default `sync`.",
        "enum": [
          "sync",
          "stream"
        ],
        "default": "sync"
      },
      "timeout_ms": {
        "type": "integer",
        "title": "Timeout (ms)",
        "description": "Maximum time to wait for the invocation to complete (or idle timeout between chunks in stream mode). Default 30000 for sync, 600000 for stream.",
        "minimum": 1000
      },
      "intents": {
        "type": "array",
        "title": "Intent Catalog",
        "description": "Define the intents to detect. Each needs a name and description.",
        "items": {
          "type": "object",
          "properties": {
            "name": {
              "type": "string",
              "title": "Intent Name"
            },
            "description": {
              "type": "string",
              "title": "Description"
            },
            "examples": {
              "type": "string",
              "title": "Example Phrases"
            }
          },
          "required": [
            "name",
            "description"
          ]
        },
        "default": []
      },
      "allow_multiple": {
        "type": "boolean",
        "title": "Allow Multiple Intents",
        "description": "Allow detecting multiple intents in a single input.",
        "default": false
      },
      "confidence_threshold": {
        "type": "number",
        "title": "Confidence Threshold",
        "description": "Flag as needs_review when confidence falls below this threshold.",
        "default": 0.7,
        "minimum": 0,
        "maximum": 1
      },
      "knowledge_resource_id": {
        "type": "string",
        "title": "Intent Catalog (Knowledge Resource)",
        "description": "Load intent catalog from a Knowledge Resource instead of inline config.",
        "ui_widget": "knowledge_resource_picker"
      },
      "language": {
        "type": "string",
        "title": "Language",
        "description": "Output language code (e.g., \"en\", \"es\").",
        "default": "en"
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "text": {
        "type": "string",
        "description": "The text input to analyze for intent."
      },
      "context": {
        "type": "string",
        "description": "Optional conversation or session context."
      },
      "channel": {
        "type": "string",
        "description": "Optional channel identifier (chat, email, api, etc.)."
      }
    },
    "required": [
      "text"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "primary_intent": {
        "type": "string",
        "description": "The detected primary intent name or \"unknown\"."
      },
      "confidence": {
        "type": "number",
        "description": "Confidence score (0-1) for the primary intent."
      },
      "all_intents": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "intent": {
              "type": "string"
            },
            "confidence": {
              "type": "number"
            }
          }
        },
        "description": "Probability distribution across all catalog intents."
      },
      "parameters": {
        "type": "object",
        "description": "Extracted key-value parameters relevant to the intent."
      },
      "routing_hint": {
        "type": "string",
        "description": "Suggested next action or routing target."
      },
      "needs_review": {
        "type": "boolean",
        "description": "True when confidence is below the threshold."
      }
    }
  },
  "ports": [
    {
      "port_id": "detected",
      "label": "Detected",
      "is_default": true
    },
    {
      "port_id": "unknown",
      "label": "Unknown"
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "async",
  "tags": [
    "ai",
    "nlp",
    "intent",
    "routing",
    "classification"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "llm_provider_id": {
      "type": "string",
      "title": "LLM Provider",
      "description": "The `id` of a `LlmProviderModel` record (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend: `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` for sync mode, or `POST /chat/conversation/execute/stream-ephemeral` (SSE) for stream mode. The backend resolves endpoint + api-key + deployment from the record and routes to the correct adapter.",
      "x-ui-widget": "llm-provider-picker",
      "x-llm-provider-capabilities": [
        "chat"
      ]
    },
    "invocation_mode": {
      "type": "string",
      "title": "Invocation Mode",
      "description": "Transport for the LLM call. `sync` blocks until the full response arrives. `stream` consumes tokens via SSE (required for long generations). Default `sync`.",
      "enum": [
        "sync",
        "stream"
      ],
      "default": "sync"
    },
    "timeout_ms": {
      "type": "integer",
      "title": "Timeout (ms)",
      "description": "Maximum time to wait for the invocation to complete (or idle timeout between chunks in stream mode). Default 30000 for sync, 600000 for stream.",
      "minimum": 1000
    },
    "intents": {
      "type": "array",
      "title": "Intent Catalog",
      "description": "Define the intents to detect. Each needs a name and description.",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "title": "Intent Name"
          },
          "description": {
            "type": "string",
            "title": "Description"
          },
          "examples": {
            "type": "string",
            "title": "Example Phrases"
          }
        },
        "required": [
          "name",
          "description"
        ]
      },
      "default": []
    },
    "allow_multiple": {
      "type": "boolean",
      "title": "Allow Multiple Intents",
      "description": "Allow detecting multiple intents in a single input.",
      "default": false
    },
    "confidence_threshold": {
      "type": "number",
      "title": "Confidence Threshold",
      "description": "Flag as needs_review when confidence falls below this threshold.",
      "default": 0.7,
      "minimum": 0,
      "maximum": 1
    },
    "knowledge_resource_id": {
      "type": "string",
      "title": "Intent Catalog (Knowledge Resource)",
      "description": "Load intent catalog from a Knowledge Resource instead of inline config.",
      "ui_widget": "knowledge_resource_picker"
    },
    "language": {
      "type": "string",
      "title": "Language",
      "description": "Output language code (e.g., \"en\", \"es\").",
      "default": "en"
    },
    "execution": {
      "type": "object",
      "title": "Execution Settings",
      "properties": {
        "alwaysOutputData": {
          "type": "boolean",
          "title": "Always Output Data",
          "description": "Always output data, even on error (if configured).",
          "default": false
        },
        "retryOnFail": {
          "type": "boolean",
          "title": "Retry On Fail",
          "description": "Retry the execution if it fails.",
          "default": false
        },
        "maxTries": {
          "type": "integer",
          "title": "Max Retries",
          "description": "Number of retries.",
          "default": 3,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "waitBetweenTries": {
          "type": "integer",
          "title": "Wait Between Retries (ms)",
          "default": 1000,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "continueOnFail": {
          "type": "boolean",
          "title": "Continue On Fail",
          "description": "Do not crash workflow on error.",
          "default": false
        },
        "timeout_ms": {
          "type": "integer",
          "title": "Timeout (ms)",
          "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
          "default": 300000
        }
      }
    }
  }
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "text": {
      "type": "string",
      "description": "The text input to analyze for intent."
    },
    "context": {
      "type": "string",
      "description": "Optional conversation or session context."
    },
    "channel": {
      "type": "string",
      "description": "Optional channel identifier (chat, email, api, etc.)."
    }
  },
  "required": [
    "text"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "primary_intent": {
      "type": "string",
      "description": "The detected primary intent name or \"unknown\"."
    },
    "confidence": {
      "type": "number",
      "description": "Confidence score (0-1) for the primary intent."
    },
    "all_intents": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "intent": {
            "type": "string"
          },
          "confidence": {
            "type": "number"
          }
        }
      },
      "description": "Probability distribution across all catalog intents."
    },
    "parameters": {
      "type": "object",
      "description": "Extracted key-value parameters relevant to the intent."
    },
    "routing_hint": {
      "type": "string",
      "description": "Suggested next action or routing target."
    },
    "needs_review": {
      "type": "boolean",
      "description": "True when confidence is below the threshold."
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "detected",
    "label": "Detected",
    "is_default": true
  },
  {
    "port_id": "unknown",
    "label": "Unknown"
  },
  {
    "port_id": "error",
    "label": "Error"
  }
]
```
