Skip to main content

Overview

ArticleAgent is a specialized agent for writing articles and long-form content. It extends the Assistant agent with capabilities for both creating new articles from scratch and continuing existing content based on reference materials.

Key Features

Full Article Writing

Create complete articles on specified topics

Content Continuation

Extend existing content with coherent additions

Research Integration

Incorporate reference materials into writing

Structured Output

Generate well-organized, thematic content

Constructor

from qwen_agent.agents.article_agent import ArticleAgent

agent = ArticleAgent(
    llm={'model': 'qwen-max-latest', 'model_type': 'qwen_dashscope'},
    system_message='You are a skilled article writer.',
    files=['./reference1.pdf', './reference2.docx'],
    rag_cfg={'lang': 'en', 'max_ref_token': 4000}
)

Parameters

ArticleAgent inherits all parameters from Assistant:
function_list
list
Optional tools (usually not needed for article writing).
llm
dict | BaseChatModel
LLM configuration for writing.
system_message
str
Instructions for the agent’s writing style.
files
list
Reference materials to incorporate into writing.
rag_cfg
dict
RAG configuration for reference material retrieval.

Basic Usage

Write a Full Article

from qwen_agent.agents.article_agent import ArticleAgent

agent = ArticleAgent(
    llm={'model': 'qwen-max-latest', 'model_type': 'qwen_dashscope'},
    system_message='You are an expert technical writer.'
)

messages = [{
    'role': 'user',
    'content': 'Write a comprehensive article about machine learning basics'
}]

for response in agent.run(messages=messages, lang='en', full_article=True):
    print(response[-1]['content'])

Continue Existing Content

from qwen_agent.agents.article_agent import ArticleAgent

agent = ArticleAgent(
    llm={'model': 'qwen-max-latest', 'model_type': 'qwen_dashscope'}
)

existing_content = """
# Introduction to Neural Networks

Neural networks are computational models inspired by the human brain...
"""

messages = [{
    'role': 'user',
    'content': f'Continue this article:\n\n{existing_content}\n\nAdd a section about training neural networks.'
}]

for response in agent.run(messages=messages, lang='en', full_article=False):
    print(response[-1]['content'])

Writing with Reference Materials

from qwen_agent.agents.article_agent import ArticleAgent

# Load reference documents
agent = ArticleAgent(
    llm={'model': 'qwen-max-latest', 'model_type': 'qwen_dashscope'},
    files=[
        './research_paper1.pdf',
        './research_paper2.pdf',
        './dataset_documentation.pdf'
    ],
    rag_cfg={
        'lang': 'en',
        'max_ref_token': 8000,  # More context for research
        'search_method': 'hybrid'
    },
    system_message='You are a research writer. Cite sources when using information.'
)

messages = [{
    'role': 'user',
    'content': 'Write an article summarizing the key findings from the research papers'
}]

for response in agent.run(messages=messages, lang='en', full_article=True):
    content = response[-1]['content']
    if 'Search for relevant information' in content:
        print('Researching references...')
    else:
        print(content)

Writing Workflow

1

Research Phase

The agent searches reference materials for relevant information:
> Search for relevant information:
[Retrieved context from documents]
2

Writing Phase

The agent generates content based on the query and references:
> Writing Text:
[Generated article content]
3

Streaming Output

Content is streamed token by token for real-time display.

Advanced Configuration

Custom Writing Style

agent = ArticleAgent(
    llm={'model': 'qwen-max-latest', 'model_type': 'qwen_dashscope'},
    system_message="""
    You are a technical writer specializing in developer documentation.
    
    Guidelines:
    - Use clear, concise language
    - Include code examples where appropriate
    - Structure content with headers and sections
    - Use bullet points for lists
    - Explain technical concepts simply
    """
)

Multi-Language Support

# English article
messages_en = [{'role': 'user', 'content': 'Write about AI safety'}]
for response in agent.run(messages=messages_en, lang='en', full_article=True):
    print(response[-1]['content'])

# Chinese article  
messages_zh = [{'role': 'user', 'content': '写一篇关于AI安全的文章'}]
for response in agent.run(messages=messages_zh, lang='zh', full_article=True):
    print(response[-1]['content'])

Use Cases

Technical Blog Posts

agent = ArticleAgent(
    llm={'model': 'qwen-max-latest', 'model_type': 'qwen_dashscope'},
    function_list=['code_interpreter'],  # For code examples
    system_message='You are a developer advocate writing technical blog posts.'
)

messages = [{
    'role': 'user',
    'content': 'Write a blog post about async/await in Python with code examples'
}]

for response in agent.run(messages=messages, full_article=True):
    print(response[-1]['content'])

Research Summaries

agent = ArticleAgent(
    llm={'model': 'qwen-max-latest', 'model_type': 'qwen_dashscope'},
    files=['./research/*.pdf'],
    rag_cfg={'lang': 'en', 'max_ref_token': 12000}
)

messages = [{
    'role': 'user',
    'content': 'Write a literature review summarizing these research papers'
}]

for response in agent.run(messages=messages, full_article=True):
    print(response[-1]['content'])

Content Expansion

outline = """
# Guide to Docker

## 1. Introduction
## 2. Installation  
## 3. Basic Commands
## 4. Dockerfile Basics
## 5. Docker Compose
"""

messages = [{
    'role': 'user',
    'content': f'Expand this outline into a full guide:\n{outline}'
}]

for response in agent.run(messages=messages, full_article=True):
    print(response[-1]['content'])

Best Practices

  • Provide clear topics or outlines
  • Specify the target audience
  • Indicate desired length or depth
  • Define the article’s purpose
  • Use relevant, high-quality sources
  • Organize references by topic
  • Ensure references are accessible
  • Set appropriate max_ref_token
  • Customize system_message for your needs
  • Specify formatting preferences
  • Request specific structures (headers, lists)
  • Iterate with follow-up prompts

Comparison: Full Article vs Continue Writing

Modefull_article=Truefull_article=False
Use CaseCreate complete articlesExtend existing content
InputTopic or outlineExisting text + direction
OutputFull articleAdditional paragraphs/sections
Agent UsedWriteFromScratchContinueWriting

Assistant Agent

Base agent with RAG capabilities

RAG Guide

Learn about document retrieval

BrowserQwen

Browser extension for article writing

GUI Deployment

Deploy with a web interface

Build docs developers (and LLMs) love