# Qwen-Agent

> Build LLM agents on Qwen with tool calling, MCP, code interpreter, and RAG

- Category: Agents & Automation / Agent Frameworks & Builders
- Language: Python
- Licence: Apache-2.0
- Repository: https://github.com/QwenLM/Qwen-Agent
- Website: https://pypi.org/project/qwen-agent/
- Canonical page: https://ai-tldr.dev/tools/qwen-agent/

## In short

Qwen-Agent is an open-source framework from the Qwen team at Alibaba for building LLM applications on top of Qwen models. It builds on the models' instruction following, tool usage, planning, and memory abilities, and ships example apps such as a Browser Assistant, a Code Interpreter, and a Custom Assistant. It sits in the Agent Frameworks & Builders category of the Agents & Automation tools and is open-source, written in Python and licensed Apache-2.0.

## Overview

Qwen-Agent is an open-source framework from the Qwen team at Alibaba for building LLM applications on top of Qwen models. It builds on the models' instruction following, tool usage, planning, and memory abilities, and ships example apps such as a Browser Assistant, a Code Interpreter, and a Custom Assistant. The same framework serves as the backend of Qwen Chat.

The framework gives you atomic building blocks (LLM classes that support function calling and Tool classes you can subclass) plus higher-level Agent classes like the ready-made Assistant, which can call tools and read files. You connect it to a model either through Alibaba Cloud's DashScope API or your own OpenAI-compatible service such as vLLM or Ollama.

Beyond plain chat, it includes a built-in code interpreter that runs code inside a local Docker sandbox, support for the Model Context Protocol (MCP) so agents can use external tool servers, a RAG solution aimed at very long documents, and an optional Gradio-based web UI for quickly demoing an agent.

## What it does

- Function calling (tool calling) on Qwen models, including parallel, multi-step, and multi-turn calls
- Ready-made agents such as the Assistant, which can use tools and read files (for example PDFs)
- Built-in code interpreter that executes generated code in a local Docker sandbox
- MCP support, so agents can connect to Model Context Protocol tool servers (memory, filesystem, SQLite, and more)
- RAG support for question-answering over very long documents, up to around 1M-token contexts
- Optional Gradio-based GUI to launch a web demo of your agent in a few lines

## Getting started

Install the package from PyPI with the optional extras you need, point it at a Qwen model service, then create an Assistant agent and run it. The example below mirrors the project README.

1. Install Qwen-Agent

   Install the stable release from PyPI. The optional extras in double brackets add GUI, RAG, code interpreter, and MCP support; use the bare package for minimal requirements.

```bash
pip install -U "qwen-agent[gui,rag,code_interpreter,mcp]"
```

2. Connect a model service

   Use Alibaba Cloud DashScope by setting your DASHSCOPE_API_KEY environment variable, or deploy your own OpenAI-compatible service with vLLM or Ollama and point the config at its base URL.

```bash
export DASHSCOPE_API_KEY=your_api_key
```

3. Create and run an Assistant agent

   Configure the LLM, create an Assistant with a system message, an optional tool list, and files to read, then stream its responses. code_interpreter is a built-in tool.

```python
from qwen_agent.agents import Assistant

llm_cfg = {'model': 'qwen-max-latest', 'model_type': 'qwen_dashscope'}
bot = Assistant(
    llm=llm_cfg,
    function_list=['code_interpreter'],
    files=['./examples/resource/doc.pdf'],
)

messages = [{'role': 'user', 'content': 'Summarize the PDF.'}]
for response in bot.run(messages=messages):
    print(response)
```

4. Launch a web UI (optional)

   Wrap your agent in the Gradio-based WebUI to get a chat interface for quick demos. The GUI requires Python 3.10 or higher.

```python
from qwen_agent.gui import WebUI
WebUI(bot).run()
```

## When to use it

- Build a custom assistant that reads your documents and calls your own tools to answer questions
- Run an agent that writes and executes code in a sandbox to analyze data or process files
- Connect Qwen models to external MCP tool servers (filesystem, SQLite, memory) for richer automation
- Do retrieval-augmented question-answering over very long documents using the built-in RAG solution
