Qwen-Agent は、千問大規模言語モデルをベースにしたエージェント開発フレームワークであり、指示に従う、ツールを使用する、計画を立てる、記憶する能力を備えた LLM アプリケーションの開発に特化しています。このプロジェクトは、Alibaba 千問チームによって開発・メンテナンスされており、現在は千問チャットサービス (Qwen Chat) のバックエンドをサポートしています。
reasoning_content
フィールドをサポート、デフォルトの関数呼び出しテンプレートを調整pip install -U "qwen-agent[gui,rag,code_interpreter,mcp]"
# または最小インストール
pip install -U qwen-agent
git clone https://github.com/QwenLM/Qwen-Agent.git
cd Qwen-Agent
pip install -e ./"[gui,rag,code_interpreter,mcp]"
[gui]
: Gradio グラフィカルインターフェースのサポート[rag]
: RAG 検索拡張機能[code_interpreter]
: コードインタープリター機能[mcp]
: MCP プロトコルサポートllm_cfg = {
'model': 'qwen-max-latest',
'model_server': 'dashscope',
# 'api_key': 'YOUR_DASHSCOPE_API_KEY',
'generate_cfg': {
'top_p': 0.8
}
}
llm_cfg = {
'model': 'Qwen2.5-7B-Instruct',
'model_server': 'http://localhost:8000/v1',
'api_key': 'EMPTY',
}
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
# ステップ1: カスタムツールの追加
@register_tool('my_image_gen')
class MyImageGen(BaseTool):
description = 'AI painting (image generation) service, input text description, and return the image URL drawn based on text information.'
parameters = [{
'name': 'prompt',
'type': 'string',
'description': 'Detailed description of the desired image content, in English',
'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)
# ステップ2: LLM の設定
llm_cfg = {
'model': 'qwen-max-latest',
'model_server': 'dashscope',
'generate_cfg': {
'top_p': 0.8
}
}
# ステップ3: エージェントの作成
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']
files = ['./examples/resource/doc.pdf']
bot = Assistant(llm=llm_cfg,
system_message=system_instruction,
function_list=tools,
files=files)
# ステップ4: エージェントチャットの実行
messages = []
while True:
query = input('\nuser query: ')
messages.append({'role': 'user', 'content': query})
response = []
response_plain_text = ''
print('bot response:')
for response in bot.run(messages=messages):
response_plain_text = typewriter_print(response, response_plain_text)
messages.extend(response)
from qwen_agent.gui import WebUI
WebUI(bot).run()
{
"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"
]
}
}
}
プロジェクトは、高速な RAG ソリューションと、非常に長いドキュメントを対象とした競争力のあるエージェントを提供し、2つの困難なベンチマークテストでネイティブの長コンテキストモデルよりも優れたパフォーマンスを発揮し、100万トークンのコンテキストを含むシングルショットの「干し草の山から針を探す」ストレステストで完璧な結果を示しました。
BrowserQwen は、Qwen-Agent をベースに構築されたブラウザアシスタントであり、ウェブページの閲覧、操作、情報抽出機能を提供します。
Qwen-Agent は、強力で使いやすいエージェント開発フレームワークであり、開発者に複雑な LLM アプリケーションを構築するための完全なツールチェーンを提供します。単純なチャットボットから複雑な多機能スマートアシスタントまで、このフレームワークを通じて迅速に実現およびデプロイできます。