Text Generation
Transformers
Safetensors
English
qwen3
agents
tool-use
customer-service
reinforcement-learning
grpo
tau2-bench
conversational
text-generation-inference
Instructions to use JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2") model = AutoModelForCausalLM.from_pretrained("JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2
- SGLang
How to use JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2 with Docker Model Runner:
docker model run hf.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2
Update model card
Browse files
README.md
CHANGED
|
@@ -25,41 +25,83 @@ tags:
|
|
| 25 |
|
| 26 |
**Code** [github.com/JaspinXu/KnowWhenToHandOff](https://github.com/JaspinXu/KnowWhenToHandOff) · **Data** [KnowWhenToHandOff-data](https://huggingface.co/datasets/JaspinXu/KnowWhenToHandOff-data) · **Family** [SFT](https://huggingface.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-SFT) · [R1](https://huggingface.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1) · [R2](https://huggingface.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2)
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
## Quick start
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
```python
|
| 36 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 37 |
|
| 38 |
repo = "JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2"
|
| 39 |
tokenizer = AutoTokenizer.from_pretrained(repo)
|
| 40 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
"
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
messages = [
|
| 48 |
-
{"role": "system", "content": "<
|
| 49 |
-
{"role": "user", "content": "I need
|
| 50 |
]
|
| 51 |
-
inputs = tokenizer.apply_chat_template(
|
|
|
|
|
|
|
|
|
|
| 52 |
output = model.generate(inputs, max_new_tokens=512)
|
| 53 |
print(tokenizer.decode(output[0][inputs.shape[-1]:], skip_special_tokens=True))
|
| 54 |
```
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
```bash
|
| 59 |
-
vllm serve JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2
|
|
|
|
| 60 |
```
|
| 61 |
|
| 62 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
- Base model: Qwen/Qwen3-4B-Instruct-2507 (revision
|
| 65 |
`cdbee75f17c01a7cc42f958dc650907174af0554`), Apache-2.0.
|
|
@@ -70,17 +112,6 @@ vllm serve JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2 --enable-auto-tool-choice --to
|
|
| 70 |
`fc0055dc4e0a316c3f83133267fbd6faaa770992`; all sources in
|
| 71 |
[reports/main/sources.json](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/sources.json).
|
| 72 |
|
| 73 |
-
## Model family
|
| 74 |
-
|
| 75 |
-
| Model | Training | Hand-off F1 | Over-escalation | Use it for |
|
| 76 |
-
| --- | --- | --- | --- | --- |
|
| 77 |
-
| [SFT (B2)](https://huggingface.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-SFT) | LoRA SFT on 790 filtered teacher dialogues | 0.768 | 0.016 | starting point; precise but misses hand-offs |
|
| 78 |
-
| [R1](https://huggingface.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1) | GRPO from B2, task reward only | 0.802 | 0.462 | studying the outcome-reward loophole |
|
| 79 |
-
| [R2](https://huggingface.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2) | GRPO from B2, task reward + violation and hand-off penalties | **0.812** | 0.103 | the best-calibrated hand-off model |
|
| 80 |
-
|
| 81 |
-
Task success on the official test tasks is the same for all three within
|
| 82 |
-
noise (0.33–0.35).
|
| 83 |
-
|
| 84 |
## Intended use
|
| 85 |
|
| 86 |
Studying when a tool-using customer-service agent should hand off to a human,
|
|
@@ -95,22 +126,6 @@ requests for a human, out-of-scope requests, hard negatives); the user
|
|
| 95 |
simulator is Qwen3-30B-A3B-Instruct-2507. No real user data. Test tasks were
|
| 96 |
never used for training or selection.
|
| 97 |
|
| 98 |
-
## Evaluation
|
| 99 |
-
|
| 100 |
-
Test split, protocol frozen in [ADR-005](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/docs/adr/ADR-005-evaluation-protocol.md); 95 % bootstrap intervals over tasks.
|
| 101 |
-
|
| 102 |
-
| Metric | This model | B2 (SFT start) | Source |
|
| 103 |
-
| --- | --- | --- | --- |
|
| 104 |
-
| Success (pass^1), test_main | 0.342 [0.245, 0.449] | 0.327 [0.224, 0.434] | [main table](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/main_table.md) |
|
| 105 |
-
| Paired Δ success vs B2 | +0.015 [−0.056, 0.082] | — | [paired differences](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/paired_differences.md) |
|
| 106 |
-
| pass^4 | 0.122 [0.041, 0.224] | 0.102 [0.041, 0.204] | [main table](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/main_table.md) |
|
| 107 |
-
| Violation rate (incl. off-reference writes) | 0.444 | 0.469 | same |
|
| 108 |
-
| Hand-off F1 / precision / recall, test_handoff | **0.812** / 0.886 / 0.750 | 0.768 / 0.976 / 0.633 | [`R2-final-test_handoff-s0-20261007`](https://huggingface.co/datasets/JaspinXu/KnowWhenToHandOff-data/blob/main/runs/R2-final-test_handoff-s0-20261007/metrics.json) |
|
| 109 |
-
| Over-escalation, test_handoff | 0.103 | 0.016 | same |
|
| 110 |
-
| Worst-style success / style gap | 0.316 / 0.112 | 0.327 / 0.112 | [styles](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/styles.md) |
|
| 111 |
-
|
| 112 |
-
**Known behaviour.** R2 removes R1's over-escalation but sometimes makes the opposite error on out-of-scope requests: it refuses and tells the user to contact the company directly without calling the transfer tool, or substitutes an unrelated write (under-escalation 0.25). Once it justified a hand-off with a policy that does not exist.
|
| 113 |
-
|
| 114 |
## Limitations
|
| 115 |
|
| 116 |
- One user simulator (Qwen3-30B-A3B-Instruct-2507, which also generated the
|
|
|
|
| 25 |
|
| 26 |
**Code** [github.com/JaspinXu/KnowWhenToHandOff](https://github.com/JaspinXu/KnowWhenToHandOff) · **Data** [KnowWhenToHandOff-data](https://huggingface.co/datasets/JaspinXu/KnowWhenToHandOff-data) · **Family** [SFT](https://huggingface.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-SFT) · [R1](https://huggingface.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1) · [R2](https://huggingface.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2)
|
| 27 |
|
| 28 |
+
**R2** is Qwen3-4B-Instruct-2507 trained with SFT and then multi-turn GRPO on the τ²-bench airline and retail domains, with a reward that adds penalties for rule violations, unnecessary hand-offs and missed hand-offs. It has the best hand-off F1 of the study (0.812) with 10 % over-escalation, at the same task success as its SFT starting point.
|
| 29 |
+
|
| 30 |
+
## Model family
|
| 31 |
+
|
| 32 |
+
| Model | Training | Hand-off F1 | Over-escalation | Use it for |
|
| 33 |
+
| --- | --- | --- | --- | --- |
|
| 34 |
+
| [SFT (B2)](https://huggingface.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-SFT) | LoRA SFT on 790 filtered teacher dialogues | 0.768 | 0.016 | starting point; precise but misses hand-offs |
|
| 35 |
+
| [R1](https://huggingface.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1) | GRPO from B2, task reward only | 0.802 | 0.462 | studying the outcome-reward loophole |
|
| 36 |
+
| [R2](https://huggingface.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2) | GRPO from B2, task reward + violation and hand-off penalties | **0.812** | 0.103 | the best-calibrated hand-off model |
|
| 37 |
+
|
| 38 |
+
Task success on the official test tasks is the same for all three within
|
| 39 |
+
noise (0.33–0.35).
|
| 40 |
+
|
| 41 |
## Quick start
|
| 42 |
|
| 43 |
+
A standard Qwen3 chat model with tool calling. It was trained with the
|
| 44 |
+
τ²-bench domain policy as the system prompt and the domain's tools, including
|
| 45 |
+
`transfer_to_human_agents`; for faithful behaviour run it inside the evaluation
|
| 46 |
+
harness of the [code repository](https://github.com/JaspinXu/KnowWhenToHandOff).
|
| 47 |
|
| 48 |
```python
|
| 49 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 50 |
|
| 51 |
repo = "JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2"
|
| 52 |
tokenizer = AutoTokenizer.from_pretrained(repo)
|
| 53 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 54 |
+
repo, torch_dtype="auto", device_map="auto"
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
transfer = {
|
| 58 |
+
"type": "function",
|
| 59 |
+
"function": {
|
| 60 |
+
"name": "transfer_to_human_agents",
|
| 61 |
+
"description": "Transfer the user to a human agent.",
|
| 62 |
+
"parameters": {
|
| 63 |
+
"type": "object",
|
| 64 |
+
"properties": {"summary": {"type": "string"}},
|
| 65 |
+
"required": ["summary"],
|
| 66 |
+
},
|
| 67 |
+
},
|
| 68 |
+
}
|
| 69 |
messages = [
|
| 70 |
+
{"role": "system", "content": "<airline or retail policy>"},
|
| 71 |
+
{"role": "user", "content": "I need the unaccompanied-minor service."},
|
| 72 |
]
|
| 73 |
+
inputs = tokenizer.apply_chat_template(
|
| 74 |
+
messages, tools=[transfer], add_generation_prompt=True,
|
| 75 |
+
return_tensors="pt",
|
| 76 |
+
).to(model.device)
|
| 77 |
output = model.generate(inputs, max_new_tokens=512)
|
| 78 |
print(tokenizer.decode(output[0][inputs.shape[-1]:], skip_special_tokens=True))
|
| 79 |
```
|
| 80 |
|
| 81 |
+
Serve it with vLLM (OpenAI-compatible API, tool calls parsed):
|
| 82 |
|
| 83 |
```bash
|
| 84 |
+
vllm serve JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2 \
|
| 85 |
+
--enable-auto-tool-choice --tool-call-parser hermes
|
| 86 |
```
|
| 87 |
|
| 88 |
+
## Evaluation
|
| 89 |
+
|
| 90 |
+
Test split, protocol frozen in [ADR-005](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/docs/adr/ADR-005-evaluation-protocol.md); 95 % bootstrap intervals over tasks.
|
| 91 |
+
|
| 92 |
+
| Metric | This model | B2 (SFT start) | Source |
|
| 93 |
+
| --- | --- | --- | --- |
|
| 94 |
+
| Success (pass^1), test_main | 0.342 [0.245, 0.449] | 0.327 [0.224, 0.434] | [main table](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/main_table.md) |
|
| 95 |
+
| Paired Δ success vs B2 | +0.015 [−0.056, 0.082] | — | [paired differences](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/paired_differences.md) |
|
| 96 |
+
| pass^4 | 0.122 [0.041, 0.224] | 0.102 [0.041, 0.204] | [main table](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/main_table.md) |
|
| 97 |
+
| Violation rate (incl. off-reference writes) | 0.444 | 0.469 | same |
|
| 98 |
+
| Hand-off F1 / precision / recall, test_handoff | **0.812** / 0.886 / 0.750 | 0.768 / 0.976 / 0.633 | [`R2-final-test_handoff-s0-20261007`](https://huggingface.co/datasets/JaspinXu/KnowWhenToHandOff-data/blob/main/runs/R2-final-test_handoff-s0-20261007/metrics.json) |
|
| 99 |
+
| Over-escalation, test_handoff | 0.103 | 0.016 | same |
|
| 100 |
+
| Worst-style success / style gap | 0.316 / 0.112 | 0.327 / 0.112 | [styles](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/styles.md) |
|
| 101 |
+
|
| 102 |
+
**Known behaviour.** R2 removes R1's over-escalation but sometimes makes the opposite error on out-of-scope requests: it refuses and tells the user to contact the company directly without calling the transfer tool, or substitutes an unrelated write (under-escalation 0.25). Once it justified a hand-off with a policy that does not exist.
|
| 103 |
+
|
| 104 |
+
## Training details
|
| 105 |
|
| 106 |
- Base model: Qwen/Qwen3-4B-Instruct-2507 (revision
|
| 107 |
`cdbee75f17c01a7cc42f958dc650907174af0554`), Apache-2.0.
|
|
|
|
| 112 |
`fc0055dc4e0a316c3f83133267fbd6faaa770992`; all sources in
|
| 113 |
[reports/main/sources.json](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/sources.json).
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
## Intended use
|
| 116 |
|
| 117 |
Studying when a tool-using customer-service agent should hand off to a human,
|
|
|
|
| 126 |
simulator is Qwen3-30B-A3B-Instruct-2507. No real user data. Test tasks were
|
| 127 |
never used for training or selection.
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
## Limitations
|
| 130 |
|
| 131 |
- One user simulator (Qwen3-30B-A3B-Instruct-2507, which also generated the
|