Introduction
This quickstart guide will help you create a functional AI agent with tool-calling capabilities in just 5 minutes. By the end, you’ll have a working agent that can generate images and interact with users.Prerequisites: Complete the installation steps and configure your model service (DashScope or self-hosted) before proceeding.
Your First Agent
Let’s build a simple weather assistant that can answer questions about the weather.Import Required Modules
Open These imports provide:
weather_agent.py and add the necessary imports:weather_agent.py
Assistant: The high-level agent class with built-in tool supportWebUI: A Gradio-based interface for interacting with your agent
Configure the LLM
Set up your language model configuration:
If using DashScope, ensure your
DASHSCOPE_API_KEY environment variable is set.Adding Custom Tools
Now let’s enhance your agent by adding a custom image generation tool.Define a Custom Tool
Add this code before creating your agent:
weather_agent.py
The
@register_tool decorator automatically registers your tool with Qwen-Agent, making it available to all agents.Using Built-in Tools
Qwen-Agent comes with powerful built-in tools like the Code Interpreter.Complete Example: Image Generator with Code
Here’s a complete, production-ready example combining custom tools and built-in capabilities:complete_agent.py
http://localhost:7860).
Working with Files
Agents can read and process various file formats:file_agent.py
- PDF (
.pdf) - Word documents (
.docx) - PowerPoint (
.pptx) - Excel (
.xlsx) - Text files (
.txt,.md,.csv)
Advanced Configuration
Customizing Generation Parameters
Using Streaming Responses
Multi-turn Conversations
Next Steps
MCP Integration
Connect external tools via Model Context Protocol
RAG Tutorial
Build retrieval-augmented generation systems
Advanced Agents
Explore multi-agent systems and custom workflows
API Reference
Full API documentation
Common Patterns
Function Calling Without Agents
Function Calling Without Agents
You can use function calling directly with LLM classes:
Custom Agent Classes
Custom Agent Classes
Inherit from
Agent to create specialized agents:Error Handling
Error Handling
Handle errors gracefully in production:
Troubleshooting
Agent not calling tools
Agent not calling tools
Ensure your system message clearly instructs the agent to use tools:
Code Interpreter fails
Code Interpreter fails
Check that Docker is running:
Streaming output issues
Streaming output issues
Make sure you’re iterating through the generator: