OSS Agents JP
オープンソース AI エージェント 日本語ガイド
← 一覧へ
Qwen-Agent
OTHER

Qwen-Agent

Qwen-Agent

Alibaba Qwen LLMをベースとしたエージェント開発フレームワーク。Function Calling、Code Interpreter、RAG、ブラウザ拡張など豊富な機能を搭載し、インテリジェントなLLMアプリケーション構築を支援するPythonライブラリです。

#LLM Agent#Code Interpreter#RAG
EDITOR'S TAKE

編集部メモ

Qwen 公式による統合エージェント フレームワーク

Alibaba による Qwen LLM 専用エージェント フレームワークです。Function Calling、Code Interpreter、RAG、MCP など豊富な機能が統合されており、Qwen Chat のバックエンドとしても使用されています。Qwen3.5 など最新モデル対応も早く、DeepPlanning ベンチマークで評価も可能です。Gradio 5 ベース GUI により、プロトタイプから本運用アプリケーションまで対応できます。ただし Code Interpreter の Python Executor は非 sandbox のため、本番環境での使用には注意が必要です。

USE CASES

こんな場面で使う

  • 構築する:Qwen LLM の最新機能を活用したエージェント開発(Function Calling やツール統合推論を活用した実装)
  • 実装する:Code Interpreter で Python や SQL などの実行機能を搭載した高度で柔軟な AI アシスタント
  • 構築する:RAG によるエンタープライズグレードの社内ドキュメント検索・質問応答システム実装
DIFFERENTIATOR

類似ツールとの違い

LangChain / LangGraph は汎用フレームワークで多くの LLM に対応していますが、Qwen-Agent は Qwen LLM に最適化され、Function Calling などの機能統合度が高くなっています。DeepPlanning ベンチマークやツール統合推論対応も特徴です。
CAVEAT

注意点・向かない用途

⚠️ Code Interpreter の Python Executor は非 sandbox 設計で本番環境に不適切です。また Qwen モデル前提のため、他の LLM 利用者には関心が薄い可能性があります。
BEST FOR

向いている読者

Qwen LLM ユーザーPython エンジニアAI エージェント開発者最新 LLM 機能をいち早く試したい技術者

— OSS Agents JP 編集部による独自評価(Qwen-Agent に関する観察)

REPO STATS

リポジトリ統計

⭐ Stars
-
🍴 Forks
-
⚠️ Open Issues
-
🌿 Language
-
📄 License
-
🕒 最終更新
-
📅 公開日
-
🌿 Branch
-
REFERENCE

公式ドキュメント(README)

本ハブの独自評価は上記「編集部メモ」が一次情報です。以下は GitHub README の参考転載(折りたたみ)。

📖 GitHub README の日本語訳を読む(AI 自動翻訳 / 参考情報)

— AI による自動翻訳 (2026.05.20 更新)。正確な情報は GitHub の原文 をご確認ください。

中文 | English


💜 Qwen Chat | 🤗 Hugging Face | 🤖 ModelScope | 📑 ブログ | 📖 ドキュメント
📊 ベンチマーク | 💬 WeChat (微信) | 🫨 Discord

Qwen-Agent は、Qwen の指示追従、ツール使用、計画、およびメモリ機能に基づいて LLM アプリケーションを開発するためのフレームワークです。Browser Assistant、Code Interpreter、Custom Assistant などのサンプルアプリケーションも付属しています。現在、Qwen-Agent は Qwen Chat のバックエンドとして機能しています。

ニュース

  • 🔥🔥🔥2月16日、2026年:Qwen3.5 をオープンソース化しました。使用例については、Qwen3.5 Agent Demo を参照してください。
  • 1月27日、2026年:エージェント評価ベンチマーク DeepPlanning をオープンソース化し、Qwen-Agent ドキュメント を追加しました。
  • 9月23日、2025年:Qwen3-VL Tool-call Demo を追加し、ズーム、画像検索、ウェブ検索などのツールをサポートしています。
  • 7月23日、2025年:Qwen3-Coder Tool-call Demo を追加しました。ネイティブ API ツール呼び出しインターフェイスサポート(vLLM の組み込みツール呼び出し解析を使用するなど)を追加しました。
  • 5月1日、2025年:Qwen3 Tool-call Demo を追加し、MCP Cookbooks を追加しました。
  • 3月18日、2025年:reasoning_content フィールドのサポートを追加し、デフォルトの Function Call テンプレート を調整しました。これは Qwen2.5 シリーズ汎用モデルと QwQ-32B に適用されます。古いバージョンのテンプレートを使用する必要がある場合は、 を参照してパラメータを渡してください。
  • 3月7日、2025年:QwQ-32B Tool-call Demo を追加しました。並列、複数ステップ、複数ターンのツール呼び出しをサポートしています。
  • 12月3日、2024年:GUI を Gradio 5 ベースにアップグレードしました。注:GUI には Python 3.10 以上が必要です。
  • 9月18日、2024年:Qwen2.5-Math Demo を追加し、Qwen2.5-Math の Tool-Integrated Reasoning 機能をデモンストレーションしています。注:Python エグゼキューターはサンドボックス化されておらず、ローカルテスト用です。本番用ではありません。

はじめに

インストール

  • PyPI から安定版をインストールします:
pip install -U "qwen-agent[gui,rag,code_interpreter,mcp]"
# Or use `pip install -U qwen-agent` for the minimal requirements.
# The optional requirements, specified in double brackets, are:
#   [gui] for Gradio-based GUI support;
#   [rag] for RAG support;
#   [code_interpreter] for Code Interpreter support;
#   [mcp] for MCP support.
  • または、ソースから最新の開発版をインストールできます:
git clone https://github.com/QwenLM/Qwen-Agent.git
cd Qwen-Agent
pip install -e ./"[gui,rag,code_interpreter,mcp]"
# Or `pip install -e ./` for minimal requirements.

準備:モデルサービス

Alibaba Cloud の DashScope が提供するモデルサービスを使用するか、またはオープンソース Qwen モデルを使用して独自のモデルサービスをデプロイして使用することができます。

  • DashScope が提供するモデルサービスを使用することを選択した場合は、環境変数 DASHSCOPE_API_KEY を固有の DashScope API キーに設定してください。

  • または、独自のモデルサービスをデプロイして使用する場合は、Qwen2 の README に記載されている OpenAI 互換 API サービスをデプロイするための手順に従ってください。具体的には、高スループット GPU デプロイメント用の vLLM セクション、またはローカル CPU (+GPU) デプロイメント用の Ollama セクションを参照してください。QwQ および Qwen3 モデルの場合、Qwen-Agent が vLLM からのツール出力を独自に解析するため、--enable-auto-tool-choice および --tool-call-parser hermes パラメータを追加しないことを お勧めします。Qwen3-Coder の場合は、上記の両方のパラメータを有効にし、vLLM の組み込みツール解析を使用し、use_raw_api パラメータ 使用方法 と組み合わせることをお勧めします。

独自エージェントの開発

Qwen-Agent は、LLMs(class BaseChatModel から継承し、function calling を備えている)や Tools(class BaseTool から継承)などの原子的コンポーネント、ならびに Agents(class Agent から派生)のような高レベルコンポーネントを提供します。

以下の例は、PDFファイルを読み取り、ツールを利用でき、かつカスタムツールを組み込むことができるエージェントを作成するプロセスを示しています。

import pprint
import urllib.parse
import json5
from qwen_agent.agents import Assistant
from qwen_agent.tools.base import BaseTool, register_tool
from qwen_agent.utils.output_beautify import typewriter_print


# Step 1 (Optional): Add a custom tool named `my_image_gen`.
@register_tool('my_image_gen')
class MyImageGen(BaseTool):
    # The `description` tells the agent the functionality of this tool.
    description = 'AI painting (image generation) service, input text description, and return the image URL drawn based on text information.'
    # The `parameters` tell the agent what input parameters the tool has.
    parameters = [{
        'name': 'prompt',
        'type': 'string',
        'description': 'Detailed description of the desired image content, in English',
        'required': True
    }]

    def call(self, params: str, **kwargs) -> str:
        # `params` are the arguments generated by the LLM agent.
        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)


# Step 2: Configure the LLM you are using.
llm_cfg = {
    # Use the model service provided by DashScope:
    'model': 'qwen-max-latest',
    'model_type': 'qwen_dashscope',
    # 'api_key': 'YOUR_DASHSCOPE_API_KEY',
    # It will use the `DASHSCOPE_API_KEY' environment variable if 'api_key' is not set here.

    # Use a model service compatible with the OpenAI API, such as vLLM or Ollama:
    # 'model': 'Qwen2.5-7B-Instruct',
    # 'model_server': 'http://localhost:8000/v1',  # base_url, also known as api_base
    # 'api_key': 'EMPTY',

    # (Optional) LLM hyperparameters for generation:
    'generate_cfg': {
        'top_p': 0.8
    }
}

# Step 3: Create an agent. Here we use the `Assistant` agent as an example, which is capable of using tools and reading files.
system_instruction = '''After receiving the user's request, you should:
- first draw an image and obtain the image url,
- then run code `request.get(image_url)` to download the image,
- and finally select an image operation from the given document to process the image.
Please show the image using `plt.show()`.'''
tools = ['my_image_gen', 'code_interpreter']  # `code_interpreter` is a built-in tool for executing code. For configuration details, please refer to the FAQ.
files = ['./examples/resource/doc.pdf']  # Give the bot a PDF file to read.
bot = Assistant(llm=llm_cfg,
                system_message=system_instruction,
                function_list=tools,
                files=files)

# Step 4: Run the agent as a chatbot.
messages = []  # This stores the chat history.
while True:
    # For example, enter the query "draw a dog and rotate it 90 degrees".
    query = input('\nuser query: ')
    # Append the user query to the chat history.
    messages.append({'role': 'user', 'content': query})
    response = []
    response_plain_text = ''
    print('bot response:')
    for response in bot.run(messages=messages):
        # Streaming output.
        response_plain_text = typewriter_print(response, response_plain_text)
    # Append the bot responses to the chat history.
    messages.extend(response)

class Assistant などの組み込みエージェント実装を使用するほかに、class Agent から継承することで独自のエージェント実装を開発することもできます。

このフレームワークは便利な GUI インターフェースを提供しており、エージェント向けの Gradio Demo の高速デプロイをサポートしています。例えば、上記の例では、以下のコードを使用して Gradio Demo を素早く起動できます。

from qwen_agent.gui import WebUI
WebUI(bot).run()  # bot is the agent defined in the above code, we do not repeat the definition here for saving space.

これで Web UI 内でエージェントとチャットできます。その他の使用例については、examples ディレクトリを参照してください。

FAQ

コード インタプリタ ツールの使い方は?

ローカル Docker コンテナに基づくコード インタプリタ ツールを実装しています。エージェント用の組み込み code interpreter ツールを有効にして、特定のシナリオに応じて自動的にコードを記述し、隔離されたサンドボックス環境内で安全に実行し、実行結果を返すことができます。

⚠️ 注意:このツールを使用する前に、ローカル オペレーティング システムに Docker がインストールされており、実行されていることを確認してください。初めてコンテナ イメージをビルドするのに必要な時間は、ネットワーク条件によって異なります。Docker のインストールと設定の手順については、公式ドキュメントを参照してください。

MCP の使い方は?

オープンソース MCP サーバー ウェブサイトから必要なツールを選択して、関連する環境を構成できます。

MCP 呼び出し形式の例:

{
    "mcpServers": {
        "memory": {
            "command": "npx",
            "args": ["-y", "@modelcontextprotocol/server-memory"]
        },
        "filesystem": {
            "command": "npx",
            "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/files"]
        },
        "sqlite" : {
            "command": "uvx",
            "args": [
                "mcp-server-sqlite",
                "--db-path",
                "test.db"
            ]
        }
    }
}

詳細については、MCP の使用例を参照してください。

この例を実行するために必要な依存関係は以下の通りです:

# Node.js (Download and install the latest version from the Node.js official website)
# uv 0.4.18 or higher (Check with uv --version)
# Git (Check with git --version)
# SQLite (Check with sqlite3 --version)

# For macOS users, you can install these components using Homebrew:
brew install uv git sqlite3

# For Windows users, you can install these components using winget:
winget install --id=astral-sh.uv -e
winget install git.git sqlite.sqlite

関数呼び出し(ツール呼び出しとも呼ばれる)を持っていますか?

はい。LLM クラスは関数呼び出しを提供しています。さらに、一部の Agent クラスは関数呼び出し機能に基づいて構築されています。例えば、FnCallAgent や ReActChat です。

現在のデフォルト ツール呼び出しテンプレートは、ネイティブに並列関数呼び出しをサポートしています。

LLMパラメータをエージェントに渡す方法

llm_cfg = {
    # The model name being used:
    'model': 'qwen3-32b',
    # The model service being used:
    'model_type': 'qwen_dashscope',
    # If 'api_key' is not set here, it will default to reading the `DASHSCOPE_API_KEY` environment variable:
    'api_key': 'YOUR_DASHSCOPE_API_KEY',

    # Using an OpenAI API compatible model service, such as vLLM or Ollama:
    # 'model': 'qwen3-32b',
    # 'model_server': 'http://localhost:8000/v1',  # base_url, also known as api_base
    # 'api_key': 'EMPTY',

    # (Optional) LLM hyperparameters:
    'generate_cfg': {
        # This parameter will affect the tool-call parsing logic. Default is False:
          # Set to True: when content is `<think>this is the thought</think>this is the answer`
          # Set to False: when response consists of reasoning_content and content
        # 'thought_in_content': True,

        # tool-call template: default is nous (recommended for qwen3):
        # 'fncall_prompt_type': 'nous'

        # Maximum input length, messages will be truncated if they exceed this length, please adjust according to model API:
        # 'max_input_tokens': 58000

        # Parameters that will be passed directly to the model API, such as top_p, enable_thinking, etc., according to the API specifications:
        # 'top_p': 0.8

        # Using the API's native tool call interface
        # 'use_raw_api': True,
    }
}

1Mトークンに関わる超長いドキュメント上での質問応答を行う方法

高速RAGソリューション、および計算量が多いですが競争力のあるエージェント超長いドキュメント上での質問応答を実現するためにリリースしました。これらはハイレベルなベンチマーク2つでネイティブな長文コンテキストモデルを上回るパフォーマンスを達成しながら、より効率的です。また、1Mトークンのコンテキストを含む単一針の「needle-in-the-haystack」プレッシャーテストで完全に動作します。技術的な詳細についてはブログを参照してください。

RELATED

同じカテゴリの他のツール