ScriptsApr 2, 2026·2 min read

Qwen-Agent — Build AI Agents on Qwen Models

Agent framework by Alibaba with function calling, code interpreter, RAG, and MCP support. Built for Qwen 3.0+. 15K+ stars.

TL;DR
Alibaba's agent framework with function calling, code interpreter, RAG, and MCP support built for Qwen 3.0+ models.
§01

What it is

Qwen-Agent is an agent framework by Alibaba designed for building AI agents on top of Qwen models. It provides function calling, a built-in code interpreter, RAG (retrieval-augmented generation), and MCP server support. The framework is optimized for Qwen 3.0+ but can work with other OpenAI-compatible models. It has 15K+ GitHub stars.

Qwen-Agent targets developers building AI applications with Qwen models who need agent capabilities beyond simple chat completions. It provides the infrastructure for multi-step reasoning, tool use, and knowledge retrieval.

§02

How it saves time or tokens

Qwen-Agent provides pre-built components for common agent patterns. The code interpreter executes Python in a sandboxed environment for data analysis tasks. The RAG module handles document chunking, embedding, and retrieval without separate infrastructure. MCP support lets agents connect to external tools through the Model Context Protocol. These components eliminate the need to build agent infrastructure from scratch.

§03

How to use

  1. Install Qwen-Agent:
pip install -U 'qwen-agent[gui,rag,code_interpreter,mcp]'
  1. Create an agent with tools:
from qwen_agent.agents import Assistant

agent = Assistant(
    llm={'model': 'qwen-max', 'api_key': 'YOUR_KEY'},
    function_list=['code_interpreter'],
    system_message='You are a data analysis assistant.'
)
  1. Run the agent on a task and it will use tools as needed.
§04

Example

Agent with code interpreter for data analysis:

from qwen_agent.agents import Assistant

agent = Assistant(
    llm={'model': 'qwen-max', 'api_key': 'YOUR_KEY'},
    function_list=['code_interpreter'],
)

# The agent writes and executes Python code
response = agent.run([
    {'role': 'user', 'content': 'Analyze this CSV data and create a chart: ...data...'}
])

# Agent generates Python code, runs it in sandbox,
# produces matplotlib charts, and returns results
for chunk in response:
    print(chunk)

The code interpreter runs in a sandboxed environment, preventing unsafe operations.

§05

Related on TokRepo

§06

Common pitfalls

  • Qwen-Agent is optimized for Qwen models. While it supports OpenAI-compatible APIs, function calling behavior may differ across providers.
  • The code interpreter requires a Python environment. Docker is recommended for production deployments to ensure sandboxing.
  • RAG performance depends on embedding quality. Use Qwen's own embedding models for best results with the Qwen-Agent RAG pipeline.
  • Always check the official documentation for the latest version-specific changes and migration guides before upgrading in production environments.
  • For team deployments, establish clear guidelines on configuration and usage patterns to ensure consistency across developers.

Frequently Asked Questions

Does Qwen-Agent only work with Qwen models?+

Qwen-Agent is optimized for Qwen 3.0+ models but supports any OpenAI-compatible API. However, function calling behavior and output quality may vary when using non-Qwen models.

What is the code interpreter feature?+

The code interpreter is a sandboxed Python execution environment. When the agent needs to analyze data, create charts, or compute results, it writes Python code and executes it safely. Results including generated files and images are returned to the user.

Does Qwen-Agent support MCP?+

Yes. Qwen-Agent supports the Model Context Protocol, allowing agents to connect to MCP servers for database access, web browsing, file management, and other external tools.

How does RAG work in Qwen-Agent?+

Qwen-Agent's RAG module handles document parsing, chunking, embedding, and retrieval. You provide documents and the agent automatically retrieves relevant chunks when answering questions, grounding responses in your data.

Is Qwen-Agent free to use?+

Qwen-Agent is open-source and free. However, using Qwen models through Alibaba Cloud's API requires an API key with associated costs. Local deployment with open-source Qwen model weights is also supported.

Citations (3)
🙏

Source & Thanks

Created by QwenLM (Alibaba Qwen Team). Licensed under Apache-2.0.

Qwen-Agent — ⭐ 15,800+

Thanks to the Qwen team at Alibaba for open-sourcing both the models and the agent framework.

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets