# Classifier

### Classifier Tool

The `minded-classifier` tool categorizes text using AI. It can be used in flows or directly in code.

#### Using in Flows

Use the tool in your flows by referencing `minded-classifier`:

```yaml
- id: classifyUserIntent
  type: tool
  toolName: minded-classifier
  prompt: |
    Classify the user's message into one of these categories:
    - Technical Issue: Problems with the system
    - Billing: Payment or pricing questions
    - Feature Request: Asking for new features
```

#### Tool Parameters

| Parameter     | Type             | Description                           | Required |
| ------------- | ---------------- | ------------------------------------- | -------- |
| content       | string           | Text content to classify              | Yes      |
| classes       | array            | Classes (strings, tuples, or objects) | No\*     |
| systemPrompt  | string           | Custom system prompt                  | No       |
| includeReason | boolean          | Include reasoning (default: true)     | No       |
| outputFormat  | 'json' \| 'text' | Output format (default: 'json')       | No       |
| defaultClass  | string           | Fallback class                        | No       |
| defaultReason | string           | Fallback reason                       | No       |

\*Classes can be provided in parameters or stored in agent memory.

#### Overriding Classifier Parameters in Flows

You can override classifier parameters directly in your flow YAML for deterministic classification:

```yaml
- name: 'Classify Support Ticket'
  type: 'tool'
  toolName: 'minded-classifier'
  parameters:
    # Dynamic - from state
    content: '{state.memory.ticketDescription}'
    # Fixed - predefined classes
    classes:
      - name: 'urgent'
        description: 'Requires immediate attention'
      - name: 'standard'
        description: 'Normal priority'
      - name: 'low'
        description: 'Can be handled later'
    # Fixed - configuration
    includeReason: true
    defaultClass: 'standard'
    # Let AI infer: systemPrompt (optional override)
```

### Using as a Utility

#### Import the utilities

```typescript
import { toolsLibrary } from '@minded-ai/mindedjs';

const { classify, createClassifier, createConversationClassifier, multiClassify } = toolsLibrary.tools['minded-classifier'];
```

#### Direct classification

```typescript
const result = await classify(
  "I can't access my account",
  {
    classes: [
      { name: 'Technical', description: 'Technical issues' },
      { name: 'Account', description: 'Account access problems' },
    ],
    includeReason: true,
  },
  agent.llm,
);

console.log(result);
// { class: 'Account', reason: 'User cannot access their account', confidence: 0.95 }
```

#### Create reusable classifiers

```typescript
// Simple classifier with string classes
const sentimentClassifier = createClassifier(['positive', 'negative', 'neutral']);

// Classifier with descriptions
const intentClassifier = createClassifier([
  ['greeting', 'User is greeting or saying hello'],
  ['question', 'User is asking a question'],
  ['complaint', 'User is complaining or expressing dissatisfaction'],
  ['goodbye', 'User is saying goodbye or ending conversation'],
]);

// Use the classifier
const sentiment = await sentimentClassifier('This is amazing!', agent.llm);
const intent = await intentClassifier('Hello there!', agent.llm);
```

#### Conversation classification

```typescript
const conversationClassifier = createConversationClassifier([
  { name: 'Resolved', description: 'Issue was resolved successfully' },
  { name: 'Escalated', description: 'Needs escalation to human agent' },
  { name: 'Pending', description: 'Awaiting more information' },
]);

const result = await conversationClassifier(messages, agent.llm);
```

#### Multi-label classification

```typescript
const topics = await multiClassify(
  'The app crashes on login and the UI looks outdated',
  {
    classes: [
      { name: 'Bug', description: 'Software bugs or crashes' },
      { name: 'UI/UX', description: 'User interface issues' },
      { name: 'Authentication', description: 'Login or auth problems' },
    ],
    maxClasses: 3,
  },
  agent.llm,
);

console.log(topics);
// [
//   { class: 'Bug', reason: 'App crashes', confidence: 0.9 },
//   { class: 'Authentication', reason: 'Login issues', confidence: 0.85 },
//   { class: 'UI/UX', reason: 'Outdated UI', confidence: 0.7 }
// ]
```

### Configuration

#### `ClassifierConfig` interface

```typescript
interface ClassifierConfig {
  classes: ClassDefinition[];
  systemPrompt?: string;
  outputFormat?: 'json' | 'text';
  includeReason?: boolean;
  defaultClass?: string;
  defaultReason?: string;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.minded.com/tooling/classifier.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
