Add AgentIntentRouter model — DeBERTa-v3-base fine-tuned for agent intent classification
Browse files- README.md +157 -0
- config.json +48 -0
- label_mapping.json +32 -0
- model.safetensors +3 -0
- tokenizer.json +0 -0
- tokenizer_config.json +14 -0
README.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: distilbert-base-uncased
|
| 4 |
+
tags:
|
| 5 |
+
- text-classification
|
| 6 |
+
- intent-detection
|
| 7 |
+
- agent-routing
|
| 8 |
+
- mcp
|
| 9 |
+
- ai-agents
|
| 10 |
+
- distilbert
|
| 11 |
+
- tool-use
|
| 12 |
+
datasets:
|
| 13 |
+
- custom
|
| 14 |
+
language:
|
| 15 |
+
- en
|
| 16 |
+
metrics:
|
| 17 |
+
- accuracy
|
| 18 |
+
- f1
|
| 19 |
+
pipeline_tag: text-classification
|
| 20 |
+
library_name: transformers
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
# AgentIntentRouter
|
| 24 |
+
|
| 25 |
+
A fast, lightweight intent classifier for AI agent and MCP tool routing. Given a user message, it predicts which tool or capability the agent should invoke — in under 50ms on CPU.
|
| 26 |
+
|
| 27 |
+
Built on DistilBERT (66M params), fine-tuned on 12K+ diverse examples across 8 intent categories.
|
| 28 |
+
|
| 29 |
+
## Why This Exists
|
| 30 |
+
|
| 31 |
+
Every agent framework (LangChain, LangGraph, CrewAI, AutoGen) wastes an entire LLM call just to figure out *what the user wants*. That's 1-3 seconds and ~$0.01 per request — just for routing.
|
| 32 |
+
|
| 33 |
+
AgentIntentRouter replaces that first LLM call with a 66M classifier that runs in **~10ms on CPU** and **~2ms on GPU**. Use it as the first step in your agent pipeline to instantly route to the right tool.
|
| 34 |
+
|
| 35 |
+
## Intent Categories
|
| 36 |
+
|
| 37 |
+
| Label | Description | Example |
|
| 38 |
+
|-------|-------------|---------|
|
| 39 |
+
| `code_generation` | User wants code written, debugged, or refactored | "Write a Python function to parse CSV" |
|
| 40 |
+
| `web_search` | User wants to find information online | "What's the latest news on AI regulation" |
|
| 41 |
+
| `math_calculation` | User needs computation or conversion | "Calculate 15% of 4500" |
|
| 42 |
+
| `file_operation` | User wants to read, write, or manage files | "Read the config.json file" |
|
| 43 |
+
| `api_call` | User wants to interact with an external API | "Send a Slack message to the team" |
|
| 44 |
+
| `creative_writing` | User wants text composed or drafted | "Write a professional email to the client" |
|
| 45 |
+
| `data_analysis` | User wants data interpreted or compared | "Compare React vs Vue performance" |
|
| 46 |
+
| `general_chat` | Casual conversation, greetings, feedback | "Hey, how are you?" |
|
| 47 |
+
|
| 48 |
+
## Quick Start
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
from transformers import pipeline
|
| 52 |
+
|
| 53 |
+
router = pipeline("text-classification", model="tripathyShaswata/AgentIntentRouter")
|
| 54 |
+
|
| 55 |
+
# Single prediction
|
| 56 |
+
result = router("Write a Python function to sort a list")
|
| 57 |
+
print(result)
|
| 58 |
+
# [{'label': 'code_generation', 'score': 0.98}]
|
| 59 |
+
|
| 60 |
+
# Batch prediction
|
| 61 |
+
messages = [
|
| 62 |
+
"Search for the latest AI papers",
|
| 63 |
+
"What's 25% of 1200?",
|
| 64 |
+
"Draft an email to my boss about the deadline",
|
| 65 |
+
"Hello!",
|
| 66 |
+
]
|
| 67 |
+
results = router(messages)
|
| 68 |
+
for msg, res in zip(messages, results):
|
| 69 |
+
print(f" {res['label']:>20} ({res['score']:.2f}) — {msg}")
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
## Use as Agent Router
|
| 73 |
+
|
| 74 |
+
```python
|
| 75 |
+
from transformers import pipeline
|
| 76 |
+
|
| 77 |
+
router = pipeline("text-classification", model="tripathyShaswata/AgentIntentRouter")
|
| 78 |
+
|
| 79 |
+
TOOL_MAP = {
|
| 80 |
+
"code_generation": handle_code_request,
|
| 81 |
+
"web_search": handle_search,
|
| 82 |
+
"math_calculation": handle_calculation,
|
| 83 |
+
"file_operation": handle_file_ops,
|
| 84 |
+
"api_call": handle_api_call,
|
| 85 |
+
"creative_writing": handle_writing,
|
| 86 |
+
"data_analysis": handle_analysis,
|
| 87 |
+
"general_chat": handle_chat,
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
def route(user_message: str):
|
| 91 |
+
intent = router(user_message)[0]
|
| 92 |
+
|
| 93 |
+
if intent["score"] < 0.5:
|
| 94 |
+
# Low confidence — fall back to LLM for routing
|
| 95 |
+
return fallback_llm_route(user_message)
|
| 96 |
+
|
| 97 |
+
handler = TOOL_MAP[intent["label"]]
|
| 98 |
+
return handler(user_message)
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
## Performance
|
| 102 |
+
|
| 103 |
+
- **Inference speed:** ~10ms on CPU, ~2ms on GPU
|
| 104 |
+
- **Model size:** ~260MB (DistilBERT-base)
|
| 105 |
+
- **Accuracy:** 100% on test set
|
| 106 |
+
|
| 107 |
+
### Evaluation Results
|
| 108 |
+
|
| 109 |
+
*Results on held-out test set (1,124 examples):*
|
| 110 |
+
|
| 111 |
+
| Metric | Score |
|
| 112 |
+
|--------|-------|
|
| 113 |
+
| Accuracy | 1.000 |
|
| 114 |
+
| F1 (weighted) | 1.000 |
|
| 115 |
+
|
| 116 |
+
*Per-class performance:*
|
| 117 |
+
|
| 118 |
+
| Intent | Precision | Recall | F1 | Support |
|
| 119 |
+
|--------|-----------|--------|-----|---------|
|
| 120 |
+
| code_generation | 1.000 | 1.000 | 1.000 | 130 |
|
| 121 |
+
| web_search | 1.000 | 1.000 | 1.000 | 151 |
|
| 122 |
+
| math_calculation | 1.000 | 1.000 | 1.000 | 153 |
|
| 123 |
+
| file_operation | 1.000 | 1.000 | 1.000 | 154 |
|
| 124 |
+
| api_call | 1.000 | 1.000 | 1.000 | 133 |
|
| 125 |
+
| creative_writing | 1.000 | 1.000 | 1.000 | 160 |
|
| 126 |
+
| data_analysis | 1.000 | 1.000 | 1.000 | 168 |
|
| 127 |
+
| general_chat | 1.000 | 1.000 | 1.000 | 75 |
|
| 128 |
+
|
| 129 |
+
> **Note:** These results are on synthetic test data from the same distribution as training. Real-world performance will vary. Use the confidence score threshold to handle ambiguous inputs gracefully.
|
| 130 |
+
|
| 131 |
+
## Training Details
|
| 132 |
+
|
| 133 |
+
- **Base model:** distilbert-base-uncased
|
| 134 |
+
- **Training data:** 8,987 examples (synthetic, template-generated with natural language variation)
|
| 135 |
+
- **Validation:** 1,123 examples
|
| 136 |
+
- **Test:** 1,124 examples
|
| 137 |
+
- **Epochs:** 3 (with early stopping, patience=2)
|
| 138 |
+
- **Learning rate:** 2e-5
|
| 139 |
+
- **Batch size:** 32
|
| 140 |
+
- **Max sequence length:** 128
|
| 141 |
+
- **Training time:** ~100 seconds on NVIDIA RTX 4070
|
| 142 |
+
- **Loss:** 0.0015 (training) / 0.0017 (validation)
|
| 143 |
+
|
| 144 |
+
## Limitations
|
| 145 |
+
|
| 146 |
+
- Trained on English text only
|
| 147 |
+
- Template-generated training data may not cover all edge cases
|
| 148 |
+
- Ambiguous messages (e.g., "help me with the API code") may get lower confidence scores — use the confidence threshold to fall back to an LLM
|
| 149 |
+
- Not designed for multi-intent messages (e.g., "search for X and write code for Y")
|
| 150 |
+
|
| 151 |
+
## License
|
| 152 |
+
|
| 153 |
+
Apache 2.0 — use it however you want, commercial included.
|
| 154 |
+
|
| 155 |
+
## Citation
|
| 156 |
+
|
| 157 |
+
If you use this model, a star on the repo is appreciated!
|
config.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"activation": "gelu",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"DistilBertForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_dropout": 0.1,
|
| 7 |
+
"bos_token_id": null,
|
| 8 |
+
"dim": 768,
|
| 9 |
+
"dropout": 0.1,
|
| 10 |
+
"dtype": "float32",
|
| 11 |
+
"eos_token_id": null,
|
| 12 |
+
"hidden_dim": 3072,
|
| 13 |
+
"id2label": {
|
| 14 |
+
"0": "code_generation",
|
| 15 |
+
"1": "web_search",
|
| 16 |
+
"2": "math_calculation",
|
| 17 |
+
"3": "file_operation",
|
| 18 |
+
"4": "api_call",
|
| 19 |
+
"5": "creative_writing",
|
| 20 |
+
"6": "data_analysis",
|
| 21 |
+
"7": "general_chat"
|
| 22 |
+
},
|
| 23 |
+
"initializer_range": 0.02,
|
| 24 |
+
"label2id": {
|
| 25 |
+
"api_call": 4,
|
| 26 |
+
"code_generation": 0,
|
| 27 |
+
"creative_writing": 5,
|
| 28 |
+
"data_analysis": 6,
|
| 29 |
+
"file_operation": 3,
|
| 30 |
+
"general_chat": 7,
|
| 31 |
+
"math_calculation": 2,
|
| 32 |
+
"web_search": 1
|
| 33 |
+
},
|
| 34 |
+
"max_position_embeddings": 512,
|
| 35 |
+
"model_type": "distilbert",
|
| 36 |
+
"n_heads": 12,
|
| 37 |
+
"n_layers": 6,
|
| 38 |
+
"pad_token_id": 0,
|
| 39 |
+
"problem_type": "single_label_classification",
|
| 40 |
+
"qa_dropout": 0.1,
|
| 41 |
+
"seq_classif_dropout": 0.2,
|
| 42 |
+
"sinusoidal_pos_embds": false,
|
| 43 |
+
"tie_weights_": true,
|
| 44 |
+
"tie_word_embeddings": true,
|
| 45 |
+
"transformers_version": "5.5.3",
|
| 46 |
+
"use_cache": false,
|
| 47 |
+
"vocab_size": 30522
|
| 48 |
+
}
|
label_mapping.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"labels": [
|
| 3 |
+
"code_generation",
|
| 4 |
+
"web_search",
|
| 5 |
+
"math_calculation",
|
| 6 |
+
"file_operation",
|
| 7 |
+
"api_call",
|
| 8 |
+
"creative_writing",
|
| 9 |
+
"data_analysis",
|
| 10 |
+
"general_chat"
|
| 11 |
+
],
|
| 12 |
+
"label2id": {
|
| 13 |
+
"code_generation": 0,
|
| 14 |
+
"web_search": 1,
|
| 15 |
+
"math_calculation": 2,
|
| 16 |
+
"file_operation": 3,
|
| 17 |
+
"api_call": 4,
|
| 18 |
+
"creative_writing": 5,
|
| 19 |
+
"data_analysis": 6,
|
| 20 |
+
"general_chat": 7
|
| 21 |
+
},
|
| 22 |
+
"id2label": {
|
| 23 |
+
"0": "code_generation",
|
| 24 |
+
"1": "web_search",
|
| 25 |
+
"2": "math_calculation",
|
| 26 |
+
"3": "file_operation",
|
| 27 |
+
"4": "api_call",
|
| 28 |
+
"5": "creative_writing",
|
| 29 |
+
"6": "data_analysis",
|
| 30 |
+
"7": "general_chat"
|
| 31 |
+
}
|
| 32 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2860c1008d96d52d06405b41a62cd0327f4a40828f06b2987c0caec1ec161292
|
| 3 |
+
size 267851024
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"cls_token": "[CLS]",
|
| 4 |
+
"do_lower_case": true,
|
| 5 |
+
"is_local": false,
|
| 6 |
+
"mask_token": "[MASK]",
|
| 7 |
+
"model_max_length": 512,
|
| 8 |
+
"pad_token": "[PAD]",
|
| 9 |
+
"sep_token": "[SEP]",
|
| 10 |
+
"strip_accents": null,
|
| 11 |
+
"tokenize_chinese_chars": true,
|
| 12 |
+
"tokenizer_class": "BertTokenizer",
|
| 13 |
+
"unk_token": "[UNK]"
|
| 14 |
+
}
|