Skip to content

feat(paper): 重构 FAROS paper 写作流程,引入 compile/review 多 agent 反馈循环 - #42

Merged
Icakacm merged 10 commits into
devtzbfrom
devtzb_paper
Aug 12, 2026
Merged

Icakacm merged 10 commits into
devtzbfrom
devtzb_paper

Conversation

@Ironknory

Copy link
Copy Markdown
Collaborator

概述

本 PR 重构了 FAROS paper 模块的论文写作流程和前端页面,引入了多 agent 协作的论文生成与反馈修改循环。

新的 paper writing 流程中,三个 agent 分工如下:

  • Writing agent:负责论文撰写和根据反馈进行局部修改
  • LaTeX compile agent:负责 LaTeX 编译,并只返回编译反馈
  • Simple review agent:负责格式、规范、图表、artifact 使用情况等非原理性审查,并只返回审查反馈

Compile agent 和 review agent 不直接修改论文内容。所有修改都由 writing agent 根据反馈进行。

主要改动

后端

  • 使用独立的 LaTeX compile agent 替代原有 compile 步骤。
  • 移除旧的 compile_pdf / 通用 figure 生成路径。
  • 删除 figure_generate,避免论文中引入通用占位图表。
  • 引入反馈修改循环:
    • Writing -> Compile
    • Compile 失败或有问题时,反馈给 Writing 修改
    • Compile 通过后,交给 Simple review
    • Review 有修改意见时,反馈给 Writing 修改
    • Writing 修改后进入下一轮 Compile
  • 细化论文最终状态:
    • 只有 LaTeX 编译成功且 simple review 通过时,才标记为完成
    • 区分编译失败和 review 后仍有问题
  • 完善 code evidence 收集:
    • 支持收集 CART 结构下的代码成果、实验指标、实验结果、图表和分析
    • Brief 中不直接拷贝 code artifact 的图表内容,而是通过 label、文件名、位置和分析信息进行关联
  • 重整 paper artifacts:
    • artifact 改为 JSON-only
    • feedback artifact 按 loop round 组织:
      • artifacts/feedback/round_XX/compile.json
      • artifacts/feedback/round_XX/review.json
      • artifacts/feedback/round_XX/rewrite_compile.json
      • artifacts/feedback/round_XX/rewrite_review.json

前端

  • 将 paper writing 前端重构为 4 步流程:
    1. 起始阶段:paper、template、模块链接和 evidence 展示
    2. Brief 阶段:paper brief 和 section brief 编辑
    3. Feedback writing 阶段:展示 agent 交互、步骤计时和反馈循环
    4. 结果展示阶段:展示论文文件和 PDF 预览
  • 点击 new paper 后直接进入 4 步 writing 页面。
  • Template 决定论文模板和 venue,不再单独选择 venue。
  • 在 paper 列表中增加删除论文功能。
  • 改进 agent feedback 展示:
    • 按 loop round 分组
    • 每个 round 内先显示 compile feedback,再显示 review feedback
    • compile/review 无修改意见时也明确显示 success / no feedback
    • rewrite artifact 只表示 writing agent 的修改结果,不再被当作 review feedback
  • 细化 paper 前端显示状态:
    • Created
    • Generating
    • Loop revising
    • Compile failed
    • Review issues
    • Review passed

验证

已在 FAROS conda 环境中运行相关测试:

conda run -n faros pytest \
  backend/tests/test_paper_agent_feedback.py \
  backend/tests/test_paper_code_evidence.py \
  backend/tests/test_paper_prompt_formatting.py \
  backend/tests/test_paper_latex_safety.py

测试结果:

56 passed

说明

本 PR 中 compile agent 和 review agent 均保持只读,不直接修改论文。所有实际论文内容修改都由 writing agent 根据反馈执行。

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the FAROS “paper” module into a multi-agent feedback loop (writing → LaTeX compile → simple review → writing revisions), updates artifact layout to JSON-only feedback rounds, and revamps the frontend into a 4-stage paper-writing workspace with richer status/feedback visualization.

Changes:

  • Introduces dedicated compile/review agents and an orchestrator-driven loop; refines completion criteria (compile success + review passed) and persists compile/review status fields.
  • Reworks evidence collection and prompt formatting to include code-stage evidence/tables/figures (without copying raw artifact bodies into the manuscript).
  • Replaces the paper UI flow with a new multi-step workspace, updated routes, paper deletion, and unified display status mapping.

Reviewed changes

Copilot reviewed 40 out of 41 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
frontend/src/pages/Papers/PaperWritingWorkspace.tsx New 4-stage writing workspace UI (start/brief/writing/result) with feedback-loop rendering and file/PDF preview.
frontend/src/pages/Papers/paperStatus.ts Adds derived display statuses (loop revising / compile failed / review issues / review passed) with label/class helpers.
frontend/src/pages/Papers/PapersList.tsx Navigates into new workspace flow, adds delete paper action, and switches status rendering to derived display status helpers.
frontend/src/pages/Papers/PaperEditor.tsx Updates legacy editor badge rendering to use derived display status helpers.
frontend/src/App.tsx Routes papers to the new workspace (/papers/:id/:stage) and moves legacy editor to /papers/legacy/:id.
backend/tests/test_paper_prompt_formatting.py Extends prompt-formatting tests (FakeClient sequencing, truncated outline fallback, simple review prompt evidence audit).
backend/tests/test_paper_latex_safety.py Adds tests for LaTeX preflight sanitization, storage path safety, rewrite sanitization, and PDF render status fields.
backend/data/plan_packages/demo_ppkg_math.json Removes demo plan package JSON.
backend/app/storage/paper_storage.py Adds compile/pdf fields defaults, delete_paper, and path traversal protection for write_paper_file.
backend/app/services/pdf_renderer.py Adds latexmk compile timeout handling and better timeout error reporting.
backend/app/modules/paper/storage.py Re-exports delete_paper.
backend/app/modules/paper/skills/utils.py Introduces reset_artifacts_dir and stable JSON-only artifact paths; expands collected context with code evidence/tables.
backend/app/modules/paper/skills/section_writers/experiments.py Adds code table artifact guidance in experiments writer prompt.
backend/app/modules/paper/skills/section_writers/base.py Tightens figure requirements; expands prompt context budgets; adjusts figure/table requirement triggering.
backend/app/modules/paper/skills/section_write.py Stops emitting section_write artifacts (artifacts list now empty).
backend/app/modules/paper/skills/section_rewrite.py Adds Markdown→LaTeX sanitizers (inline code/emphasis) and removes rewrite artifact emission.
backend/app/modules/paper/skills/review_feedback.py New compile-feedback and simple-review feedback prompt builders (JSON schema) with source bundling.
backend/app/modules/paper/skills/qa_audit.py Replaces legacy evidence gates summary with evidence-usage suggestions extracted from simple reviews.
backend/app/modules/paper/skills/paper_brief.py Incorporates code-stage evidence into brief prompts and normalizes must-use evidence/figures from code artifacts.
backend/app/modules/paper/skills/outline.py Adds compact retry prompt and robust fallback outline generation without injecting default references.
backend/app/modules/paper/skills/leader.py Renames default chain semantics to writing-only chain; removes compile/figure/evidence gates steps from chain.
backend/app/modules/paper/skills/latex_compile_support.py Adds preflight text-special sanitization, skips artifacts dir, and replaces compile step with compile_latex_once result fields.
backend/app/modules/paper/skills/figure_generate.py Removes generic figure generation skill.
backend/app/modules/paper/skills/evidence_collect.py Collects both plan and code evidence and writes combined evidence record.
backend/app/modules/paper/skills/collect_context.py Stops emitting collect_context artifacts (artifacts list now empty).
backend/app/modules/paper/skills/code_evidence.py New code-stage evidence collector (repo/runs/experiments/CART summaries) and artifact materialization helpers.
backend/app/modules/paper/skills/code_artifact_collect.py New step to materialize code figures/tables into the paper LaTeX tree and merge into context summaries.
backend/app/modules/paper/skills/init.py Exposes build_writing_skill_chain.
backend/app/modules/paper/service.py Switches generation to PaperAgentOrchestrator loop; resets artifacts; updates final status fields; refactors skill running helpers.
backend/app/modules/paper/papers_api.py Adds delete and metadata PATCH endpoints; records PDF render status (latexmk vs fallback) with compile errors.
backend/app/modules/paper/agents/writing.py New writing agent that runs writing-only skills and applies compile/review feedback via targeted rewrites.
backend/app/modules/paper/agents/simple_review.py New simple review agent with evidence-usage audit + iterative review/repair loop.
backend/app/modules/paper/agents/orchestrator.py New orchestrator to sequence writing → compile → (optional) review.
backend/app/modules/paper/agents/latex_compile.py New compile agent with iterative compile-feedback loop and targeted rewrite application.
backend/app/modules/paper/agents/base.py New shared agent base for timing/logging and ctx data application.
backend/app/modules/paper/agents/init.py Exports new paper agents/orchestrator.
backend/app/modules/code/tests/test_challenge_cup_code.py Adds regression test for zip directory entries without trailing slash.
backend/app/modules/code/code_bundle_import.py Improves safe zip extraction handling for implicit directory entries.
backend/app/llm/provider_client.py Plumbs timeout kwarg into provider API config.
backend/app/faros/capabilities/adapters/paper_drafting.py Populates compile/pdf render fields for provider-backed drafting payloads.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread backend/app/modules/paper/service.py Resolved
Comment thread backend/app/storage/paper_storage.py Outdated
Comment on lines +123 to +128
def delete_paper(paper_id: str) -> bool:
paper_dir = os.path.join(PAPERS_DIR, paper_id)
if not os.path.isdir(paper_dir):
return False
shutil.rmtree(paper_dir)
return True
Comment on lines +1514 to +1524
{paperDisplayStatusLabel(selectedPaper) === 'Review passed'
? 'PDF is being generated...'
: selectedPaper.status === 'generating'
: paperDisplayStatusLabel(selectedPaper) === 'Generating'
? 'Paper generation in progress...'
: 'Generate the paper to see the PDF preview.'}
: paperDisplayStatusLabel(selectedPaper) === 'Loop revising'
? 'Agent feedback loop is revising the paper...'
: paperDisplayStatusLabel(selectedPaper) === 'Compile failed'
? 'LaTeX compile failed; review compile feedback before previewing the PDF.'
: paperDisplayStatusLabel(selectedPaper) === 'Review issues'
? 'Review loop ended with remaining issues.'
: 'Generate the paper to see the PDF preview.'}
@Icakacm
Icakacm merged commit 255db38 into devtzb Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants