| name | thesis-workflow-agent |
| description | Academic thesis automation via Word COM interface. Template generation, format normalization, quality checking, document analysis, content restructuring, batch processing. Compatible with Word 2010+. Use when user mentions thesis writing, paper formatting, academic document, Word automation, document analysis, 论文写作, 格式调整, 毕业论文, Word自动化, 文档分析, 论文格式. |
论文工作流Agent技能
快速开始
环境要求
- Windows系统 + Microsoft Word已安装
- Python 3.8+ +
pywin32 (pip install pywin32)
- Python-docx库 (
pip install python-docx)
连接Word并创建论文
import sys; sys.path.insert(0, r"SKILL_DIR/scripts")
from word_connect import connect_word, ThesisWriter
from template_engine import load_template, fill_template
from format_manager import apply_format_spec
word_app, doc = connect_word(visible=False)
writer = ThesisWriter(visible=False)
result = writer.write_thesis(content_dict, "output.docx")
将 SKILL_DIR 替换为此技能的实际安装路径。
核心工作流
根据用户需求选择对应模块:
| 需求 | 脚本 | 参考文档 |
|---|
| Word连接与文档管理 | scripts/word_connect.py | - |
| 文档结构与格式分析 | scripts/document_analyzer.py | references/document_analysis.md |
| 论文编辑与内容重组 | scripts/thesis_editor.py | references/thesis_editing.md |
| 格式规范应用 | scripts/format_manager.py | references/format_standards.md |
| 模板解析与填充 | scripts/template_engine.py | references/template_specification.md |
| 内容智能生成 | scripts/content_generator.py | references/content_generation.md |
| 质量检查与验证 | scripts/quality_checker.py | references/quality_check.md |
| 格式深度检查 | scripts/format_checker.py | references/format_checking.md |
| 工作流协调管理 | scripts/workflow_manager.py | references/workflow_management.md |
| 批量文档处理 | scripts/batch_processor.py | references/batch_processing.md |
| CLI命令行接口 | scripts/cli_interface.py | references/cli_usage.md |
使用流程
针对现有文档的增强工作流(毕业论文修改版)
-
文档分析阶段:
- 使用
document_analyzer.py分析文档结构、格式和内容
- 生成分析报告,识别格式问题和结构缺陷
- 对比学校格式规范,找出不符合项
-
内容编辑阶段:
- 使用
thesis_editor.py进行章节重排、内容重组
- 执行批量文本替换和格式调整
- 更新目录和页码管理
-
格式规范化阶段:
- 使用
format_manager.py应用学校格式规范
- 标准化字体、字号、行距、页边距等格式
- 修复标题样式和段落格式
-
质量检查阶段:
- 使用
quality_checker.py验证格式和内容完整性
- 生成质量检查报告和改进建议
- 确保符合学术规范
-
输出验证阶段:
- 检查最终文档,确保所有修改正确应用
- 生成最终报告,记录所有变更
- 保存为新的.docx文件
创建新论文的简化工作流
- 准备配置:检查
config/formats/中的格式规范,config/templates/中的模板文件
- 选择工作流:
- 生成新论文:使用
template_engine.py基于模板创建
- 格式规范化:使用
format_manager.py应用格式规范
- 质量检查:使用
quality_checker.py验证文档质量
- 批量处理:使用
batch_processor.py处理多个文档
- 执行操作:调用对应脚本函数完成操作
- 验证结果:检查输出文档,生成质量报告
关键注意事项
- Word版本:使用
Word.Application自动连接,兼容Word 2010-2025各版本
- 后台运行:默认
visible=False后台运行,调试时可设为True
- 模板系统:支持占位符替换和内容结构化填充
- 格式规范:基于JSON配置文件,可扩展支持多学校格式
- 目录生成:正确应用标题样式后自动生成可点击目录
- 错误处理:完善的异常处理和日志系统
配置文件说明
格式规范 (config/formats/)
{
"学校名称": "福建技术师范学院",
"页面设置": { "上边距": "2.54cm", "下边距": "2.54cm" },
"字体规范": { "中文标题": "黑体", "正文中文": "宋体" },
"字号规范": { "论文题目": "小二(18pt)", "一级标题": "三号(16pt)" }
}
模板文件 (config/templates/)
undergraduate_thesis_template.docx:本科毕业论文模板
- 支持自定义占位符:
{{title}}, {{author}}, {{abstract}}等
全局设置 (config/settings.yaml)
word_app:
visible: false
version: auto
timeout: 30
templates:
default: undergraduate_thesis_template.docx
path: ./config/templates/
output:
backup: true
log_level: INFO
示例代码
查看 examples/ 目录获取完整使用示例:
01_basic_thesis_generation.py:基础论文生成
02_format_application.py:格式规范化
03_content_generation.py:智能内容填充
04_quality_check.py:质量检查
05_batch_processing.py:批量处理
工作流管理器(新增功能)
工作流管理器 (workflow_manager.py) 是系统的核心协调器,提供以下功能:
预定义工作流
- 文档分析工作流 (
document_analysis):自动执行文档结构分析、格式检查、质量验证和报告生成
- 文档编辑工作流 (
document_editing):打开文档、应用格式规范、更新目录、保存编辑后文档
- 文档生成工作流 (
document_generation):从模板生成完整论文文档
- 批量处理工作流 (
batch_processing):批量扫描、处理和汇总多个文档
使用方法
from workflow_manager import WorkflowManager
manager = WorkflowManager()
workflows = manager.list_workflows()
result = manager.execute("document_analysis", {
"doc_path": "论文.docx",
"config_path": "config/formats/fujian_tech_college.json",
"output_dir": "./output"
})
custom_steps = [
{
"name": "analyze",
"module": "document_analyzer",
"method": "analyze_document",
"parameters": {"doc_path": "${doc_path}"}
},
{
"name": "check",
"module": "format_checker",
"method": "check_document_format",
"parameters": {"doc_path": "${doc_path}", "config_path": "${config_path}"}
}
]
manager.create_custom_workflow("my_workflow", custom_steps, "custom", "我的自定义工作流")
命令行使用
python scripts/cli_interface.py workflow list
python scripts/cli_interface.py workflow execute document_analysis --input 论文.docx
python scripts/cli_interface.py analyze 论文.docx
故障排除
常见问题请参考 references/troubleshooting.md:
- Word COM连接失败
- 目录生成不正确
- 格式应用异常
- 模板解析错误