All Products
Search
Document Center

Alibaba Cloud Model Studio:Intent recognition

Last Updated:Oct 20, 2025

Qwen's intent recognition model quickly and accurately parses user intents in milliseconds and selects appropriate tools to resolve user queries.

Important

This document applies only to the China (Beijing) region. To use the model, you must use an API key from the China (Beijing) region.

Supported models

Model

Context window

Maximum input

Maximum output

Input price

Output price

(Tokens)

(Million tokens)

tongyi-intent-detect-v3

8,192

8,192

1,024

$0.058

$0.144

Usage

Prerequisites

You must obtain an API key and set the API key as an environment variable. If you use the OpenAI SDK or DashScope SDK to make calls, you must also install the SDK.

Output both intent and function call information

To enable the intent recognition model to output both intent and function calling information, you need to set the System Message as follows:

You are Qwen, created by Alibaba Cloud. You are a helpful assistant. You may call one or more tools to assist with the user query. The tools you can use are as follows:
{Tool information}
Response in INTENT_MODE.

Specify Response in INTENT_MODE. in the System Message and include information about the available tools. The format for the tool information is:

[{
    "name": "Name of tool 1",
    "description": "Description of tool 1",
    "parameters": {
        "type": "The type of the parameter, typically object",
        "properties": {
            "parameter_1": {
                "description": "Description of parameter_1",
                "type": "Type of parameter_1",
                "default": "Default value of parameter_1"
            },
            ...
            "parameter_n": {
                "description": "Description of parameter_n",
                "type": "Type of parameter_n",
                "default": "Default value of parameter_n"
            }
        },
        "required": [
        "parameter_1",
        ...
        "parameter_n"
    ]
    },
},
...
{
    "name": "Name of tool n",
    "description": "Description of tool n",
    "parameters": {
        "type": "The type of the parameter, typically object",
        "properties": {
            "parameter_1": {
                "description": "Description of parameter_1",
                "type": "Type of parameter_1",
                "default": "Default value of parameter_1"
            },
            ...
            "parameter_n": {
                "description": "Description of parameter_n",
                "type": "Type of parameter_n",
                "default": "Default value of parameter_n"
            }
        },
        "required": [
        "parameter_1",
        ...
        "parameter_n"
    ]
    },
}]

Assume that you require two tools: a time query tool and a weather query tool. The tool information is as follows:

[
    {
        "name": "get_current_time",
        "description": "This is useful when you want to know the current time.",
        "parameters": {}
    },
    {
        "name": "get_current_weather",
        "description": "This is useful when you want to query the weather of a specified city.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "A city or district, such as Beijing, Hangzhou, or Yuhang District.",
                }
            },
            "required": ["location"]
        }
    }
]

Sample request

OpenAI compatible

import os
import json
from openai import OpenAI

# Define tools
tools = [
    {
        "name": "get_current_time",
        "description": "This is useful when you want to know the current time.",
        "parameters": {}
    },
    {
        "name": "get_current_weather",
        "description": "This is useful when you want to query the weather of a specified city.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "A city or district, such as Beijing, Hangzhou, or Yuhang District.",
                }
            },
            "required": ["location"]
        }
    }
]

tools_string = json.dumps(tools,ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant. You may call one or more tools to assist with the user query. The tools you can use are as follows:
{tools_string}
Response in INTENT_MODE."""
client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
messages = [
    {'role': 'system', 'content': system_prompt},
    {'role': 'user', 'content': "Weather in Hangzhou"}
    ]
response = client.chat.completions.create(
    model="tongyi-intent-detect-v3",
    messages=messages
)

print(response.choices[0].message.content)

DashScope

import os
import json
from dashscope import Generation

# Define tools
tools = [
    {
        "name": "get_current_time",
        "description": "This is useful when you want to know the current time.",
        "parameters": {}
    },
    {
        "name": "get_current_weather",
        "description": "This is useful when you want to query the weather of a specified city.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "A city or district, such as Beijing, Hangzhou, or Yuhang District.",
                }
            },
            "required": ["location"]
        }
    }
]

tools_string = json.dumps(tools,ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant. You may call one or more tools to assist with the user query. The tools you can use are as follows:
{tools_string}
Response in INTENT_MODE."""

messages = [
    {'role': 'system', 'content': system_prompt},
    {'role': 'user', 'content': "Weather in Hangzhou"}
    ]
response = Generation.call(
    # If you have not set the environment variable, replace the following line with your Model Studio API key: api_key = "sk-xxx",
    api_key=os.getenv("DASHSCOPE_API_KEY"), 
    model="tongyi-intent-detect-v3",
    messages=messages,
    result_format="message"
)

print(response.output.choices[0].message.content)

Sample response

<tags>
[function call, json response]
</tags><tool_call>
[{"name": "get_current_weather", "arguments": {"location": "Hangzhou"}}]
</tool_call><content>

</content>

After you receive the response, you can use the parse_text function to parse the returned tool and parameter information:

import re

def parse_text(text):
    # Define regular expression patterns to match <tags>, <tool_call>, <content>, and their content
    tags_pattern = r'<tags>(.*?)</tags>'
    tool_call_pattern = r'<tool_call>(.*?)</tool_call>'
    content_pattern = r'<content>(.*?)</content>'
    # Use regular expressions to find matching content
    tags_match = re.search(tags_pattern, text, re.DOTALL)
    tool_call_match = re.search(tool_call_pattern, text, re.DOTALL)
    content_match = re.search(content_pattern, text, re.DOTALL)
    # Extract the matched content. If no match is found, an empty string is returned.
    tags = tags_match.group(1).strip() if tags_match else ""
    tool_call = tool_call_match.group(1).strip() if tool_call_match else ""
    content = content_match.group(1).strip() if content_match else ""
    # Store the extracted content in a dictionary
    result = {
      "tags": tags,
      "tool_call": tool_call,
      "content": content
    }
    return result

response = """<tags>
[function call, json response]
</tags><tool_call>
[{"name": "get_current_weather", "arguments": {"location": "Hangzhou"}}]
</tool_call><content>

</content>"""
print(parse_text(response))

Sample output

{
    "tags": "[function call, json response]",
    "tool_call": [
        {
            "name": "get_current_weather",
            "arguments": {
                "location": "Hangzhou"
            }
        }
    ],
    "content": ""
}

Output only intent information

To make the intent recognition model output only intent information, you need to set the System Message as follows:

You are Qwen, created by Alibaba Cloud. You are a helpful assistant. \nYou should choose one tag from the tag list:\n{intent information}\njust reply with the chosen tag.

The format for the intent information is as follows:

{
    "Intent 1": "Description of Intent 1",
    "Intent 2": "Description of Intent 2",
    "Intent 3": "Description of Intent 3",
    ...
}

Sample request

OpenAI compatible

import os
import json
from openai import OpenAI


intent_dict = {
    "play_game": "Play game",
    "email_querycontact": "Email query contact",
    "general_quirky": "quirky",
    "email_addcontact": "Email add contact",
    "takeaway_query": "Takeaway query",
    "recommendation_locations": "Location recommendation",
    "transport_traffic": "Transportation",
    "iot_cleaning": "IoT - vacuum cleaner, cleaner",
    "general_joke": "Joke",
    "lists_query": "Query list/checklist",
    "calendar_remove": "Calendar delete event",
    "transport_taxi": "Taxi, taxi booking",
    "qa_factoid": "Factual Q&A",
    "transport_ticket": "Transportation ticket",
    "play_radio": "Play radio",
    "alarm_set": "Set alarm",
}

intent_string = json.dumps(intent_dict,ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant. 
You should choose one tag from the tag list:
{intent_string}
Just reply with the chosen tag."""


client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
messages = [
    {'role': 'system', 'content': system_prompt},
    {'role': 'user', 'content': "Wake me up at nine on Friday morning"}
    ]
response = client.chat.completions.create(
    model="tongyi-intent-detect-v3",
    messages=messages
)

print(response.choices[0].message.content)

DashScope

import os
import json
from dashscope import Generation

intent_dict = {
    "play_game": "Play game",
    "email_querycontact": "Email query contact",
    "general_quirky": "quirky",
    "email_addcontact": "Email add contact",
    "takeaway_query": "Takeaway query",
    "recommendation_locations": "Location recommendation",
    "transport_traffic": "Transportation",
    "iot_cleaning": "IoT - vacuum cleaner, cleaner",
    "general_joke": "Joke",
    "lists_query": "Query list/checklist",
    "calendar_remove": "Calendar delete event",
    "transport_taxi": "Taxi, taxi booking",
    "qa_factoid": "Factual Q&A",
    "transport_ticket": "Transportation ticket",
    "play_radio": "Play radio",
    "alarm_set": "Set alarm",
}

intent_string = json.dumps(intent_dict,ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant. 
You should choose one tag from the tag list:
{intent_string}
Just reply with the chosen tag."""

messages = [
    {'role': 'system', 'content': system_prompt},
    {'role': 'user', 'content': "Wake me up at nine on Friday morning"}
    ]
response = Generation.call(
    # If you have not set the environment variable, replace the following line with your Model Studio API key: api_key = "sk-xxx",
    api_key=os.getenv("DASHSCOPE_API_KEY"), 
    model="tongyi-intent-detect-v3",
    messages=messages,
    result_format="message"
)

print(response.output.choices[0].message.content)

Sample response

alarm_set

Improve the response time of intent recognition

To improve the response time for intent recognition, you can use a single uppercase letter to represent each intent category. The intent recognition response will then be a single token, which optimizes the response time of the model call.

OpenAI compatible

import os
import json
from openai import OpenAI


intent_dict = {
    "A": "Play game",
    "B": "Email query contact",
    "C": "quirky",
    "D": "Email add contact",
    "E": "Takeaway query",
    "F": "Location recommendation",
    "G": "Transportation",
    "H": "IoT - vacuum cleaner, cleaner",
    "I": "Joke",
    "J": "Query list/checklist",
    "K": "Calendar delete event",
    "L": "Taxi, taxi booking",
    "M": "Factual Q&A",
    "N": "Transportation ticket",
    "O": "Play radio",
    "P": "Set alarm",
}

intent_string = json.dumps(intent_dict, ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant. 
You should choose one tag from the tag list:
{intent_string}
Just reply with the chosen tag."""


client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
messages = [
    {"role": "system", "content": system_prompt},
    {"role": "user", "content": "What is the earliest flight from Beijing to Hangzhou?"},
]
response = client.chat.completions.create(
    model="tongyi-intent-detect-v3", messages=messages
)

print(response.choices[0].message.content)

DashScope

import os
import json
from dashscope import Generation

intent_dict = {
    "A": "Play game",
    "B": "Email query contact",
    "C": "quirky",
    "D": "Email add contact",
    "E": "Takeaway query",
    "F": "Location recommendation",
    "G": "Transportation",
    "H": "IoT - vacuum cleaner, cleaner",
    "I": "Joke",
    "J": "Query list/checklist",
    "K": "Calendar delete event",
    "L": "Taxi, taxi booking",
    "M": "Factual Q&A",
    "N": "Transportation ticket",
    "O": "Play radio",
    "P": "Set alarm",
}

intent_string = json.dumps(intent_dict, ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant. 
You should choose one tag from the tag list:
{intent_string}
Just reply with the chosen tag."""

messages = [
    {"role": "system", "content": system_prompt},
    {"role": "user", "content": "What is the earliest flight from Beijing to Hangzhou?"},
]
response = Generation.call(
    # If you have not set the environment variable, replace the following line with your Model Studio API key: api_key = "sk-xxx",
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="tongyi-intent-detect-v3",
    messages=messages,
    result_format="message",
)

print(response.output.choices[0].message.content)

After you run the code, you can obtain a single-token intent categorization result.

M

Output only function call information

To make the intent recognition model output only function calling information, you need to set the System Message as follows:

You are Qwen, created by Alibaba Cloud. You are a helpful assistant. You may call one or more tools to assist with the user query. The tools you can use are as follows:\n{Tool information}\nResponse in NORMAL_MODE.

The format for the tool information is the same as that described in Output both intent and function call information.

Sample request

OpenAI compatible

import os
import json
from openai import OpenAI

# Define tools
tools = [
    {
        "name": "get_current_time",
        "description": "This is useful when you want to know the current time.",
        "parameters": {}
    },
    {
        "name": "get_current_weather",
        "description": "This is useful when you want to query the weather of a specified city.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "A city or district, such as Beijing, Hangzhou, or Yuhang District.",
                }
            },
            "required": ["location"]
        }
    }
]

tools_string = json.dumps(tools,ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant. You may call one or more tools to assist with the user query. The tools you can use are as follows:
{tools_string}
Response in NORMAL_MODE."""
client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
messages = [
    {'role': 'system', 'content': system_prompt},
    {'role': 'user', 'content': "Weather in Hangzhou"}
    ]
response = client.chat.completions.create(
    model="tongyi-intent-detect-v3",
    messages=messages
)

print(response.choices[0].message.content)

DashScope

import os
import json
from dashscope import Generation

# Define tools
tools = [
    {
        "name": "get_current_time",
        "description": "This is useful when you want to know the current time.",
        "parameters": {}
    },
    {
        "name": "get_current_weather",
        "description": "This is useful when you want to query the weather of a specified city.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "A city or district, such as Beijing, Hangzhou, or Yuhang District.",
                }
            },
            "required": ["location"]
        }
    }
]

tools_string = json.dumps(tools,ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant. You may call one or more tools to assist with the user query. The tools you can use are as follows:
{tools_string}
Response in NORMAL_MODE."""

messages = [
    {'role': 'system', 'content': system_prompt},
    {'role': 'user', 'content': "Weather in Hangzhou"}
    ]
response = Generation.call(
    # If you have not set the environment variable, replace the following line with your Model Studio API key: api_key = "sk-xxx",
    api_key=os.getenv("DASHSCOPE_API_KEY"), 
    model="tongyi-intent-detect-v3",
    messages=messages,
    result_format="message"
)

print(response.output.choices[0].message.content)

Sample response

<tool_call>
{"name": "get_current_weather", "arguments": {"location": "Hangzhou"}}
</tool_call>

After you receive the response, you can use the parse_text function to parse the returned tool and parameter information:

import re


def parse_text(text):
    tool_call_pattern = r'<tool_call>(.*?)</tool_call>'
    # Use regular expressions to find matching content
    tool_call_match = re.search(tool_call_pattern, text, re.DOTALL)
    # Extract the matched content. If no match is found, an empty string is returned.
    tool_call = tool_call_match.group(1).strip() if tool_call_match else ""
    return tool_call

response = """<tool_call>
{"name": "get_current_weather", "arguments": {"location": "Hangzhou"}}
</tool_call>"""
print(parse_text(response))

Sample output

{"name": "get_current_weather", "arguments": {"location": "Hangzhou"}}

Multi-round conversation

If a user does not provide sufficient information in a query, the intent recognition model will ask follow-up questions. After collecting the necessary parameters, it then outputs the function calling information.

Output both intent and function call information

Sample request

OpenAI compatible

import os
import json
from openai import OpenAI

# Define tools
tools = [
    {
        "name": "get_current_time",
        "description": "This is useful when you want to know the current time.",
        "parameters": {},
    },
    {
        "name": "get_current_weather",
        "description": "This is useful when you want to query the weather of a specified city.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "A city or district, such as Beijing, Hangzhou, or Yuhang District.",
                }
            },
            "required": ["location"],
        },
    },
]

tools_string = json.dumps(tools, ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant. You may call one or more tools to assist with the user query. The tools you can use are as follows:
{tools_string}
Response in INTENT_MODE."""
client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
messages = [
    {"role": "system", "content": system_prompt},
    # The question asked in the first round of conversation
    {"role": "user", "content": "I want to check the weather"},
]
response = client.chat.completions.create(
    model="tongyi-intent-detect-v3", messages=messages
)

print("Query: I want to check the weather")
print("First-round output:\n")
print(response.choices[0].message.content)
messages.append(response.choices[0].message)
# The question asked in the second round of conversation
messages.append({"role": "user", "content": "In Hangzhou"})
response = client.chat.completions.create(
    model="tongyi-intent-detect-v3", messages=messages
)
print("\nQuery: In Hangzhou")
print("Second-round output:\n")
print(response.choices[0].message.content)

DashScope

import os
import json
from dashscope import Generation

# Define tools
tools = [
    {
        "name": "get_current_time",
        "description": "This is useful when you want to know the current time.",
        "parameters": {},
    },
    {
        "name": "get_current_weather",
        "description": "This is useful when you want to query the weather of a specified city.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "A city or district, such as Beijing, Hangzhou, or Yuhang District.",
                }
            },
            "required": ["location"],
        },
    },
]

tools_string = json.dumps(tools, ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant. You may call one or more tools to assist with the user query. The tools you can use are as follows:
{tools_string}
Response in INTENT_MODE."""

messages = [
    {"role": "system", "content": system_prompt},
    # The question asked in the first round of conversation
    {"role": "user", "content": "I want to check the weather"},
]
response = Generation.call(
    # If you have not set the environment variable, replace the following line with your Model Studio API key: api_key = "sk-xxx",
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="tongyi-intent-detect-v3",
    messages=messages,
    result_format="message",
)
print("Query: I want to check the weather")
print("First-round output:\n")
print(response.output.choices[0].message.content)

messages.append(
    {"role": "assistant", "content": response.output.choices[0].message.content}
)
# The question asked in the second round of conversation
messages.append({"role": "user", "content": "Hangzhou"})

response = Generation.call(
    # If you have not set the environment variable, replace the following line with your Model Studio API key: api_key = "sk-xxx",
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="tongyi-intent-detect-v3",
    messages=messages,
    result_format="message",
)
print("\nQuery: Hangzhou")
print("Second-round output:\n")
print(response.output.choices[0].message.content)
Sample response
Query: I want to check the weather
First-round output:

<tags>
[weather inquiry]
</tags><tool_call>
[]
</tool_call><content>
OK. Which city's weather would you like to check?
</content>

Query: Hangzhou
Second-round output:

<tags>
[function call, json response]
</tags><tool_call>
[{"name": "get_current_weather", "arguments": {"location": "Hangzhou"}}]
</tool_call><content>

</content>

Output only function call information

Sample request

OpenAI compatible

import os
import json
from openai import OpenAI

# Define tools
tools = [
    {
        "name": "get_current_time",
        "description": "This is useful when you want to know the current time.",
        "parameters": {},
    },
    {
        "name": "get_current_weather",
        "description": "This is useful when you want to query the weather of a specified city.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "A city or district, such as Beijing, Hangzhou, or Yuhang District.",
                }
            },
            "required": ["location"],
        },
    },
]

tools_string = json.dumps(tools, ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant. You may call one or more tools to assist with the user query. The tools you can use are as follows:
{tools_string}
Response in NORMAL_MODE."""
client = OpenAI(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)
messages = [
    {"role": "system", "content": system_prompt},
    {"role": "user", "content": "I want to check the weather"},
]
response = client.chat.completions.create(
    model="tongyi-intent-detect-v3", messages=messages
)

messages.append(response.choices[0].message)
print("Query: I want to check the weather")
print("First-round output:\n")
print(response.choices[0].message.content)
messages.append({"role": "user", "content": "Hangzhou"})
response = client.chat.completions.create(
    model="tongyi-intent-detect-v3", messages=messages
)
print("\nQuery: Hangzhou")
print("Second-round output:\n")
print(response.choices[0].message.content)

DashScope

import os
import json
from dashscope import Generation

# Define tools
tools = [
    {
        "name": "get_current_time",
        "description": "This is useful when you want to know the current time.",
        "parameters": {},
    },
    {
        "name": "get_current_weather",
        "description": "This is useful when you want to query the weather of a specified city.",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "A city or district, such as Beijing, Hangzhou, or Yuhang District.",
                }
            },
            "required": ["location"],
        },
    },
]

tools_string = json.dumps(tools, ensure_ascii=False)

system_prompt = f"""You are Qwen, created by Alibaba Cloud. You are a helpful assistant. You may call one or more tools to assist with the user query. The tools you can use are as follows:
{tools_string}
Response in NORMAL_MODE."""

messages = [
    {"role": "system", "content": system_prompt},
    {"role": "user", "content": "I want to check the weather"},
]
response = Generation.call(
    # If you have not set the environment variable, replace the following line with your Model Studio API key: api_key = "sk-xxx",
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="tongyi-intent-detect-v3",
    messages=messages,
    result_format="message",
)
print("Query: I want to check the weather")
print("First-round output:\n")
print(response.output.choices[0].message.content)
messages.append(
    {"role": "assistant", "content": response.output.choices[0].message.content}
)
messages.append({"role": "user", "content": "Hangzhou"})
response = Generation.call(
    # If you have not set the environment variable, replace the following line with your Model Studio API key: api_key = "sk-xxx",
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="tongyi-intent-detect-v3",
    messages=messages,
    result_format="message",
)
print("\nQuery: Hangzhou")
print("Second-round output:\n")
print(response.output.choices[0].message.content)
Sample response
Query: I want to check the weather
First-round output:

Which city's weather would you like to check?

Query: Hangzhou
Second-round output:

<tool_call>
{"name": "get_current_weather", "arguments": {"location": "Hangzhou"}}
</tool_call>

FAQ

Q: What is the maximum number of tools that can be passed in?

A: We recommend that you provide no more than 10 tools. Otherwise, the accuracy of tool calls may decrease.