Qwen-Agent
Qwen-Agent
Qwen-Agent는 Qwen의 지시 따르기, 도구 사용, 계획, 메모리 능력을 바탕으로 LLM 애플리케이션을 개발하기 위한 프레임워크예요. 이 글은 Qwen-Agent를 사용해 Qwen3의 에이전트 능력을 빠르게 체험하는 간단한 튜토리얼이에요.
출처: 문서
본문
더 자세한 내용은 Qwen-Agent 저장소를 참고하세요.
설치
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.
나만의 에이전트 만들기
Qwen3는 도구 호출 능력이 뛰어나요. Qwen-Agent는 내부적으로 도구 호출 템플릿과 도구 호출 파서를 캡슐화하고 있어서 코딩 복잡도를 크게 줄여줘요.
사용 가능한 도구를 정의하려면 MCP 설정 파일을 사용하거나, Qwen-Agent의 통합 도구를 사용하거나, 다른 도구를 직접 통합하면 돼요.
import os
from qwen_agent.agents import Assistant
# Define LLM
llm_cfg = {
# Use a custom endpoint compatible with OpenAI API by vLLM/SGLang:
'model': 'Qwen/Qwen3-32B',
'model_server': 'http://localhost:8000/v1', # api_base
'api_key': 'EMPTY',
# 'generate_cfg': {
# # When using vLLM/SGLang OAI API, pass the parameter of whether to enable thinking mode in this way
# 'extra_body': {
# 'chat_template_kwargs': {'enable_thinking': False}
# },
#
# # Add: When the content is ` thinkingthis is the thought responsethis is the answer`
# # Do not add: When the response has been separated by reasoning_content and content
# # This parameter will affect the parsing strategy of tool call
# # 'thought_in_content': True,
# },
}
# llm_cfg = {
# # Use the model service provided by DashScope:
# 'model': 'qwen3-235b-a22b',
# 'model_type': 'qwen_dashscope',
#
# # 'generate_cfg': {
# # # When using the Dash Scope API, pass the parameter of whether to enable thinking mode in this way
# # 'enable_thinking': False,
# # },
# }
# llm_cfg = {
# # Use the OpenAI-compatible model service provided by DashScope:
# 'model': 'qwen3-235b-a22b',
# 'model_server': 'https://dashscope.aliyuncs.com/compatible-mode/v1',
# 'api_key': os.getenv('DASHSCOPE_API_KEY'),
#
# # 'generate_cfg': {
# # # When using Dash Scope OAI API, pass the parameter of whether to enable thinking mode in this way
# # 'extra_body': {
# # 'enable_thinking': False
# # },
# # },
# }
# Define Tools
tools = [
{'mcpServers': { # You can specify the MCP configuration file
'time': {
'command': 'uvx',
'args': ['mcp-server-time', '--local-timezone=Asia/Shanghai']
},
"fetch": {
"command": "uvx",
"args": ["mcp-server-fetch"]
}
}
},
'code_interpreter', # Built-in tools
]
# Define Agent
bot = Assistant(llm=llm_cfg, function_list=tools)
# Streaming generation
messages = [{'role': 'user', 'content': 'https://qwenlm.github.io/blog/ Introduce the latest developments of Qwen'}]
for responses in bot.run(messages=messages):
pass
print(responses)
더 자세한 예시와 MCP 쿡북은 Qwen-Agent 저장소를 참고하세요.