Archive of AI

Source Snapshot / 2024-06-06-alibaba-qwen-agent-framework-2

QwenLM/Qwen-Agent

Linked event: 2024-06-06 · Alibaba Qwen Open-Sources Qwen-Agent Framework and Demonstrates Low-Cost Generalization from 8K to 1M Context

Publisher
GitHub
Archived
2026-11-23
Capture Method
Direct page capture
HTTP / SHA-256
200 / c829aebf8fd95831
Original URL
Open source ↗
Wayback Backup
Not archived
This page preserves a plain-text static snapshot against link rot. When citing figures, tables, or full legal terms, verify against the original URL and Wayback Machine archive.

[来源关键摘录] Qwen-Agent 官方开源仓库,提供函数调用、代码解释器、文档检索与可视化交互界面组件。

[正文前段节选] Skip to content

Navigation Menu

Appearance settings

You signed in with another tab or window. Reload to refresh your session.

You signed out in another tab or window. Reload to refresh your session.

You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

Repository navigation

NotificationsYou must be signed in to change notification settings

Fork1.8k (1.8k)

Star17.3k (17.3k)You must be signed in to star a repository

Agent framework and applications built upon Qwen>=3.0, featuring Function Calling, MCP, Code Interpreter, RAG, Chrome extension, etc.

pypi.org/project/qwen-agent/

Apache-2.0 license

Custom properties

103 watching

Report repository

BranchesTags

Open more actions menu

Latest commit

Folders and files

Last commit message

Last commit date

.github/workflows

browser_qwen

qwen-agent-docs/website

.pre-commit-config.yaml

README_CN.md

browser_qwen.md

browser_qwen_cn.md

run_server.py

View all files

Repository files navigation

中文 | English

💜 Qwen Chat   |   🤗 Hugging Face   |   🤖 ModelScope   |    📑 Blog    |   📖 Documentation

📊 Benchmark   |   💬 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.

🔥🔥🔥Feb 16, 2026: Open-sourced Qwen3.5. For usage examples, refer to Qwen3.5 Agent Demo.

Jan 27, 2026: Open-sourced agent evaluation benchmark DeepPlanning and added Qwen-Agent documentation.

Sep 23, 2025: Added Qwen3-VL Tool-call Demo, supporting tools such as zoom in, image search, and web search.

Jul 23, 2025: Add Qwen3-Coder Tool-call Demo; Added native API tool call interface support, such as using vLLM's built-in tool call parsing.

May 1, 2025: Add Qwen3 Tool-call Demo, and add MCP Cookbooks.

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:

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, you can install the latest development version from the 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.

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 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.

For Qwen3-Coder, it is recommended to enable both of the above parameters, use vLLM's built-in tool parsing, and combine with the use_raw_api parameter usage.

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:

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

# Step 1 (Optional): Add a custom tool named `my_image_gen`.

@register_tool('my_image_gen')

class MyImageGen(BaseTool):

# The `description` tells the agent the functionality of this tool.

description = 'AI painting (image generation) service, input text description, and return the image URL drawn based on text information.'

# The `parameters` tell the agent what input parameters the tool has.

parameters = [{

'name': 'prompt',

'type': 'string',

'description': 'Detailed description of the desired image content, in English',

'required': True

def call(self, params: str, **kwargs) -> str:

# `params` are the arguments generated by the LLM agent.

prompt = json5.loads(params)['prompt']

prompt = urllib.parse.quote(prompt)

return json5.dumps(

{'image_url': f'https://image.pollinations.ai/prompt/{prompt}'},

ensure_ascii=False)

# Step 2: Configure the LLM you are using.

# Use the model service provided by DashScope:

'model': 'qwen-max-latest',

'model_type': 'qwen_dashscope',

# 'api_key': 'YOUR_DASHSCOPE_API_KEY',

# It will use the `DASHSCOPE_API_KEY' environment variable if 'api_key' is not set here.

# Use a model service compatible with the OpenAI API, such as vLLM or Ollama:

# 'model': 'Qwen2.5-7B-Instruct',

# 'model_server': 'http://localhost:8000/v1', # base_url, also known as api_base

# 'api_key': 'EMPTY',

# (Optional) LLM hyperparameters for generation:

'generate_cfg': {

'top_p': 0.8

# Step 3: Create an agent. Here we use the `Assistant` agent as an example, which is capable of using tools and reading files.

system_instruction = '''After receiving the user's request, you should:

- first draw an image and obtain the image url,

- then run code `request.get(image_url)` to download the image,

- and finally select an image operation from the given document to process the image.

Please show the image using `plt.show()`.'''

tools = ['my_image_gen', 'code_interpreter'] # `code_interpreter` is a built-in tool for executing code. For configuration details, please refer to the FAQ.

files = ['./examples/resource/doc.pdf'] # Give the bot a PDF file to read.

bot = Assistant(llm=llm_cfg,

system_message=system_instruction,

function_list=tools,

files=files)

# Step 4: Run the agent as a chatbot.

messages = [] # This stores the chat history.

# For example, enter the query "draw a dog and rotate it 90 degrees".

query = input('\nuser query: ')

# Append the user query to the chat history.

messages.append({'role': 'user', 'content': query})

response = []

response_plain_text = ''

print('bot response:')

for response in bot.run(messages=messages):

# Streaming output.

response_plain_text = typewriter_print(response, response_plain_text)

# Append the bot responses to the chat history.

messages.extend(response)

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.

[...内容已截断,完整版请查看原文或 Wayback 快照]