Qwen-Agent Library

0.0.34 · active · verified Sun Apr 12

Qwen-Agent is a Python library designed to enhance Large Language Models (LLMs) with advanced capabilities such as Agent Workflows, Retrieval-Augmented Generation (RAG), Function Calling, and Code Interpreters. It's actively developed, with version 0.0.34 released recently, maintaining a rapid release cadence with frequent minor updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize an `AssistantAgent` with a Code Interpreter tool and use it to execute a simple task. It requires an API key for DashScope (for Qwen models) or OpenAI, which should be set as an environment variable.

import os
from qwen_agent.agents import AssistantAgent
from qwen_agent.tools.tool_code_interpreter import CodeInterpreter

# Configure your LLM access
# Ensure DASHSCOPE_API_KEY or OPENAI_API_KEY is set in your environment variables.
llm_config = {
    'model': 'qwen-turbo',
    'model_server': 'dashscope', # or 'openai', 'ollama', etc.
    'api_key': os.environ.get('DASHSCOPE_API_KEY', os.environ.get('OPENAI_API_KEY', ''))
}

if not llm_config['api_key']:
    raise ValueError("Please set DASHSCOPE_API_KEY or OPENAI_API_KEY environment variable.")

# Initialize the agent with tools
agent = AssistantAgent(
    llm=llm_config,
    tools=[CodeInterpreter()]
)

# Run the agent with a prompt
response = agent.run("Please write a python code snippet to calculate the sum of 123 and 456.")
print(response)

view raw JSON →