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
|
@@ -23,21 +23,64 @@ tags:
|
|
| 23 |
> simulated users on a public benchmark. It has not been tested with real
|
| 24 |
> customers, real data or real business systems.
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
## Model
|
| 30 |
|
| 31 |
- Base model: Qwen/Qwen3-4B-Instruct-2507 (revision
|
| 32 |
`cdbee75f17c01a7cc42f958dc650907174af0554`), Apache-2.0.
|
| 33 |
-
- Training: GRPO from the SFT checkpoint B2 with the composite reward (`configs/reward/r2.yaml`: task reward − 0.25 × weighted violations − 0.5 × unneeded transfer − 1.0 × missed transfer − 0.1 × format errors); LoRA rank 64, alpha 128, lr 1e-5; 8 tasks × 8 rollouts per step, 60 steps, no KL term.
|
| 34 |
- Training run `R2-s1-20261006` (seed 1); exported step-60 checkpoint
|
| 35 |
-
`sha256:be6198a0c51773f52ba4f20c9605a5931f23b0206e92a9fe0521a93761348c96` (
|
| 36 |
-
format).
|
| 37 |
- Evaluation code at git `462b5d17b4e9add637a2ee7802974c720b625a5b`; τ²-bench
|
| 38 |
`fc0055dc4e0a316c3f83133267fbd6faaa770992`; all sources in
|
| 39 |
[reports/main/sources.json](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/sources.json).
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
## Intended use
|
| 42 |
|
| 43 |
Studying when a tool-using customer-service agent should hand off to a human,
|
|
@@ -54,17 +97,17 @@ never used for training or selection.
|
|
| 54 |
|
| 55 |
## Evaluation
|
| 56 |
|
| 57 |
-
Test split, protocol frozen in ADR-005; 95 % bootstrap intervals over tasks.
|
| 58 |
|
| 59 |
| Metric | This model | B2 (SFT start) | Source |
|
| 60 |
| --- | --- | --- | --- |
|
| 61 |
-
| Success (pass^1), test_main | 0.342 [0.245, 0.449] | 0.327 [0.224, 0.434] |
|
| 62 |
-
| Paired Δ success vs B2 | +0.015 [−0.056, 0.082] | — |
|
| 63 |
-
| pass^4 | 0.122 [0.041, 0.224] | 0.102 [0.041, 0.204] |
|
| 64 |
| Violation rate (incl. off-reference writes) | 0.444 | 0.469 | same |
|
| 65 |
-
| 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`
|
| 66 |
| Over-escalation, test_handoff | 0.103 | 0.016 | same |
|
| 67 |
-
| Worst-style success / style gap | 0.316 / 0.112 | 0.327 / 0.112 |
|
| 68 |
|
| 69 |
**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.
|
| 70 |
|
|
@@ -91,3 +134,15 @@ its Apache-2.0 licence. τ²-bench code and data (pinned commit
|
|
| 91 |
its `LICENSE` file;
|
| 92 |
released dialogue samples are τ²-bench-derived synthetic conversations with
|
| 93 |
no real user data.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
> simulated users on a public benchmark. It has not been tested with real
|
| 24 |
> customers, real data or real business systems.
|
| 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 |
+
The model is a standard Qwen3 chat model with tool calling. It was trained with
|
| 31 |
+
the τ²-bench domain policy as the system prompt and the domain's tools,
|
| 32 |
+
including `transfer_to_human_agents`; for faithful behaviour run it inside the
|
| 33 |
+
evaluation harness of the [code repository](https://github.com/JaspinXu/KnowWhenToHandOff).
|
| 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(repo, torch_dtype="auto", device_map="auto")
|
| 41 |
+
|
| 42 |
+
tools = [{"type": "function", "function": {
|
| 43 |
+
"name": "transfer_to_human_agents",
|
| 44 |
+
"description": "Transfer the user to a human agent with a summary of the issue.",
|
| 45 |
+
"parameters": {"type": "object", "properties": {"summary": {"type": "string"}}, "required": ["summary"]},
|
| 46 |
+
}}]
|
| 47 |
+
messages = [
|
| 48 |
+
{"role": "system", "content": "<the airline or retail policy from tau2-bench>"},
|
| 49 |
+
{"role": "user", "content": "I need to book the unaccompanied-minor escort service for my child."},
|
| 50 |
+
]
|
| 51 |
+
inputs = tokenizer.apply_chat_template(messages, tools=tools, add_generation_prompt=True, return_tensors="pt").to(model.device)
|
| 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 |
+
Serving with vLLM (OpenAI-compatible, tool calls parsed):
|
| 57 |
+
|
| 58 |
+
```bash
|
| 59 |
+
vllm serve JaspinXu/KnowWhenToHandOff-Qwen3-4B-R2 --enable-auto-tool-choice --tool-call-parser hermes
|
| 60 |
+
```
|
| 61 |
|
| 62 |
## Model
|
| 63 |
|
| 64 |
- Base model: Qwen/Qwen3-4B-Instruct-2507 (revision
|
| 65 |
`cdbee75f17c01a7cc42f958dc650907174af0554`), Apache-2.0.
|
| 66 |
+
- Training: GRPO from the SFT checkpoint B2 with the composite reward ([`configs/reward/r2.yaml`](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/configs/reward/r2.yaml): task reward − 0.25 × weighted violations − 0.5 × unneeded transfer − 1.0 × missed transfer − 0.1 × format errors); LoRA rank 64, alpha 128, lr 1e-5; 8 tasks × 8 rollouts per step, 60 steps, no KL term.
|
| 67 |
- Training run `R2-s1-20261006` (seed 1); exported step-60 checkpoint
|
| 68 |
+
`sha256:be6198a0c51773f52ba4f20c9605a5931f23b0206e92a9fe0521a93761348c96` (merged bf16, Hugging Face format).
|
|
|
|
| 69 |
- Evaluation code at git `462b5d17b4e9add637a2ee7802974c720b625a5b`; τ²-bench
|
| 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,
|
|
|
|
| 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 |
|
|
|
|
| 134 |
its `LICENSE` file;
|
| 135 |
released dialogue samples are τ²-bench-derived synthetic conversations with
|
| 136 |
no real user data.
|
| 137 |
+
|
| 138 |
+
## Citation
|
| 139 |
+
|
| 140 |
+
```bibtex
|
| 141 |
+
@misc{knowwhentohandoff2026,
|
| 142 |
+
title = {Know When to Hand Off: Multi-turn Reinforcement Learning for
|
| 143 |
+
Trustworthy Customer-Service Agents},
|
| 144 |
+
author = {{KnowWhenToHandOff contributors}},
|
| 145 |
+
year = {2026},
|
| 146 |
+
howpublished = {\url{https://github.com/JaspinXu/KnowWhenToHandOff}}
|
| 147 |
+
}
|
| 148 |
+
```
|