Overview
TheAssistant agent is the most widely applicable agent in Qwen-Agent, combining retrieval-augmented generation (RAG) capabilities with function calling. It extends FnCallAgent and is perfect for building conversational AI applications that need to access documents and use tools.
The Assistant agent is used as the backend for Qwen Chat and has been battle-tested with millions of users.
Key Features
RAG Integration
Built-in document parsing and retrieval for question-answering over files
Function Calling
Native support for calling tools and external APIs
Multi-format Support
Process PDF, Word, PowerPoint, HTML, and text documents
Memory Management
Automatic conversation history and context management
Constructor
Parameters
List of tools to enable. Can be tool names (strings), tool configurations (dicts), or tool objects.
LLM configuration or model object. Include
model, model_type, and optionally api_key, model_server.System message that defines the agent’s behavior and personality.
Agent name for identification in multi-agent scenarios.
Agent description for routing in multi-agent systems.
Initial list of document URLs or file paths to load into memory.
RAG configuration including:
lang: Language (‘en’ or ‘zh’)max_ref_token: Maximum tokens for retrieved contextparser_page_size: Pages per document chunkrag_keygen_llm: LLM for keyword generationsearch_method: Search strategy (‘front_page’, ‘keywords’, ‘vector’, ‘hybrid’)
Basic Usage
RAG Example
The Assistant automatically performs retrieval when documents are provided:Function Calling Example
Combine document QA with tool usage:GUI Integration
Quickly deploy with a web interface:Advanced Configuration
Custom RAG Settings
Multi-turn Conversations
Best Practices
Document Organization
Document Organization
- Keep documents focused and relevant to avoid irrelevant retrievals
- Use descriptive filenames for better source attribution
- Pre-process documents to remove unnecessary content
- Consider document size limits (very large documents should use ParallelDocQA)
RAG Configuration
RAG Configuration
- Use
hybridsearch for best retrieval quality - Adjust
max_ref_tokenbased on your model’s context window - Set
langcorrectly for optimal chunking and keyword extraction - Use smaller
parser_page_sizefor fine-grained retrieval
Tool Selection
Tool Selection
- Only include tools that are relevant to your use case
- Provide clear tool descriptions to help the agent choose correctly
- Test tool combinations to ensure they work well together
- Monitor tool usage patterns to optimize performance
Related Resources
RAG Guide
Learn more about retrieval-augmented generation
Custom Tools
Create your own tools for the Assistant
GUI Deployment
Deploy your Assistant with a web interface
API Reference
Complete API documentation