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-R1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1") 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-R1") model = AutoModelForCausalLM.from_pretrained("JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1", 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-R1 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-R1" # 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-R1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1
- SGLang
How to use JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1 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-R1" \ --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-R1", "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-R1" \ --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-R1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1 with Docker Model Runner:
docker model run hf.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1
Update model card
Browse files24 unmodified lines25262728293031323334353637383940414243444546474849505152535455565758596061626364654 unmodified lines70717273747576777879808182838485868 unmodified lines959697989910010110210310410510610710810911011111211311411511624 unmodified lines**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)## Quick startThe model is a standard Qwen3 chat model with tool calling. It was trained withthe τ²-bench domain policy as the system prompt and the domain's tools,including `transfer_to_human_agents`; for faithful behaviour run it inside theevaluation harness of the [code repository](https://github.com/JaspinXu/KnowWhenToHandOff).```pythonfrom transformers import AutoModelForCausalLM, AutoTokenizerrepo = "JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1"tokenizer = AutoTokenizer.from_pretrained(repo)model = AutoModelForCausalLM.from_pretrained(repo, torch_dtype="auto", device_map="auto")tools = [{"type": "function", "function": {"name": "transfer_to_human_agents","description": "Transfer the user to a human agent with a summary of the issue.","parameters": {"type": "object", "properties": {"summary": {"type": "string"}}, "required": ["summary"]},}}]messages = [{"role": "system", "content": "<the airline or retail policy from tau2-bench>"},{"role": "user", "content": "I need to book the unaccompanied-minor escort service for my child."},]inputs = tokenizer.apply_chat_template(messages, tools=tools, add_generation_prompt=True, return_tensors="pt").to(model.device)output = model.generate(inputs, max_new_tokens=512)print(tokenizer.decode(output[0][inputs.shape[-1]:], skip_special_tokens=True))```Serving with vLLM (OpenAI-compatible, tool calls parsed):```bashvllm serve JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1 --enable-auto-tool-choice --tool-call-parser hermes```## Model- Base model: Qwen/Qwen3-4B-Instruct-2507 (revision`cdbee75f17c01a7cc42f958dc650907174af0554`), Apache-2.0.4 unmodified lines`fc0055dc4e0a316c3f83133267fbd6faaa770992`; all sources in[reports/main/sources.json](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/sources.json).## Model family| Model | Training | Hand-off F1 | Over-escalation | Use it for || --- | --- | --- | --- | --- || [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 || [R1](https://huggingface.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1) | GRPO from B2, task reward only | 0.802 | 0.462 | studying the outcome-reward loophole || [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 |Task success on the official test tasks is the same for all three withinnoise (0.33–0.35).## Intended useStudying when a tool-using customer-service agent should hand off to a human,8 unmodified linessimulator is Qwen3-30B-A3B-Instruct-2507. No real user data. Test tasks werenever used for training or selection.## EvaluationTest 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.| Metric | This model | B2 (SFT start) | Source || --- | --- | --- | --- || Success (pass^1), test_main | 0.347 [0.235, 0.459] | 0.327 [0.224, 0.434] | [main table](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/main_table.md) || Paired Δ success vs B2 | +0.020 [−0.066, 0.107] | — | [paired differences](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/paired_differences.md) || pass^4 | 0.224 [0.102, 0.347] | 0.102 [0.041, 0.204] | [main table](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/main_table.md) || Violation rate (incl. off-reference writes) | 0.327 | 0.469 | same || Hand-off F1 / precision / recall, test_handoff | 0.802 / 0.689 / 0.959 | 0.768 / 0.976 / 0.633 | [`R1-final-test_handoff-s0-20261006`](https://huggingface.co/datasets/JaspinXu/KnowWhenToHandOff-data/blob/main/runs/R1-final-test_handoff-s0-20261006/metrics.json) || Over-escalation, test_handoff | **0.462** | 0.016 | same || Worst-style success / style gap | 0.286 / 0.102 | 0.327 / 0.112 | [styles](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/styles.md) |**Known behaviour.** This checkpoint over-escalates: it transfers almost half of the users who did not need a human, usually right after the account lookup and without explaining why (citation rate 0.06). Under the task-only reward a transfer scores 1.0 whenever the reference solution makes no database change, so "transfer when unsure" was learned in the last 20 steps (step 40 had over-escalation 0.141). Use R2 for hand-off studies.## Limitations- One user simulator (Qwen3-30B-A3B-Instruct-2507, which also generated the24 unmodified lines2526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061074 unmodified lines1121131141151161178 unmodified lines12612712812913013124 unmodified lines**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)**R1** is the same recipe as R2 but trained on τ²-bench's task reward only. It reaches a similar hand-off F1 (0.802) by transferring almost half of the users who did not need a human (46 % over-escalation): an outcome-reward loophole, released as a case study rather than as a model to use.## Model family| Model | Training | Hand-off F1 | Over-escalation | Use it for || --- | --- | --- | --- | --- || [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 || [R1](https://huggingface.co/JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1) | GRPO from B2, task reward only | 0.802 | 0.462 | studying the outcome-reward loophole || [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 |Task success on the official test tasks is the same for all three withinnoise (0.33–0.35).## Quick startA standard Qwen3 chat model with tool calling. It was trained with theτ²-bench domain policy as the system prompt and the domain's tools, including`transfer_to_human_agents`; for faithful behaviour run it inside the evaluationharness of the [code repository](https://github.com/JaspinXu/KnowWhenToHandOff).```pythonfrom transformers import AutoModelForCausalLM, AutoTokenizerrepo = "JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1"tokenizer = AutoTokenizer.from_pretrained(repo)model = AutoModelForCausalLM.from_pretrained(repo, torch_dtype="auto", device_map="auto")transfer = {"type": "function","function": {"name": "transfer_to_human_agents","description": "Transfer the user to a human agent.","parameters": {"type": "object","properties": {"summary": {"type": "string"}},"required": ["summary"],},},}messages = [{"role": "system", "content": "<airline or retail policy>"},{"role": "user", "content": "I need the unaccompanied-minor service."},]inputs = tokenizer.apply_chat_template(messages, tools=[transfer], add_generation_prompt=True,return_tensors="pt",).to(model.device)output = model.generate(inputs, max_new_tokens=512)print(tokenizer.decode(output[0][inputs.shape[-1]:], skip_special_tokens=True))```Serve it with vLLM (OpenAI-compatible API, tool calls parsed):```bashvllm serve JaspinXu/KnowWhenToHandOff-Qwen3-4B-R1 \--enable-auto-tool-choice --tool-call-parser hermes```## EvaluationTest 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.| Metric | This model | B2 (SFT start) | Source || --- | --- | --- | --- || Success (pass^1), test_main | 0.347 [0.235, 0.459] | 0.327 [0.224, 0.434] | [main table](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/main_table.md) || Paired Δ success vs B2 | +0.020 [−0.066, 0.107] | — | [paired differences](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/paired_differences.md) || pass^4 | 0.224 [0.102, 0.347] | 0.102 [0.041, 0.204] | [main table](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/main_table.md) || Violation rate (incl. off-reference writes) | 0.327 | 0.469 | same || Hand-off F1 / precision / recall, test_handoff | 0.802 / 0.689 / 0.959 | 0.768 / 0.976 / 0.633 | [`R1-final-test_handoff-s0-20261006`](https://huggingface.co/datasets/JaspinXu/KnowWhenToHandOff-data/blob/main/runs/R1-final-test_handoff-s0-20261006/metrics.json) || Over-escalation, test_handoff | **0.462** | 0.016 | same || Worst-style success / style gap | 0.286 / 0.102 | 0.327 / 0.112 | [styles](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/styles.md) |**Known behaviour.** This checkpoint over-escalates: it transfers almost half of the users who did not need a human, usually right after the account lookup and without explaining why (citation rate 0.06). Under the task-only reward a transfer scores 1.0 whenever the reference solution makes no database change, so "transfer when unsure" was learned in the last 20 steps (step 40 had over-escalation 0.141). Use R2 for hand-off studies.## Training details- Base model: Qwen/Qwen3-4B-Instruct-2507 (revision`cdbee75f17c01a7cc42f958dc650907174af0554`), Apache-2.0.4 unmodified lines`fc0055dc4e0a316c3f83133267fbd6faaa770992`; all sources in[reports/main/sources.json](https://github.com/JaspinXu/KnowWhenToHandOff/blob/main/reports/main/sources.json).## Intended useStudying when a tool-using customer-service agent should hand off to a human,8 unmodified linessimulator is Qwen3-30B-A3B-Instruct-2507. No real user data. Test tasks werenever used for training or selection.## Limitations- One user simulator (Qwen3-30B-A3B-Instruct-2507, which also generated the
README.md+59-44