The BasicDocQA agent (aliased as DocQAAgent) is specialized for document question-answering tasks. It extends the Assistant agent with optimized prompts and workflows for retrieving and answering questions from documents.
DocQAAgent is the default solution for long document question answering in Qwen-Agent. The actual implementation may change with releases to incorporate improvements.
messages = [{ 'role': 'user', 'content': 'What is the main conclusion of this paper?'}]for response in agent.run(messages=messages): print(response[-1]['content'])
from qwen_agent.agents import DocQAAgent# Load a single PDF documentagent = DocQAAgent( llm={'model': 'qwen-max-latest', 'model_type': 'qwen_dashscope'}, files=['./technical_manual.pdf'], rag_cfg={'lang': 'en', 'search_method': 'hybrid'})# Ask specific questionsquestions = [ 'What is covered in Section 3?', 'Explain Table 2', 'What are the system requirements?']for question in questions: messages = [{'role': 'user', 'content': question}] for response in agent.run(messages=messages): pass print(f"Q: {question}") print(f"A: {response[-1]['content']}\n")
from qwen_agent.agents import DocQAAgentagent = DocQAAgent( llm={'model': 'qwen-max-latest', 'model_type': 'qwen_dashscope'}, files=['./user_guide.pdf'])messages = []# First questionmessages.append({'role': 'user', 'content': 'How do I install the software?'})for response in agent.run(messages=messages): passmessages.extend(response)# Follow-up questionmessages.append({'role': 'user', 'content': 'What are the system requirements for that?'})for response in agent.run(messages=messages): passmessages.extend(response)print(messages[-1]['content'])