Qwen-Agent
Qwen-Agent is a framework for developing LLM applications based on the instruction following, tool usage, planning, and memory capabilities of Qwen. It provides atomic components like LLMs and Tools, high-level Agents, and example applications such as Browser Assistant and Code Interpreter. It is for developers building custom AI agents and applications with Qwen models.
✨ Key features
- Framework for building LLM applications with Qwen models
- Supports function calling, tool usage, planning, and memory
- Includes built-in agents like Assistant, FnCallAgent, ReActChat
- Provides GUI support via Gradio for rapid demos
- Optional RAG, code interpreter, and MCP support
- Compatible with DashScope and OpenAI-compatible model services
🎯 Use cases
- Build custom AI assistants that can read files and use tools
- Create browser assistants for web automation
- Implement code interpreters with sandboxed execution
- Develop question-answering systems over long documents
- Integrate MCP servers for extended tool capabilities
📦 Installation
🧰 Requirements: Python 3.10 or higher for GUI; requires a model service (DashScope API key or self-hosted OpenAI-compatible service); optional Docker for code interpreter.
pip install -U "qwen-agent[gui,rag,code_interpreter,mcp]"
# Or use `pip install -U qwen-agent` for the minimal requirements.
# The optional requirements, specified in double brackets, are:
# [gui] for Gradio-based GUI support;
# [rag] for RAG support;
# [code_interpreter] for Code Interpreter support;
# [mcp] for MCP support.
Alternatively, install from source:
git clone https://github.com/QwenLM/Qwen-Agent.git
cd Qwen-Agent
pip install -e ./"[gui,rag,code_interpreter,mcp]"
# Or `pip install -e ./` for minimal requirements.
🚀 Usage
from qwen_agent.agents import Assistant
from qwen_agent.tools.base import BaseTool, register_tool
# Define a custom tool
@register_tool('my_image_gen')
class MyImageGen(BaseTool):
description = 'AI painting service'
parameters = [{'name': 'prompt', 'type': 'string', 'description': 'Image description', 'required': True}]
def call(self, params: str, **kwargs) -> str:
# implementation
return 'image_url'
# Configure LLM
llm_cfg = {
'model': 'qwen-max-latest',
'model_type': 'qwen_dashscope',
# 'api_key': 'YOUR_DASHSCOPE_API_KEY',
}
# Create agent
bot = Assistant(llm=llm_cfg, system_message='You are helpful.', function_list=['my_image_gen'])
# Run conversation
messages = [{'role': 'user', 'content': 'draw a dog'}]
for response in bot.run(messages=messages):
print(response)
⚠️ Good to know
The code interpreter tool is not sandboxed and is intended for local testing only, not for production use; the Docker container-based code interpreter implements basic sandbox isolation but should be used with caution in production.
❓ FAQ
How do I use the code interpreter tool?
Enable the built-in 'code interpreter' tool for your agent. Ensure Docker is installed and running. The tool executes code in an isolated sandbox container.
Does Qwen-Agent support function calling?
Yes, the LLM classes provide function calling, and some Agent classes like FnCallAgent and ReActChat are built upon it. The default template supports parallel function calls.
How can I use MCP with Qwen-Agent?
You can configure MCP servers in a JSON format and use them as tools. Refer to the MCP usage example in the repository for details.
How do I pass LLM parameters to the agent?
Set parameters in the llm_cfg dictionary, including model, model_type, api_key, and optional generate_cfg for hyperparameters like top_p or use_raw_api.
📊 Repository
🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.