{"slug":"section-writing-agent","title":"section-writing-agent","summary":"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 f","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-09-24T15:42:15.147991Z","repo":{"url":"https://github.com/Ar9av/PaperOrchestra","stars":663,"forks":92,"license":null,"updatedAt":"2026-09-21T17:10:41Z"},"bodyHtml":"<hr>\n<h2>name: section-writing-agent\ndescription: 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\".</h2>\n<h1>Section Writing Agent (Step 4)</h1>\n<p>Faithful implementation of the Section Writing Agent from PaperOrchestra\n(Song et al., 2026, arXiv:2604.05018, §4 Step 4, App. F.1 pp. 47–49).</p>\n<p><strong>Cost: ONE LLM call</strong> (App. B: \"Section Writing Agent (1 call): A single,\ncomprehensive multimodal call to draft and compile the complete LaTeX\nmanuscript\"). Do NOT split this into per-section calls — the paper\nexplicitly designs it as one comprehensive call so the model can maintain\nglobal coherence across sections.</p>\n<h2>Inputs</h2>\n<ul>\n<li><code>workspace/outline.json</code> — the master plan</li>\n<li><code>workspace/inputs/idea.md</code> — technical details</li>\n<li><code>workspace/inputs/experimental_log.md</code> — raw data for tables and qualitative analysis</li>\n<li><code>workspace/drafts/intro_relwork.tex</code> — the template <strong>with Intro + Related\nWork already filled in by Step 3</strong>. This is your starting point. The\npreamble, package list, style, and the two pre-filled sections must be\npreserved verbatim.</li>\n<li><code>workspace/citation_pool.json</code> — the citation map (<code>{key, title, abstract}</code>\nfor each verified paper)</li>\n<li><code>workspace/refs.bib</code> — the BibTeX file</li>\n<li><code>workspace/inputs/conference_guidelines.md</code> — formatting rules</li>\n<li><code>workspace/figures/</code> — the actual PNG files from Step 2 (used as\nmultimodal vision input!)</li>\n<li><code>workspace/figures/captions.json</code> — caption text per figure_id</li>\n<li><code>workspace/tex_profile.json</code> — TeX package availability flags (written by\n<code>check_tex_packages.py</code> at Step 0). <strong>Read this before generating any\nLaTeX.</strong> It tells you which packages are installed so you select the right\ncross-reference pattern, font packages, etc. before you write — not after\nyou try to compile.</li>\n</ul>\n<h2>Output</h2>\n<ul>\n<li><code>workspace/drafts/paper.tex</code> — the complete LaTeX paper, with all sections\nfilled. The Step 5 Refinement Agent will iterate on this file.</li>\n</ul>\n<h2>How to do it</h2>\n<h3>0.5. Read tex_profile.json and select LaTeX patterns</h3>\n<p>Before composing the prompt, read <code>workspace/tex_profile.json</code> and apply\nthese rules to every LaTeX choice in the generated paper:</p>\n<table>\n<thead>\n<tr>\n<th>Profile flag</th>\n<th>True → use</th>\n<th>False → use instead</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>use_cleveref</code></td>\n<td><code>\\cref{fig:X}</code>, <code>\\cref{tab:Y}</code></td>\n<td><code>Figure~\\ref{fig:X}</code>, <code>Table~\\ref{tab:Y}</code></td>\n</tr>\n<tr>\n<td><code>use_nicefrac</code></td>\n<td><code>\\nicefrac{a}{b}</code></td>\n<td><code>$a/b$</code></td>\n</tr>\n<tr>\n<td><code>use_microtype</code></td>\n<td><code>\\usepackage{microtype}</code></td>\n<td>omit the line</td>\n</tr>\n<tr>\n<td><code>use_t1_fontenc</code></td>\n<td><code>\\usepackage[T1]{fontenc}</code></td>\n<td>omit the line</td>\n</tr>\n</tbody>\n</table>\n<p>If <code>tex_profile.json</code> does not exist (old workspace), default to the safe\nfallback column (no cleveref, no nicefrac, no microtype, no T1 fontenc).</p>\n<h3>1. Pre-extract metrics from the experimental log</h3>\n<p>Run the deterministic helper:</p>\n<pre><code>python skills/section-writing-agent/scripts/extract_metrics.py \\\n    --log workspace/inputs/experimental_log.md \\\n    --out workspace/metrics.json\n</code></pre>\n<p>This parses the <code>## 2. Raw Numeric Data</code> section's markdown tables into\nstructured JSON. The Section Writing Agent uses this to construct LaTeX\nbooktabs tables without re-deriving values from raw text. Read\n<code>references/latex-table-patterns.md</code> for the booktabs conventions.</p>\n<h3>2. Compose the prompt and make ONE multimodal call</h3>\n<p>Load <code>references/prompt.md</code> (verbatim Section Writing Agent prompt from App.\nF.1). Prepend the Anti-Leakage Prompt from\n<code>../paper-orchestra/references/anti-leakage-prompt.md</code>.</p>\n<p>Then append the <strong>craft constraints</strong> for the sections being drafted. Pull\nthem from <code>skills/shared/section_rhetoric.md</code> — the global rules plus only\nthe templates for Abstract, Method, Experiments, and Conclusion (Intro and\nRelated Work are already written by Step 3; do not re-open them). The App.\nF.1 prompt specifies what each section must <em>contain</em>; the rhetoric\ntemplates specify the paragraph roles and their order. Without them the\nmodel produces content-complete sections whose paragraphs all make the same\nkind of move, which the Step 5 reviewer scores down on Logical Flow.</p>\n<p>The user message contains:</p>\n<ul>\n<li><code>outline.json</code> — full content</li>\n<li><code>idea.md</code> — full content</li>\n<li><code>experimental_log.md</code> — full content (tables AND prose)</li>\n<li><code>intro_relwork.tex</code> — full content (this becomes <code>template.tex</code> for the prompt)</li>\n<li><code>citation_pool.json</code> — full content (becomes <code>citation_map.json</code>)</li>\n<li><code>conference_guidelines.md</code> — full content</li>\n<li><code>figures_list</code> — array of <code>{figure_id, filename, caption}</code> from\n<code>captions.json</code> and the file listing</li>\n<li><strong>The actual figure PNGs</strong> as multimodal image inputs, so the model can\nvisually inspect them and write accurate descriptions / refer to them\ncorrectly in the prose.</li>\n</ul>\n<p>If your host LLM has no vision input, fall back to text-only mode: pass the\ncaptions in <code>captions.json</code> as descriptions and tell the agent it cannot see\nthe images directly. Quality drops noticeably (the paper notes that visual\ngrounding measurably improves figure-text alignment), but the pipeline\nstill completes.</p>\n<h3>3. Save the output</h3>\n<p>The agent's response is wrapped in <code>\\</code>``latex ... ```` fences. Extract\nthe LaTeX code and save to <code>workspace/drafts/paper.tex</code>.</p>\n<h3>4. Run the deterministic gates</h3>\n<pre><code># Orphan citation gate: every \\cite{KEY} must exist in refs.bib\npython skills/section-writing-agent/scripts/orphan_cite_gate.py \\\n    workspace/drafts/paper.tex workspace/refs.bib\n\n# Latex sanity: matched braces, matched begin/end, no unescaped specials\npython skills/section-writing-agent/scripts/latex_sanity.py \\\n    workspace/drafts/paper.tex\n\n# Anti-leakage post-check: no author names, emails, affiliations\npython skills/paper-orchestra/scripts/anti_leakage_check.py \\\n    workspace/drafts/paper.tex\n\n# Table conventions: booktabs rules, caption placement, metric direction,\n# decimal precision. ERRORs block; WARNs go into the re-prompt.\npython skills/section-writing-agent/scripts/table_lint.py \\\n    workspace/drafts/paper.tex\n</code></pre>\n<p>If any gate fails, <strong>re-prompt the writing call</strong> with the gate's error\nreport appended to the user message and ask the agent to fix the specific\nissues. Do NOT try to fix the gate violations by hand — the model needs to\nsee its own mistakes.</p>\n<h2>Critical rules from the prompt</h2>\n<p>These are excerpted from <code>references/prompt.md</code> (App. F.1, pp. 47-49). The\nhost agent MUST honor them on the writing call:</p>\n<h3>Existing-content preservation</h3>\n<ul>\n<li>DO NOT modify the text, style, or content of sections that are already\nfilled in <code>intro_relwork.tex</code>. Preserve Intro + Related Work verbatim.</li>\n<li>Keep the preamble (packages, document class, style) <strong>exactly</strong> as is.</li>\n<li>Come up with a good title if one is missing. Fill author names if missing\n(but the Anti-Leakage Prompt says not to invent real ones — use a\nplaceholder like \"Anonymous Authors\" for double-blind).</li>\n</ul>\n<h3>Data and tables</h3>\n<ul>\n<li>Build LaTeX tables for the experimental results.</li>\n<li>Extract numeric values directly from <code>experimental_log.md</code>. <strong>Do not\nhallucinate numbers</strong> — use the exact values in the log.</li>\n<li>Use the <code>booktabs</code> package format: <code>\\toprule</code>, <code>\\midrule</code>, <code>\\bottomrule</code>.</li>\n<li>All tables must appear before the Conclusion section, unless they are\nexplicitly placed in an Appendix.</li>\n</ul>\n<h3>Citations</h3>\n<ul>\n<li>The <code>outline.json</code> provides citation_hints per subsection. For each hint,\nfind the matching key in <code>citation_pool.json</code> (by title or content) and\nuse that exact key in <code>\\cite{...}</code>.</li>\n<li><strong>Use ONLY keys from <code>refs.bib</code>.</strong> Inventing or guessing keys violates the\nLit Review Agent's verified pool.</li>\n<li><strong>Read the abstract</strong> from <code>citation_pool.json</code> for the papers you cite.\nUse the abstract context to write specific, accurate sentences about\nthose works — not generic \"[A, B] proposed methods for X\".</li>\n</ul>\n<h3>Writing content</h3>\n<ul>\n<li>Write the missing sections following <code>outline.json</code>'s <code>section_plan</code>\nstructure exactly. Hierarchy rule: if 4.1 exists, 4.2 must exist.</li>\n<li>Use formal mathematical equations, notations, and definitions where\nappropriate AND directly supported by <code>idea.md</code> or <code>experimental_log.md</code>.\n<strong>Do not hallucinate math.</strong> Do not use complex math just for the sake\nof it.</li>\n<li>Always provide detailed ablation studies and qualitative analysis of the\nexperimental results: what worked, what does not, and why.</li>\n<li>Optional: discuss limitations and future work at the end.</li>\n<li>If you put anything in the Appendix, the Appendix section appears AFTER\nthe References section, on a fresh new page.</li>\n</ul>\n<h3>Figures and visual fidelity</h3>\n<ul>\n<li>You are being given the actual image files of the figures. You MUST\ndescribe them faithfully and accurately. Do NOT hallucinate\ninterpretations that contradict the visual evidence in the plots.</li>\n<li>Use ALL of the figures provided in <code>figures/</code>. Use the exact filenames\nincluding extensions (e.g., <code>.png</code>) in your <code>\\includegraphics</code> commands.</li>\n<li>DO NOT merge or group multiple figures into one display.</li>\n<li>If the paper is in a 2-column format, prefer single-column figures\n(<code>\\begin{figure}</code>) unless they are very wide.</li>\n<li>All figures must appear before the Conclusion section, unless explicitly\nin the Appendix.</li>\n<li>Refine the captions if necessary, but they are already provided in\n<code>captions.json</code> and should generally be used as-is.</li>\n<li>Do NOT include \"Figure X\" in the caption text — LaTeX handles numbering.</li>\n</ul>\n<h3>Rhetorical structure</h3>\n<p>Templates and checklists live in <code>skills/shared/section_rhetoric.md</code>. The\nconstraints the writing call must honor:</p>\n<ul>\n<li><strong>One paragraph, one message, stated in the first sentence.</strong> A paragraph\nwhose point arrives in sentence five is a paragraph reviewers skim.</li>\n<li><strong>Abstract</strong> follows one of three templates, chosen by contribution count:\nChallenge→Contribution, Challenge→Insight→Contribution, or\nmultiple-contributions (each contribution paired with its advantage <em>in the\nsame sentence</em>).</li>\n<li><strong>Method subsections carry the triad</strong> — design (the forward process as\n<code>input → step → step → output</code>), then motivation (<em>because X fails, we\ndesign Y</em>), then technical advantage. Design-only subsections read as a\nsystem manual; motivation-only subsections read as a pitch.</li>\n<li><strong>Experiments answers three questions</strong>: better than strong baselines,\nwhich design choices produce the gain (ablations as deltas), and how far it\ngeneralizes. Every contribution claimed in the Introduction maps to at\nleast one experiment.</li>\n<li><strong>Conclusion limitations are scope boundaries, not defects.</strong> \"We evaluate\nonly on short sequences\" bounds the method; \"we did not tune the learning\nrate\" invites rejection.</li>\n<li><strong>Terminology is frozen</strong> across Abstract→Conclusion. One name per concept.</li>\n</ul>\n<h3>Style</h3>\n<ul>\n<li>Adopt the tone of a top-tier ML conference paper: dense, objective,\ntechnical.</li>\n<li>Match the indentation and spacing style of the original <code>template.tex</code>.\nDo not change the overall LaTeX style.</li>\n</ul>\n<h3>LaTeX integrity</h3>\n<ul>\n<li>The output must compile flawlessly out-of-the-box.</li>\n<li>All <code>\\begin{X}</code> must match a <code>\\end{X}</code> (e.g., <code>\\begin{figure*}</code> must be\nclosed with <code>\\end{figure*}</code>, not <code>\\end{figure}</code>).</li>\n<li>DO NOT change <code>\\usepackage[capitalize]{cleveref}</code> to\n<code>\\usepackage[capitalize]{cleverref}</code> — there is no <code>cleverref.sty</code>.</li>\n<li><strong>Always emit <code>\\clearpage</code> immediately before <code>\\bibliographystyle{...}</code>.</strong>\nWithout it, figures deferred by LaTeX's float algorithm will appear inside\nor after the References section — a hard-to-spot layout defect that only\nshows up in the compiled PDF. <code>\\clearpage</code> forces all pending floats to be\noutput before the bibliography starts. See\n<code>references/latex-table-patterns.md</code> for details.</li>\n<li><strong>Cross-references</strong>: prefer <code>Figure~\\ref{fig:X}</code> and <code>Table~\\ref{tab:Y}</code>\nover bare <code>\\ref{fig:X}</code>. This is necessary when <code>cleveref</code> is unavailable\nand produces readable prose in all cases. Use <code>\\cref{...}</code> only when\n<code>cleveref.sty</code> is confirmed present.</li>\n</ul>\n<h3>Output format</h3>\n<ul>\n<li>Wrap the full updated <code>template.tex</code> in <code>\\</code>``latex ... ````.</li>\n<li>The previously empty sections should now be filled.</li>\n<li>Previously filled sections (Intro, Related Work) should remain mostly\nuntouched; only adjust for consistency purposes.</li>\n</ul>\n<h2>Resources</h2>\n<ul>\n<li><code>references/prompt.md</code> — verbatim Section Writing Agent prompt from App. F.1</li>\n<li><code>references/latex-table-patterns.md</code> — booktabs rules + table-from-log examples</li>\n<li><code>references/figure-integration.md</code> — <code>\\includegraphics</code>, 2-column handling, placement</li>\n<li><code>scripts/extract_metrics.py</code> — markdown tables in experimental_log → JSON</li>\n<li><code>scripts/latex_sanity.py</code> — unmatched braces, env mismatches, specials</li>\n<li><code>scripts/orphan_cite_gate.py</code> — every <code>\\cite{KEY}</code> exists in refs.bib</li>\n<li><code>scripts/table_lint.py</code> — <strong>NEW</strong> booktabs rule violations + table readability conventions</li>\n<li><code>skills/shared/section_rhetoric.md</code> — <strong>NEW</strong> per-section structural templates (abstract variants, module triad, experiment questions) + checklists</li>\n</ul>\n","files":[{"path":"references/figure-integration.md","sizeBytes":3594,"isText":true},{"path":"references/latex-table-patterns.md","sizeBytes":7300,"isText":true},{"path":"references/prompt.md","sizeBytes":5410,"isText":true},{"path":"scripts/extract_metrics.py","sizeBytes":3879,"isText":true},{"path":"scripts/latex_sanity.py","sizeBytes":3956,"isText":true},{"path":"scripts/orphan_cite_gate.py","sizeBytes":1912,"isText":true},{"path":"scripts/table_lint.py","sizeBytes":7420,"isText":true},{"path":"scripts/test_table_lint.py","sizeBytes":4221,"isText":true},{"path":"SKILL.md","sizeBytes":13229,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-09-24T15:42:29.790313Z","sha256":"A5257F7EF82969CC09B121684EF42F4184FD34FAC42C7ED3407F609811958E40","sizeBytes":22374},"review":null,"source":{"repositoryUrl":"https://github.com/Ar9av/PaperOrchestra","path":"skills/section-writing-agent","license":null,"commit":"36c3cc4b10370b1f905adcd4e5601e8b624c2dc3","subtreeSha":"29231F3063CF0520C6B8637685369BE0B43C476821EE3DA13AB34F223A02073A","lastSyncedAt":"2026-09-24T15:42:09.852277Z"},"reviewedAt":"2026-09-24T15:42:58.680802Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/Ar9av/PaperOrchestra/tree/main/skills/section-writing-agent"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install ar9av-paperorchestra@llmmart"},{"target":"git","command":"git clone https://github.com/Ar9av/PaperOrchestra.git"}]}