AI Personal Learning
and practical guidance
豆包Marscode1

Qwen-Agent: Qwen-based framework for intelligent agent applications, including tool calls, code interpreters, RAGs and Chrome extensions.

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.

Qwen-Agent:基于 Qwen的智能代理应用框架,包括功能调用、代码解释器、RAG 和 Chrome 扩展。-1


 

BrowserQwen, a browser-based extension for smart bodies

Qwen-Agent:基于Qwen的智能代理应用框架,包括工具调用、代码解释器、RAG和Chrome扩展。-1

 

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

  1. 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
  2. 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

  1. 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.
  2. Developing Custom Agents::
    Qwen-Agent provides base components, such as the components inherited from the BaseChatModel and the LLMs inherited from BaseTool tools, as well as high-level components such as those inherited from Agent 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 绘画服务,输入文本描述,返回基于文本信息绘制的图像 URL。'
    parameters = [{'name': 'prompt', 'type': 'string', 'description': '所需图像内容的详细描述', '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': 'qwen-max',
    '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: ')
    messages.append({'role': 'user', 'content': query})
    response = bot.run(messages=messages)
    for res in response:
    print('bot response:', res)
    messages.extend(res)
    
  3. Quick Start Gradio Demo::
    from qwen_agent.gui import WebUI
    WebUI(bot).run()
    
May not be reproduced without permission:Chief AI Sharing Circle " Qwen-Agent: Qwen-based framework for intelligent agent applications, including tool calls, code interpreters, RAGs and Chrome extensions.
en_USEnglish