QwenLM/Qwen-Agent
中文 | English
💜 Qwen Chat | 🤗 Hugging Face | 🤖 ModelScope | 📑 Blog | 📖 Documentation
💬 WeChat (微信) | 🫨 Discord
Qwen-Agent is a framework for developing LLM applications based on the instruction following, tool usage, planning, and memory capabilities of Qwen. It also comes with example applications such as Browser Assistant, Code Interpreter, and Custom Assistant. Now Qwen-Agent plays as the backend of Qwen Chat.
News
- 🔥🔥🔥May 1, 2025: Add Qwen3 Tool-call Demo.
- Mar 18, 2025: Support for the
reasoning_content
field; adjust the default Function Call template, which is applicable to the Qwen2.5 series general models and QwQ-32B. If you need to use the old version of the template, please refer to the example for passing parameters. - Mar 7, 2025: Added QwQ-32B Tool-call Demo. It supports parallel, multi-step, and multi-turn tool calls.
- Dec 3, 2024: Upgrade GUI to Gradio 5 based. Note: GUI requires Python 3.10 or higher.
- Sep 18, 2024: Added Qwen2.5-Math Demo to showcase the Tool-Integrated Reasoning capabilities of Qwen2.5-Math. Note: The python executor is not sandboxed and is intended for local testing only, not for production use.
Getting Started
Installation
- Install the stable version from PyPI:
|
|
- Alternatively, you can install the latest development version from the source:
|
|
Preparation: Model Service
You can either use the model service provided by Alibaba Cloud’s DashScope, or deploy and use your own model service using the open-source Qwen models.
-
If you choose to use the model service offered by DashScope, please ensure that you set the environment variable
DASHSCOPE_API_KEY
to your unique DashScope API key. -
Alternatively, if you prefer to deploy and use your own model service, please follow the instructions provided in the README of Qwen2 for deploying an OpenAI-compatible API service. Specifically, consult the vLLM section for high-throughput GPU deployment or the Ollama section for local CPU (+GPU) deployment. For the QwQ and Qwen3 model, it is recommended to add the
--enable-reasoning
and--reasoning-parser deepseek_r1
parameters when starting the service. Do not add the--enable-auto-tool-choice
and--tool-call-parser hermes
parameters, as Qwen-Agent will parse the tool outputs from vLLM on its own.
Developing Your Own Agent
Qwen-Agent offers atomic components, such as LLMs (which inherit from class BaseChatModel
and come with function calling) and Tools (which inherit
from class BaseTool
), along with high-level components like Agents (derived from class Agent
).
The following example illustrates the process of creating an agent capable of reading PDF files and utilizing tools, as well as incorporating a custom tool:
|
|
In addition to using built-in agent implementations such as class Assistant
, you can also develop your own agent implemetation by inheriting from class Agent
.
The framework also provides a convenient GUI interface, supporting the rapid deployment of Gradio Demos for Agents. For example, in the case above, you can quickly launch a Gradio Demo using the following code:
|
|
Now you can chat with the Agent in the web UI. Please refer to the examples directory for more usage examples.
FAQ
How to Use MCP?
You can select the required tools on the open-source MCP server website and configure the relevant environment.
Example of MCP invocation format:
|
|
For more details, you can refer to the MCP usage example
The dependencies required to run this example are as follows:
|
|
Do you have function calling (aka tool calling)?
Yes. The LLM classes provide function calling. Additionally, some Agent classes also are built upon the function calling capability, e.g., FnCallAgent and ReActChat.
How to do question-answering over super-long documents involving 1M tokens?
We have released a fast RAG solution, as well as an expensive but competitive agent, for doing question-answering over super-long documents. They have managed to outperform native long-context models on two challenging benchmarks while being more efficient, and perform perfectly in the single-needle “needle-in-the-haystack” pressure test involving 1M-token contexts. See the blog for technical details.
Application: BrowserQwen
BrowserQwen is a browser assistant built upon Qwen-Agent. Please refer to its documentation for details.
Disclaimer
The code interpreter is not sandboxed, and it executes code in your own environment. Please do not ask Qwen to perform dangerous tasks, and do not directly use the code interpreter for production purposes.