Qwen-Agent는 첸원 대규모 언어 모델을 기반으로 한 지능형 에이전트 개발 프레임워크로, 명령어 준수, 도구 사용, 계획 및 기억 능력을 갖춘 LLM 애플리케이션 개발에 특화되어 있습니다. 이 프로젝트는 알리바바 첸원 팀에서 개발 및 유지 관리하며, 현재 첸원 채팅 서비스(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 그림 (이미지 생성) 서비스, 텍스트 설명을 입력하면 텍스트 정보를 기반으로 그림 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)
# 2단계: LLM 구성
llm_cfg = {
'model': 'qwen-max-latest',
'model_server': 'dashscope',
'generate_cfg': {
'top_p': 0.8
}
}
# 3단계: 지능형 에이전트 생성
system_instruction = '''사용자의 요청을 받으면 다음을 수행해야 합니다.
- 먼저 이미지를 그리고 이미지 URL을 얻습니다.
- 그런 다음 `request.get(image_url)` 코드를 실행하여 이미지를 다운로드합니다.
- 마지막으로 주어진 문서에서 이미지 작업을 선택하여 이미지를 처리합니다.
`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 솔루션과 초장문서에 대한 경쟁적인 지능형 에이전트를 제공하며, 두 가지 어려운 벤치마크 테스트에서 원시 성장 컨텍스트 모델보다 우수한 성능을 보이며, 100만 토큰 컨텍스트가 관련된 단일 "건초 더미에서 바늘 찾기" 스트레스 테스트에서 완벽한 성능을 보입니다.
BrowserQwen은 Qwen-Agent를 기반으로 구축된 브라우저 도우미로, 웹 페이지 탐색, 조작 및 정보 추출 능력을 제공합니다.
Qwen-Agent는 강력하고 사용하기 쉬운 지능형 에이전트 개발 프레임워크로, 개발자에게 복잡한 LLM 애플리케이션을 구축할 수 있는 완벽한 도구 체인을 제공합니다. 간단한 챗봇이든 복잡한 다기능 지능형 도우미이든 이 프레임워크를 통해 빠르게 구현하고 배포할 수 있습니다.