Skip to main content
Qwen-Agent includes a rich collection of example applications demonstrating various capabilities, from simple function calling to complex multi-agent systems. This guide helps you navigate the examples and understand what each demonstrates.

Example Categories

Assistant Demos

Pre-built assistants for various tasks including RAG, weather forecasts, and custom tools

Function Calling

Examples of integrating external functions and APIs with LLMs

Multi-Agent Chat

Group chat systems with multiple AI agents collaborating

Document QA

Long document analysis and question answering systems

Quick Start Examples

Basic Assistant

The simplest example - a RAG-enabled assistant:
from qwen_agent.agents import Assistant
from qwen_agent.gui import WebUI

bot = Assistant(
    llm={'model': 'qwen-plus-latest'},
    name='Assistant',
    description='使用RAG检索并回答,支持文件类型:PDF/Word/PPT/TXT/HTML。'
)

WebUI(bot).run()
This creates a web interface for chatting with documents.

Function Calling

Basic example of using external functions:
from qwen_agent.llm import get_chat_model
import json

def get_weather(location, unit='fahrenheit'):
    # Your implementation
    return json.dumps({'location': location, 'temperature': '72'})

llm = get_chat_model({'model': 'qwen-plus-latest'})

messages = [{'role': 'user', 'content': "What's the weather in SF?"}]
functions = [{
    'name': 'get_weather',
    'description': 'Get the current weather',
    'parameters': {...}
}]

for response in llm.chat(messages=messages, functions=functions):
    print(response)

Example Files

Here’s a complete list of available examples:

Assistant Examples

Basic RAG (Retrieval-Augmented Generation) assistant that can answer questions about uploaded documents.Supported formats: PDF, Word, PPT, TXT, HTML
Weather forecast assistant with image generation and custom knowledge base integration.Features: Weather API integration, image generation, document knowledge
Demonstrates how to create and register custom tools for use in agents.Key concepts: Tool registration, custom implementations, plugin system
Examples specific to Qwen3 and Qwen3.5 models with optimized configurations.
Specialized for Qwen3-Coder with native tool call parsing.
QwQ-32B model demo supporting parallel, multi-step, and multi-turn tool calls.
Model Context Protocol (MCP) integration with SQLite database.

Function Calling Examples

Standard function calling example following OpenAI’s pattern.Demonstrates: Basic function definition, calling, and response handling
Advanced example showing parallel function execution.Key feature: Multiple functions called simultaneously for efficiency
Function calling with vision models (Qwen2-VL).

Multi-Agent Examples

Comprehensive group chat system with multiple AI agents and human participants.Features: Agent creation, role management, multi-turn conversations
Router-based multi-agent system that delegates tasks to specialized agents.Agents: VL assistant, tool assistant, text assistant
Example of agents playing chess together.

Document Processing Examples

Parallel document QA for efficient processing of long documents.Performance: Faster processing through parallelization
QA system with virtual memory for handling extremely large documents.

Advanced Examples

ReAct-style agent for data analysis tasks.
Tool-Integrated Reasoning with Qwen2.5-Math for mathematical problem solving.
Generate stories from images using vision models.
Handling long conversation contexts efficiently.

Jupyter Notebooks

Interactive cookbook examples:

cookbook_database_manipulation.ipynb

Database operations with AI assistance

cookbook_drive_guide.ipynb

Driving guide application example

cookbook_mind_map.ipynb

Generate mind maps from content

cookbook_think_with_images.ipynb

Vision-based tool calling with Qwen3-VL

Running Examples

Prerequisites

1

Install Dependencies

pip install -U "qwen-agent[gui,rag,code_interpreter]"
2

Set API Key

For DashScope:
export DASHSCOPE_API_KEY="your-api-key"
3

Navigate to Examples

cd examples/

Running an Example

Most examples support multiple modes:
# GUI mode (web interface)
python assistant_rag.py

# Programmatic mode (edit the file to uncomment test() function)
python assistant_rag.py

Common Patterns

Most examples follow this structure:
def test():
    # Programmatic usage
    bot = create_bot()
    messages = [{'role': 'user', 'content': 'query'}]
    for response in bot.run(messages):
        print(response)

def app_gui():
    # Web UI mode
    bot = create_bot()
    WebUI(bot).run()

if __name__ == '__main__':
    # Uncomment the mode you want
    # test()
    app_gui()

Customization Tips

Changing Models

All examples allow model customization:
# Use different DashScope models
llm = {'model': 'qwen-max'}  # or qwen-plus, qwen-turbo

# Use local models
llm = {
    'model': 'Qwen2.5-7B-Instruct',
    'model_server': 'http://localhost:8000/v1',
    'api_key': 'EMPTY'
}

Adding Custom Tools

See assistant_add_custom_tool.py for the complete pattern:
from qwen_agent.tools.base import BaseTool, register_tool

@register_tool('my_tool')
class MyTool(BaseTool):
    description = 'Tool description'
    parameters = [{
        'name': 'param1',
        'type': 'string',
        'description': 'Parameter description',
        'required': True
    }]
    
    def call(self, params: str, **kwargs) -> str:
        # Your implementation
        return result

Configuring WebUI

Customize the web interface:
chatbot_config = {
    'prompt.suggestions': [
        {'text': 'Example question 1'},
        {'text': 'Example question 2'},
    ],
    'verbose': True,  # Show detailed logs
}

WebUI(bot, chatbot_config=chatbot_config).run()

Next Steps

Explore specific example categories:

Assistant Demos

Detailed guide to assistant examples

Function Calling

Master function calling patterns

Multi-Agent Chat

Build collaborative agent systems

Document QA

Process long documents efficiently

Build docs developers (and LLMs) love