PaperOrchestra section-writing-agent
Step 4 of the PaperOrchestra pipeline (arXiv:2604.05018). ONE single multimodal LLM call that drafts the remaining paper sections (Abstract, Methodology, Experiments, Conclusion), extracts numeric values from experimental_log.md into LaTeX booktabs tables, splices the generated figures from Step 2, and merges everything into the template that already contains Intro + Related Work from Step 3. TRIGGER when the orchestrator delegates Step 4 or when the user asks to "write the methodology and experiments sections" or "fill in the rest of the paper".
git clone https://github.com/Ar9av/PaperOrchestra
T=$(mktemp -d) && git clone --depth=1 https://github.com/Ar9av/PaperOrchestra "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/section-writing-agent" ~/.claude/skills/ar9av-paperorchestra-section-writing-agent && rm -rf "$T"
skills/section-writing-agent/SKILL.mdSection Writing Agent (Step 4)
Faithful implementation of the Section Writing Agent from PaperOrchestra (Song et al., 2026, arXiv:2604.05018, §4 Step 4, App. F.1 pp. 47–49).
Cost: ONE LLM call (App. B: "Section Writing Agent (1 call): A single, comprehensive multimodal call to draft and compile the complete LaTeX manuscript"). Do NOT split this into per-section calls — the paper explicitly designs it as one comprehensive call so the model can maintain global coherence across sections.
Inputs
— the master planworkspace/outline.json
— technical detailsworkspace/inputs/idea.md
— raw data for tables and qualitative analysisworkspace/inputs/experimental_log.md
— the template with Intro + Related Work already filled in by Step 3. This is your starting point. The preamble, package list, style, and the two pre-filled sections must be preserved verbatim.workspace/drafts/intro_relwork.tex
— the citation map (workspace/citation_pool.json
for each verified paper){key, title, abstract}
— the BibTeX fileworkspace/refs.bib
— formatting rulesworkspace/inputs/conference_guidelines.md
— the actual PNG files from Step 2 (used as multimodal vision input!)workspace/figures/
— caption text per figure_idworkspace/figures/captions.json
— TeX package availability flags (written byworkspace/tex_profile.json
at Step 0). Read this before generating any LaTeX. It tells you which packages are installed so you select the right cross-reference pattern, font packages, etc. before you write — not after you try to compile.check_tex_packages.py
Output
— the complete LaTeX paper, with all sections filled. The Step 5 Refinement Agent will iterate on this file.workspace/drafts/paper.tex
How to do it
0.5. Read tex_profile.json and select LaTeX patterns
Before composing the prompt, read
workspace/tex_profile.json and apply
these rules to every LaTeX choice in the generated paper:
| Profile flag | True → use | False → use instead |
|---|---|---|
| , | , |
| | |
| | omit the line |
| | omit the line |
If
tex_profile.json does not exist (old workspace), default to the safe
fallback column (no cleveref, no nicefrac, no microtype, no T1 fontenc).
1. Pre-extract metrics from the experimental log
Run the deterministic helper:
python skills/section-writing-agent/scripts/extract_metrics.py \ --log workspace/inputs/experimental_log.md \ --out workspace/metrics.json
This parses the
## 2. Raw Numeric Data section's markdown tables into
structured JSON. The Section Writing Agent uses this to construct LaTeX
booktabs tables without re-deriving values from raw text. Read
references/latex-table-patterns.md for the booktabs conventions.
2. Compose the prompt and make ONE multimodal call
Load
references/prompt.md (verbatim Section Writing Agent prompt from App.
F.1). Prepend the Anti-Leakage Prompt from
../paper-orchestra/references/anti-leakage-prompt.md.
The user message contains:
— full contentoutline.json
— full contentidea.md
— full content (tables AND prose)experimental_log.md
— full content (this becomesintro_relwork.tex
for the prompt)template.tex
— full content (becomescitation_pool.json
)citation_map.json
— full contentconference_guidelines.md
— array offigures_list
from{figure_id, filename, caption}
and the file listingcaptions.json- The actual figure PNGs as multimodal image inputs, so the model can visually inspect them and write accurate descriptions / refer to them correctly in the prose.
If your host LLM has no vision input, fall back to text-only mode: pass the captions in
captions.json as descriptions and tell the agent it cannot see
the images directly. Quality drops noticeably (the paper notes that visual
grounding measurably improves figure-text alignment), but the pipeline
still completes.
3. Save the output
The agent's response is wrapped in
\``latex ... ```fences. Extract the LaTeX code and save toworkspace/drafts/paper.tex`.
4. Run the deterministic gates
# Orphan citation gate: every \cite{KEY} must exist in refs.bib python skills/section-writing-agent/scripts/orphan_cite_gate.py \ workspace/drafts/paper.tex workspace/refs.bib # Latex sanity: matched braces, matched begin/end, no unescaped specials python skills/section-writing-agent/scripts/latex_sanity.py \ workspace/drafts/paper.tex # Anti-leakage post-check: no author names, emails, affiliations python skills/paper-orchestra/scripts/anti_leakage_check.py \ workspace/drafts/paper.tex
If any gate fails, re-prompt the writing call with the gate's error report appended to the user message and ask the agent to fix the specific issues. Do NOT try to fix the gate violations by hand — the model needs to see its own mistakes.
Critical rules from the prompt
These are excerpted from
references/prompt.md (App. F.1, pp. 47-49). The
host agent MUST honor them on the writing call:
Existing-content preservation
- DO NOT modify the text, style, or content of sections that are already
filled in
. Preserve Intro + Related Work verbatim.intro_relwork.tex - Keep the preamble (packages, document class, style) exactly as is.
- Come up with a good title if one is missing. Fill author names if missing (but the Anti-Leakage Prompt says not to invent real ones — use a placeholder like "Anonymous Authors" for double-blind).
Data and tables
- Build LaTeX tables for the experimental results.
- Extract numeric values directly from
. Do not hallucinate numbers — use the exact values in the log.experimental_log.md - Use the
package format:booktabs
,\toprule
,\midrule
.\bottomrule - All tables must appear before the Conclusion section, unless they are explicitly placed in an Appendix.
Citations
- The
provides citation_hints per subsection. For each hint, find the matching key inoutline.json
(by title or content) and use that exact key incitation_pool.json
.\cite{...} - Use ONLY keys from
. Inventing or guessing keys violates the Lit Review Agent's verified pool.refs.bib - Read the abstract from
for the papers you cite. Use the abstract context to write specific, accurate sentences about those works — not generic "[A, B] proposed methods for X".citation_pool.json
Writing content
- Write the missing sections following
'soutline.json
structure exactly. Hierarchy rule: if 4.1 exists, 4.2 must exist.section_plan - Use formal mathematical equations, notations, and definitions where
appropriate AND directly supported by
oridea.md
. Do not hallucinate math. Do not use complex math just for the sake of it.experimental_log.md - Always provide detailed ablation studies and qualitative analysis of the experimental results: what worked, what does not, and why.
- Optional: discuss limitations and future work at the end.
- If you put anything in the Appendix, the Appendix section appears AFTER the References section, on a fresh new page.
Figures and visual fidelity
- You are being given the actual image files of the figures. You MUST describe them faithfully and accurately. Do NOT hallucinate interpretations that contradict the visual evidence in the plots.
- Use ALL of the figures provided in
. Use the exact filenames including extensions (e.g.,figures/
) in your.png
commands.\includegraphics - DO NOT merge or group multiple figures into one display.
- If the paper is in a 2-column format, prefer single-column figures
(
) unless they are very wide.\begin{figure} - All figures must appear before the Conclusion section, unless explicitly in the Appendix.
- Refine the captions if necessary, but they are already provided in
and should generally be used as-is.captions.json - Do NOT include "Figure X" in the caption text — LaTeX handles numbering.
Style
- Adopt the tone of a top-tier ML conference paper: dense, objective, technical.
- Match the indentation and spacing style of the original
. Do not change the overall LaTeX style.template.tex
LaTeX integrity
- The output must compile flawlessly out-of-the-box.
- All
must match a\begin{X}
(e.g.,\end{X}
must be closed with\begin{figure*}
, not\end{figure*}
).\end{figure} - DO NOT change
to\usepackage[capitalize]{cleveref}
— there is no\usepackage[capitalize]{cleverref}
.cleverref.sty - Always emit
immediately before\clearpage
. Without it, figures deferred by LaTeX's float algorithm will appear inside or after the References section — a hard-to-spot layout defect that only shows up in the compiled PDF.\bibliographystyle{...}
forces all pending floats to be output before the bibliography starts. See\clearpage
for details.references/latex-table-patterns.md - Cross-references: prefer
andFigure~\ref{fig:X}
over bareTable~\ref{tab:Y}
. This is necessary when\ref{fig:X}
is unavailable and produces readable prose in all cases. Usecleveref
only when\cref{...}
is confirmed present.cleveref.sty
Output format
- Wrap the full updated
intemplate.tex
``latex ... ````.\ - The previously empty sections should now be filled.
- Previously filled sections (Intro, Related Work) should remain mostly untouched; only adjust for consistency purposes.
Resources
— verbatim Section Writing Agent prompt from App. F.1references/prompt.md
— booktabs rules + table-from-log examplesreferences/latex-table-patterns.md
—references/figure-integration.md
, 2-column handling, placement\includegraphics
— markdown tables in experimental_log → JSONscripts/extract_metrics.py
— unmatched braces, env mismatches, specialsscripts/latex_sanity.py
— everyscripts/orphan_cite_gate.py
exists in refs.bib\cite{KEY}