General Introduction
Qwen-Agent is an intelligent agent application framework developed based on Qwen 2.0 and above with command following, tool usage, planning and memorization capabilities. The framework provides a variety of sample applications, such as browser helpers, code interpreters, and custom helpers, to help developers quickly build and deploy intelligent agent applications.Qwen-Agent supports a variety of functional modules, including function calls, code interpretation, RAG (Retrieval Augmentation Generation), and Chrome extensions, for a variety of complex application scenarios.
BrowserQwen, a browser-based extension for smart bodies
Function List
- function call: Supports automation of complex tasks through function calls.
- code interpreter: Provide code interpretation features to help users understand and execute code.
- RAG (Retrieval Augmentation Generation): Supports large-scale document retrieval and generation for long-document quizzing tasks.
- Chrome Extension: Provides browser extensions to enhance the user's browsing experience.
- Customization Tools: Allow users to add custom tools to extend the functionality of the framework.
Using Help
Installation process
- Installing the stable version from PyPI::
pip install -U "qwen-agent[gui,rag,code_interpreter,python_executor]"
Or install the least dependent version:
pip install -U qwen-agent
Optional dependencies include:
[gui]
: Support for Gradio-based GUIs[rag]
: Support for RAG[code_interpreter]
: Support for code interpreters[python_executor]
: Tool-integrated reasoning with support for Qwen2.5-Math
- Install the latest development version from source::
git clone https://github.com/QwenLM/Qwen-Agent.git cd Qwen-Agent pip install -e . /[gui,rag,code_interpreter,python_executor]
Or install the least dependent version:
pip install -e . /
Functional operation flow
- Configuration Modeling Service::
- Use the modeling service provided by AliCloud DashScope to set environment variables
DASHSCOPE_API_KEY
for your DashScope API key. - Alternatively, deploy and use your own modeling service, following the instructions in the README for Qwen2.
- Use the modeling service provided by AliCloud DashScope to set environment variables
- Developing Custom Agents::
Qwen-Agent provides base components, such as the components inherited from theBaseChatModel
and the LLMs inherited fromBaseTool
tools, as well as high-level components such as those inherited fromAgent
The following is an example of creating an agent that can read a PDF file and use the tool. The following is an example of creating an agent that can read PDF files and use tools:from qwen_agent.agents import Assistant from qwen_agent.tools.base import BaseTool, register_tool @register_tool('my_image_gen') class MyImageGen(BaseTool). description = 'AI painting service that inputs a text description and returns a URL of an image painted based on the text information.' parameters = [{'name': 'prompt', 'type': 'string', 'description': 'Detailed description of the desired image content', 'required': True}]] def call(self, params: str, **kwargs) -> str. prompt = json5.loads(params)['prompt'] prompt = urllib.parse.quote(prompt) return json5.dumps({'image_url': f'https://image.pollinations.ai/prompt/{prompt}'}, ensure_ascii=False) llm_cfg = { 'model_server': 'dashscope', 'generate_cfg': {'top_p': 0.8} } tools = ['my_image_gen', 'code_interpreter'] files = ['. /examples/resource/doc.pdf'] bot = Assistant(llm=llm_cfg, system_message='You are a helpful assistant.', function_list=tools, files=files) messages = [] while True: query = input('user query') query = input('user query: ') messages.append({'role': 'user', 'content': query}) response = bot.run(messages=messages) for res in response. print('bot response:', res) messages.extend(res)
- Quick Start Gradio Demo::
from qwen_agent.gui import WebUI WebUI(bot).run()