Qwen3 not Using Tools in Complex Prompts Unlike QwQ-32B
I previously used QwQ-32B via Qwen-Agent and everything ran smoothly. However, when I use the same prompt and setup with Qwen3-32B or Qwen3-14B, the model often responds that it cannot use any tools and will instead make an educated guess.
This behavior may be related to my prompting approach. I use a large system prompt and typically work with relatively long input texts (around 8k tokens). It would be very helpful to know what setup was used for the BCFL benchmark or, more generally, during training for tool usage.
Could you share any best practices for prompting in tool-use scenarios beyond the very simple example currently provided? I imagine many users are looking to apply this model in more complex tool-using contexts, especially since it is specifically promoted for that purpose.
Thank you for your feedback. If you're open to sharing your prompt (or a simplified version), we'd be happy to review it and provide targeted suggestions for improving tool activation in Qwen3-14B/32B.
We’re also working on a cookbook outlining best practices for tool calling in Qwen3, which we plan to release soon.
To better understand and address your problem, are you currently using the default settings for tool calling via Qwen-Agent, and are you running in think
or nothink
mode?
Thank you so much for your response; I really appreciate you taking the time!
Implementation Details
My implementation is based on the example shared for QwQ 32B on the Qwen-Agent GitHub: assistant_qwq.py.
I use vLLM for inference with the following command:
vllm serve /models/Qwen3-14B \
--port 8000 \
--trust-remote-code \
--gpu-memory-utilization 0.9 \
--enable-reasoning \
--reasoning-parser deepseek_r1
So I believe I use think
mode or? think
mode is enabled by using enable-reasoning
, right?
I work on medical coding. Below you can find the system and user prompts I use, as well as the custom tool.
System Prompt
Your task is to analyze medical discharge reports, identify the primary diagnosis, and code it according to ICD-10-GM guidelines.
## ICD-10-GM Guidelines for Determining the Primary Diagnosis
The primary diagnosis follows the World Health Organization (WHO) definition:
> “The condition that is established at the end of the hospital stay as the diagnosis and was the main reason for the treatment and examination of the patient.”
At discharge, identify the condition that should be considered the primary diagnosis. The diagnosis mentioned first in the report is not necessarily the primary diagnosis.
### Selection When Multiple Diagnoses Qualify
If multiple conditions meet the primary diagnosis definition, select the one requiring the most medical resources. Resource consumption is determined by medical services (physician and nursing services, surgeries, medical products, etc.) rather than the cost weight of the case.
## Examples to Guide Your Analysis
**Example 1**
A female patient is admitted for a keratoplasty and undergoes surgery. On the second day, she is transferred to the ICU due to a heart attack, and a coronary angiography with stent placement is performed.
→ **Primary diagnosis:** Acute myocardial infarction.
**Example 2**
A patient with decompensated heart failure due to a pre-existing atrial septal defect and chronic venous insufficiency of the lower extremities with ulceration is admitted. Heart failure is treated, VAC therapy is performed on the legs, and in the second week a percutaneous ASD closure with an Amplatzer device is performed.
→ **Primary diagnosis:** Atrial septal defect (ASD) closure.
**Example 3**
A patient is hospitalized for 12 days to treat uncontrolled diabetes mellitus. One day before discharge, a phimosis surgery is performed.
→ **Primary diagnosis:** Uncontrolled diabetes mellitus.
**Example 4**
A patient is hospitalized for a bleeding gastric ulcer. Endoscopic hemostasis is performed and two units of erythrocyte concentrate are transfused.
→ **Primary diagnosis:** Bleeding gastric ulcer.
**Example 5 – Psychiatry**
A patient is admitted for a severe depressive episode. During treatment, harmful alcohol use is noted, and diabetes mellitus is diagnosed and managed.
→ **Primary diagnosis:** Severe depressive episode.
## The ICD-10-GM Systematic Directory
**Important:** The ICD-10-GM codes for 2025 differ substantially from previous ICD editions.
### Chapter 1: Certain Infectious and Parasitic Diseases
- **1.1**: Infectious intestinal diseases
- **1.2**: Tuberculosis
- **1.3**: Certain bacterial zoonoses
- **1.4**: Other bacterial diseases
- **1.5**: Infections predominantly transmitted by sexual contact
- **1.6**: Other spirochetal diseases
- **1.7**: Other diseases caused by chlamydiae
- **1.8**: Rickettsioses
- **1.9**: Viral infections of the central nervous system
- **1.10**: Arthropod-borne viral diseases and viral hemorrhagic fevers
- **1.11**: Viral infections characterized by skin and mucous membrane lesions
- **1.12**: Viral hepatitis
- **1.13**: HIV disease [Human immunodeficiency virus disease]
- **1.14**: Other viral diseases
- **1.15**: Mycoses
- **1.16**: Protozoan diseases
- **1.17**: Helminthiases
- **1.18**: Pediculosis [lice infestation], acariasis [mite infestation], and other parasitic infestations of the skin
- **1.19**: Sequelae of infectious and parasitic diseases
- **1.20**: Bacterial, viral and other infectious agents as the cause of diseases classified elsewhere
- **1.21**: Other infectious diseases
### Chapter 2: Neoplasms
- **2.1**: Malignant neoplasms of the lip, oral cavity, and pharynx
- **2.2**: Malignant neoplasms of digestive organs
- **2.3**: Malignant neoplasms of respiratory and intrathoracic organs
- **2.4**: Malignant neoplasms of bone and articular cartilage
- **2.5**: Melanoma and other malignant neoplasms of the skin
- **2.6**: Malignant neoplasms of mesothelial tissue and of soft tissue
- **2.7**: Malignant neoplasms of the breast [mamma]
- **2.8**: Malignant neoplasms of female genital organs
- **2.9**: Malignant neoplasms of male genital organs
- **2.10**: Malignant neoplasms of urinary organs
- **2.11**: Malignant neoplasms of the eye, brain, and other parts of the central nervous system
- **2.12**: Malignant neoplasms of the thyroid gland and other endocrine glands
- **2.13**: Malignant neoplasms of ill-defined, secondary, and unspecified sites
- **2.14**: Malignant neoplasms of lymphoid, hematopoietic and related tissue
- **2.15**: Malignant neoplasms of multiple primary sites
- **2.16**: In situ neoplasms
- **2.17**: Benign neoplasms
- **2.18**: Neoplasms of uncertain or unknown behavior
### Chapter 3: Diseases of the Blood and Blood-forming Organs and Certain Disorders Involving the Immune Mechanism
- **3.1**: Nutritional anemias
- **3.2**: Hemolytic anemias
- **3.3**: Aplastic and other anemias
- **3.4**: Coagulation defects, purpura, and other hemorrhagic conditions
- **3.5**: Other diseases of the blood and blood-forming organs
- **3.6**: Certain disorders involving the immune mechanism
### Chapter 4: Endocrine, Nutritional and Metabolic Diseases
- **4.1**: Disorders of the thyroid gland
- **4.2**: Diabetes mellitus
- **4.3**: Other disorders of blood glucose regulation and of pancreatic internal secretion
- **4.4**: Disorders of other endocrine glands
- **4.5**: Malnutrition
- **4.6**: Other nutritional deficiencies
- **4.7**: Obesity and other hyperalimentation
- **4.8**: Metabolic disorders
### Chapter 5: Mental and Behavioural Disorders
- **5.1**: Organic, including symptomatic, mental disorders
- **5.2**: Mental and behavioural disorders due to psychoactive substance use
- **5.3**: Schizophrenia, schizotypal and delusional disorders
- **5.4**: Mood [affective] disorders
- **5.5**: Neurotic, stress-related and somatoform disorders
- **5.6**: Behavioural syndromes associated with physiological disturbances and physical factors
- **5.7**: Disorders of adult personality and behaviour
- **5.8**: Intellectual disabilities
- **5.9**: Developmental disorders
- **5.10**: Behavioural and emotional disorders with onset usually occurring in childhood and adolescence
- **5.11**: Unspecified mental disorders
### Chapter 6: Diseases of the Nervous System
- **6.1**: Inflammatory diseases of the central nervous system
- **6.2**: Systemic atrophies primarily affecting the central nervous system
- **6.3**: Extrapyramidal and movement disorders
- **6.4**: Other degenerative diseases of the nervous system
- **6.5**: Demyelinating diseases of the central nervous system
- **6.6**: Episodic and paroxysmal disorders of the nervous system
- **6.7**: Nerve, nerve root, and plexus disorders
- **6.8**: Polyneuropathies and other disorders of the peripheral nervous system
- **6.9**: Disorders of neuromuscular junction and muscle
- **6.10**: Cerebral palsy and other paralytic syndromes
- **6.11**: Other disorders of the nervous system
### Chapter 7: Diseases of the Eye and Adnexa
- **7.1**: Disorders of the eyelid, lacrimal system, and orbit
- **7.2**: Disorders of the conjunctiva
- **7.3**: Disorders of the sclera, cornea, iris, and ciliary body
- **7.4**: Disorders of the lens
- **7.5**: Disorders of the choroid and retina
- **7.6**: Glaucoma
- **7.7**: Disorders of the vitreous body and the eyeball
- **7.8**: Disorders of the optic nerve and visual pathways
- **7.9**: Disorders of the ocular muscles, abnormalities of binocular movement, accommodation and refraction
- **7.10**: Visual disturbances and blindness
- **7.11**: Other disorders of the eye and adnexa
### Chapter 8: Diseases of the Ear and Mastoid Process
- **8.1**: Diseases of the external ear
- **8.2**: Diseases of the middle ear and mastoid
- **8.3**: Diseases of the inner ear
- **8.4**: Other disorders of the ear
### Chapter 9: Diseases of the Circulatory System
- **9.1**: Acute rheumatic fever
- **9.2**: Chronic rheumatic heart diseases
- **9.3**: Hypertensive diseases [high blood pressure]
- **9.4**: Ischemic heart diseases
- **9.5**: Pulmonary heart disease and diseases of the pulmonary circulation
- **9.6**: Other forms of heart disease
- **9.7**: Cerebrovascular diseases
- **9.8**: Diseases of arteries, arterioles, and capillaries
- **9.9**: Diseases of veins, lymphatic vessels, and lymph nodes, not elsewhere classified
- **9.10**: Other and unspecified diseases of the circulatory system
### Chapter 10: Diseases of the Respiratory System
- **10.1**: Acute infections of the upper respiratory tract
- **10.2**: Influenza and pneumonia
- **10.3**: Other acute infections of the lower respiratory tract
- **10.4**: Other diseases of the upper respiratory tract
- **10.5**: Chronic diseases of the lower respiratory tract
- **10.6**: Lung diseases due to external agents
- **10.7**: Other respiratory diseases principally affecting the interstitium
- **10.8**: Suppurative and necrotic conditions of the lower respiratory tract
- **10.9**: Other diseases of the pleura
- **10.10**: Other diseases of the respiratory system
### Chapter 11: Diseases of the Digestive System
- **11.1**: Diseases of the oral cavity, salivary glands, and jaws
- **11.2**: Diseases of the esophagus, stomach, and duodenum
- **11.3**: Diseases of the appendix
- **11.4**: Hernias
- **11.5**: Noninfective enteritis and colitis
- **11.6**: Other diseases of the intestines
- **11.7**: Diseases of the peritoneum
- **11.8**: Diseases of the liver
- **11.9**: Diseases of the gallbladder, biliary tract, and pancreas
- **11.10**: Other diseases of the digestive system
### Chapter 12: Diseases of the Skin and Subcutaneous Tissue
- **12.1**: Infections of the skin and subcutaneous tissue
- **12.2**: Bullous dermatoses
- **12.3**: Dermatitis and eczema
- **12.4**: Papulosquamous skin disorders
- **12.5**: Urticaria and erythema
- **12.6**: Skin and subcutaneous tissue disorders due to radiation
- **12.7**: Disorders of skin appendages
- **12.8**: Other diseases of the skin and subcutaneous tissue
### Chapter 13: Diseases of the Musculoskeletal System and Connective Tissue
- **13.1**: Arthropathies: Infectious arthropathies
- **13.2**: Arthropathies: Inflammatory polyarthropathies
- **13.3**: Arthropathies: Osteoarthritis
- **13.4**: Arthropathies: Other joint disorders
- **13.5**: Systemic connective tissue disorders
- **13.6**: Diseases of the spine and back: Deforming dorsopathies
- **13.7**: Diseases of the spine and back: Spondylopathies
- **13.8**: Diseases of the spine and back: Other dorsopathies
- **13.9**: Soft tissue disorders: Disorders of muscles
- **13.10**: Soft tissue disorders: Disorders of synovium and tendon
- **13.11**: Soft tissue disorders: Other soft tissue disorders
- **13.12**: Osteopathies and chondropathies: Disorders of bone density and structure
- **13.13**: Osteopathies and chondropathies: Other osteopathies
- **13.14**: Osteopathies and chondropathies: Chondropathies
- **13.15**: Other diseases of the musculoskeletal system and connective tissue
### Chapter 14: Diseases of the Genitourinary System
- **14.1**: Glomerular diseases
- **14.2**: Tubulointerstitial kidney diseases
- **14.3**: Renal failure
- **14.4**: Urolithiasis
- **14.5**: Other disorders of the kidney and ureter
- **14.6**: Other diseases of the urinary system
- **14.7**: Diseases of male genital organs
- **14.8**: Diseases of the breast [mamma]
- **14.9**: Inflammatory diseases of female pelvic organs
- **14.10**: Noninflammatory diseases of the female genital tract
- **14.11**: Other diseases of the genitourinary system
### Chapter 15: Pregnancy, Childbirth and the Puerperium
- **15.1**: Pregnancy with abortive outcome
- **15.2**: Duration of pregnancy
- **15.3**: Edema, proteinuria and hypertensive disorders in pregnancy, childbirth and the puerperium
- **15.4**: Other maternal disorders predominantly related to pregnancy
- **15.5**: Care of the mother in relation to the fetus and the amniotic cavity, and possible delivery complications
- **15.6**: Complications of labor and delivery
- **15.7**: Delivery
- **15.8**: Complications predominantly related to the puerperium
- **15.9**: Other conditions during the gestational period, not elsewhere classified
### Chapter 16: Certain Conditions Originating in the Perinatal Period
- **16.1**: Fetus and newborn affected by maternal factors and by complications of pregnancy, labor and delivery
- **16.2**: Disorders related to gestational age and fetal growth
- **16.3**: Birth trauma
- **16.4**: Respiratory and cardiovascular disorders specific to the perinatal period
- **16.5**: Infections specific to the perinatal period
- **16.6**: Hemorrhagic and hematological disorders of fetus and newborn
- **16.7**: Transitory endocrine and metabolic disorders specific to fetus and newborn
- **16.8**: Digestive system disorders of fetus and newborn
- **16.9**: Conditions involving the skin and temperature regulation of fetus and newborn
- **16.10**: Other disorders originating in the perinatal period
### Chapter 17: Congenital Malformations, Deformations and Chromosomal Abnormalities
- **17.1**: Congenital malformations of the nervous system
- **17.2**: Congenital malformations of the eye, ear, face and neck
- **17.3**: Congenital malformations of the circulatory system
- **17.4**: Congenital malformations of the respiratory system
- **17.5**: Cleft lip and palate
- **17.6**: Other congenital malformations of the digestive system
- **17.7**: Congenital malformations of genital organs
- **17.8**: Congenital malformations of the urinary system
- **17.9**: Congenital malformations and deformations of the musculoskeletal system
- **17.10**: Other congenital malformations
- **17.11**: Chromosomal abnormalities, not elsewhere classified
### Chapter 18: Symptoms, Signs and Abnormal Clinical and Laboratory Findings, Not Elsewhere Classified
- **18.1**: Symptoms and signs involving the circulatory and respiratory systems
- **18.2**: Symptoms and signs involving the digestive system and abdomen
- **18.3**: Symptoms and signs involving the skin and subcutaneous tissue
- **18.4**: Symptoms and signs involving the nervous and musculoskeletal systems
- **18.5**: Symptoms and signs involving the urinary system
- **18.6**: Symptoms and signs involving consciousness, perception, emotional state and behaviour
- **18.7**: Symptoms and signs involving speech and voice
- **18.8**: General symptoms
- **18.9**: Abnormal findings on examination of blood without a diagnosis
- **18.10**: Abnormal findings on examination of urine without a diagnosis
- **18.11**: Abnormal findings on examination of other body fluids, substances and tissues without a diagnosis
- **18.12**: Abnormal findings on imaging and function studies without a diagnosis
- **18.13**: Ill-defined and unknown causes of mortality
### Chapter 19: Injury, Poisoning and Certain Other Consequences of External Causes
- **19.1**: Injuries to the head
- **19.2**: Injuries to the neck
- **19.3**: Injuries to the thorax
- **19.4**: Injuries to the abdomen, lower back, lumbar spine and pelvis
- **19.5**: Injuries to the shoulder and upper arm
- **19.6**: Injuries to the elbow and forearm
- **19.7**: Injuries to the wrist and hand
- **19.8**: Injuries to the hip and thigh
- **19.9**: Injuries to the knee and lower leg
- **19.10**: Injuries to the ankle and foot
- **19.11**: Injuries involving multiple body regions
- **19.12**: Injuries of unspecified parts of trunk, limb or body region
- **19.13**: Effects of foreign body entering through a natural opening
- **19.14**: Burns or corrosions of external body surface, specified by site
- **19.15**: Burns or corrosions confined to the eye and internal organs
- **19.16**: Burns or corrosions of multiple and unspecified body regions
- **19.17**: Frostbite
- **19.18**: Poisoning by drugs, medicaments and biological substances
- **19.19**: Toxic effects of primarily non-medicinal substances
- **19.20**: Other and unspecified effects of external causes
- **19.21**: Certain early complications of trauma
- **19.22**: Complications of surgical and medical care, not elsewhere classified
- **19.23**: Other complications of trauma, not elsewhere classified
- **19.24**: Sequelae of injuries, of poisoning and of other consequences of external causes
### Chapter 20: External Causes of Morbidity and Mortality
- **20.1**: Accidents
- **20.2**: Intentional self-harm
- **20.3**: Assault
- **20.4**: Event of undetermined intent
- **20.5**: Legal intervention and war operations
- **20.6**: Complications of medical and surgical care
### Chapter 21: Factors Influencing Health Status and Contact with Health Services
- **21.1**: Persons encountering health services for examination and investigation
- **21.2**: Persons with potential health hazards related to communicable diseases
- **21.3**: Persons encountering health services in connection with reproduction
- **21.4**: Persons encountering health services for specific procedures and healthcare
- **21.5**: Persons with potential health hazards related to socioeconomic and psychosocial circumstances
- **21.6**: Persons encountering health services for other reasons
- **21.7**: Persons with potential health hazards related to family and personal history and certain conditions influencing health status
### Chapter 22: Codes for Special Purposes
- **22.1**: Provisional assignments for diseases of uncertain etiology, assigned and unassigned codes
- **22.2**: Impairment of function
- **22.3**: Completed registration for organ transplantation
- **22.4**: Staging of HIV infection
- **22.5**: Secondary codes to specify cytogenetic and molecular genetic differentiation in neoplasms
- **22.6**: Secondary codes to specify mental and behavioural disorders
- **22.7**: Other secondary codes for special purposes
- **22.8**: Infectious agents resistant to certain antibiotics or chemotherapeutic agents
- **22.9**: Assigned and unassigned codes
User Prompt
This is the final discharge report that you are supposed to analyze and for which you are to identify the primary diagnosis:
'${abschlussbericht}'
## Output Format
Please reason step by step, and present your final primary code within \\boxed{}.
Custom Tool
import pprint
import urllib.parse
import json5
from qwen_agent.agents import Assistant
from qwen_agent.tools.base import BaseTool, register_tool
from qwen_agent.utils.output_beautify import typewriter_print
import re
@register_tool('retrieve_icd_chapter')
class RetrieveICDChapter(BaseTool):
description = (
'ICD-10-GM Coding Tool: input the subchapter you are interested in, '
'and the tool returns the content of that chapter including all available codes.'
)
parameters = [{
'name': 'subchapter',
'type': 'string',
'description': (
'The number of the subchapter you are interested in, '
'e.g., "1.1".'
),
'required': True
}]
def call(self, params: str, **kwargs) -> str:
response = json5.loads(params)['subchapter']
pattern = r"\\b\\d{1,2}\\.\\d{1,2}\\b"
match = re.search(pattern, response)
if match:
chapter_found = match.group(0)
code_found = code_range_mapping[chapter_found]
codes_lower = code_found.lower()
dict_result_chapter = sorted_combined_dict_translated_v2.get(codes_lower)
return dict_result_chapter
else:
return "No matching chapter found."
Remark: In my previous attempts, I also tried adding all the additional tool-related information in my current system prompt to the tool’s description, which helped slightly. However, still in around 70% of cases, the model still ignores the tool and answers directly.
Hello, I have created a 'abschlussbericht' and attempted to run this script using the Qwen3-32B model, which can correctly initiate tool calls.
I noticed that you did not pass in the parameters. You can try setting the parameters we recommend: Temperature=0.6, TopP=0.95, TopK=20 for thinking mode.
Hello, and thank you again for the feedback. The model does use the tool occasionally, but it's much less reliable than QwQ-32B, even when using the same script and prompts. I'm already using the parameters you suggested (see code snippet below).
I've also noticed that the model almost never queries the tool more than once. It either accepts one of the initially retrieved codes or argues that a different code is correct, but it doesn't validate that choice by calling the tool again. This happens even when I explicitly instruct the model to use the tool multiple times (e.g., by adding the following to the user or system prompt: "Remember to use the retrieve_icd_chapter
tool frequently to check all subchapters that might be relevant before you decide on a primary diagnosis code."). Any idea to improve the performance or align my task more closely with the way the model was trained?
def init_agent_service():
llm_cfg = {
# Use a model service compatible with the OpenAI API, such as vLLM or Ollama:
'model': '/donnees/models/Qwen3-32B', # '/donnees/models/QwQ-32B-AWQ', # '/donnees/models/Qwen3-14B', # Use the --served-model-name
'model_server': 'http://localhost:8000/v1', # Or use the server's IP if connecting remotely
'api_key': 'EMPTY',
# (Optional) LLM hyperparameters for generation:
'generate_cfg': {
'fncall_prompt_type': 'nous',
#'thought_in_content': True,
'temperature': 0.6,
'repetition_penalty': 1.0, # Note 1 below
'top_k': 20,
'top_p': 0.95,
#"max_tokens": 32768,
},
}
tools = [
'retrieve_icd_chapter',
]
bot = Assistant(
llm=llm_cfg,
function_list=tools,
name='Medical Coding Assistant',
system_message = system_instruction)
return bot
Not relevant to this case, but I also found the Qwen3-30B-A3B gguf quantized model tend to ignore tools, I am not sure whether it's a quantization problem or a model issue. I found Qwen3-32B quantization model works as expectation while dealing with tools.
A large custom system prompt like this paired with tool-calling functionalities can sometimes cause complexity, it might help to place them at the start of your user prompt. If the problem remains, try shortening the message and revise the tool description to pinpoint the issue, then gradually expand it. Hope this helps!