{"id":"section-writing-agent","name":"section-writing-agent","summary":"PaperOrchestraパイプラインのステップ4(arXiv:2604.05018)。残りの論文セクション(要約、方法論、実験、結論)をドラフトし、experimental_log.mdから数値をLaTeXブックタブのテーブルに抽出し、Stepから生成された図をスプライスする単一のマルチモーダルLLM呼び出しだけ…","body":"# Section Writing Agent (Step 4)\n\nFaithful 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).\n\n**Cost: ONE LLM call** (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.\n\n## Inputs\n\n- `workspace/outline.json` — the master plan\n- `workspace/inputs/idea.md` — technical details\n- `workspace/inputs/experimental_log.md` — raw data for tables and qualitative analysis\n- `workspace/drafts/intro_relwork.tex` — the template **with Intro + Related\n  Work already filled in by Step 3**. This is your starting point. The\n  preamble, package list, style, and the two pre-filled sections must be\n  preserved verbatim.\n- `workspace/citation_pool.json` — the citation map (`{key, title, abstract}`\n  for each verified paper)\n- `workspace/refs.bib` — the BibTeX file\n- `workspace/inputs/conference_guidelines.md` — formatting rules\n- `workspace/figures/` — the actual PNG files from Step 2 (used as\n  multimodal vision input!)\n- `workspace/figures/captions.json` — caption text per figure_id\n- `workspace/tex_profile.json` — TeX package availability flags (written by\n  `check_tex_packages.py` at Step 0). **Read this before generating any\n  LaTeX.** It tells you which packages are installed so you select the right\n  cross-reference pattern, font packages, etc. before you write — not after\n  you try to compile.\n\n## Output\n\n- `workspace/drafts/paper.tex` — the complete LaTeX paper, with all sections\n  filled. The Step 5 Refinement Agent will iterate on this file.\n\n## How to do it\n\n### 0.5. Read tex_profile.json and select LaTeX patterns\n\nBefore composing the prompt, read `workspace/tex_profile.json` and apply\nthese rules to every LaTeX choice in the generated paper:\n\n| Profile flag | True → use | False → use instead |\n|---|---|---|\n| `use_cleveref` | `\\cref{fig:X}`, `\\cref{tab:Y}` | `Figure~\\ref{fig:X}`, `Table~\\ref{tab:Y}` |\n| `use_nicefrac` | `\\nicefrac{a}{b}` | `$a/b$` |\n| `use_microtype` | `\\usepackage{microtype}` | omit the line |\n| `use_t1_fontenc` | `\\usepackage[T1]{fontenc}` | omit the line |\n\nIf `tex_profile.json` does not exist (old workspace), default to the safe\nfallback column (no cleveref, no nicefrac, no microtype, no T1 fontenc).\n\n### 1. Pre-extract metrics from the experimental log\n\nRun the deterministic helper:\n\n```bash\npython skills/section-writing-agent/scripts/extract_metrics.py \\\n    --log workspace/inputs/experimental_log.md \\\n    --out workspace/metrics.json\n```\n\nThis parses the `## 2. Raw Numeric Data` 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`references/latex-table-patterns.md` for the booktabs conventions.\n\n### 2. Compose the prompt and make ONE multimodal call\n\nLoad `references/prompt.md` (verbatim Section Writing Agent prompt from App.\nF.1). Prepend the Anti-Leakage Prompt from\n`../paper-orchestra/references/anti-leakage-prompt.md`.\n\nThe user message contains:\n\n- `outline.json` — full content\n- `idea.md` — full content\n- `experimental_log.md` — full content (tables AND prose)\n- `intro_relwork.tex` — full content (this becomes `template.tex` for the prompt)\n- `citation_pool.json` — full content (becomes `citation_map.json`)\n- `conference_guidelines.md` — full content\n- `figures_list` — array of `{figure_id, filename, caption}` from\n  `captions.json` and the file listing\n- **The actual figure PNGs** as multimodal image inputs, so the model can\n  visually inspect them and write accurate descriptions / refer to them\n  correctly in the prose.\n\nIf your host LLM has no vision input, fall back to text-only mode: pass the\ncaptions in `captions.json` 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.\n\n### 3. Save the output\n\nThe agent's response is wrapped in `\\`\\`\\`latex ... \\`\\`\\`` fences. Extract\nthe LaTeX code and save to `workspace/drafts/paper.tex`.\n\n### 4. Run the deterministic gates\n\n```bash\n# 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\nIf any gate fails, **re-prompt the writing call** 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.\n\n## Critical rules from the prompt\n\nThese are excerpted from `references/prompt.md` (App. F.1, pp. 47-49). The\nhost agent MUST honor them on the writing call:\n\n### Existing-content preservation\n\n- DO NOT modify the text, style, or content of sections that are already\n  filled in `intro_relwork.tex`. Preserve Intro + Related Work verbatim.\n- Keep the preamble (packages, document class, style) **exactly** as is.\n- 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\n  placeholder like \"Anonymous Authors\" for double-blind).\n\n### Data and tables\n\n- Build LaTeX tables for the experimental results.\n- Extract numeric values directly from `experimental_log.md`. **Do not\n  hallucinate numbers** — use the exact values in the log.\n- Use the `booktabs` package format: `\\toprule`, `\\midrule`, `\\bottomrule`.\n- All tables must appear before the Conclusion section, unless they are\n  explicitly placed in an Appendix.\n\n### Citations\n\n- The `outline.json` provides citation_hints per subsection. For each hint,\n  find the matching key in `citation_pool.json` (by title or content) and\n  use that exact key in `\\cite{...}`.\n- **Use ONLY keys from `refs.bib`.** Inventing or guessing keys violates the\n  Lit Review Agent's verified pool.\n- **Read the abstract** from `citation_pool.json` for the papers you cite.\n  Use the abstract context to write specific, accurate sentences about\n  those works — not generic \"[A, B] proposed methods for X\".\n\n### Writing content\n\n- Write the missing sections following `outline.json`'s `section_plan`\n  structure exactly. Hierarchy rule: if 4.1 exists, 4.2 must exist.\n- Use formal mathematical equations, notations, and definitions where\n  appropriate AND directly supported by `idea.md` or `experimental_log.md`.\n  **Do not hallucinate math.** Do not use complex math just for the sake\n  of it.\n- Always provide detailed ablation studies and qualitative analysis of the\n  experimental results: what worked, what does not, and why.\n- Optional: discuss limitations and future work at the end.\n- If you put anything in the Appendix, the Appendix section appears AFTER\n  the References section, on a fresh new page.\n\n### Figures and visual fidelity\n\n- You are being given the actual image files of the figures. You MUST\n  describe them faithfully and accurately. Do NOT hallucinate\n  interpretations that contradict the visual evidence in the plots.\n- Use ALL of the figures provided in `figures/`. Use the exact filenames\n  including extensions (e.g., `.png`) in your `\\includegraphics` commands.\n- DO NOT merge or group multiple figures into one display.\n- If the paper is in a 2-column format, prefer single-column figures\n  (`\\begin{figure}`) unless they are very wide.\n- All figures must appear before the Conclusion section, unless explicitly\n  in the Appendix.\n- Refine the captions if necessary, but they are already provided in\n  `captions.json` and should generally be used as-is.\n- Do NOT include \"Figure X\" in the caption text — LaTeX handles numbering.\n\n### Style\n\n- Adopt the tone of a top-tier ML conference paper: dense, objective,\n  technical.\n- Match the indentation and spacing style of the original `template.tex`.\n  Do not change the overall LaTeX style.\n\n### LaTeX integrity\n\n- The output must compile flawlessly out-of-the-box.\n- All `\\begin{X}` must match a `\\end{X}` (e.g., `\\begin{figure*}` must be\n  closed with `\\end{figure*}`, not `\\end{figure}`).\n- DO NOT change `\\usepackage[capitalize]{cleveref}` to\n  `\\usepackage[capitalize]{cleverref}` — there is no `cleverref.sty`.\n- **Always emit `\\clearpage` immediately before `\\bibliographystyle{...}`.**\n  Without it, figures deferred by LaTeX's float algorithm will appear inside\n  or after the References section — a hard-to-spot layout defect that only\n  shows up in the compiled PDF. `\\clearpage` forces all pending floats to be\n  output before the bibliography starts. See\n  `references/latex-table-patterns.md` for details.\n- **Cross-references**: prefer `Figure~\\ref{fig:X}` and `Table~\\ref{tab:Y}`\n  over bare `\\ref{fig:X}`. This is necessary when `cleveref` is unavailable\n  and produces readable prose in all cases. Use `\\cref{...}` only when\n  `cleveref.sty` is confirmed present.\n\n### Output format\n\n- Wrap the full updated `template.tex` in `\\`\\`\\`latex ... \\`\\`\\``.\n- The previously empty sections should now be filled.\n- Previously filled sections (Intro, Related Work) should remain mostly\n  untouched; only adjust for consistency purposes.\n\n## Resources\n\n- `references/prompt.md` — verbatim Section Writing Agent prompt from App. F.1\n- `references/latex-table-patterns.md` — booktabs rules + table-from-log examples\n- `references/figure-integration.md` — `\\includegraphics`, 2-column handling, placement\n- `scripts/extract_metrics.py` — markdown tables in experimental_log → JSON\n- `scripts/latex_sanity.py` — unmatched braces, env mismatches, specials\n- `scripts/orphan_cite_gate.py` — every `\\cite{KEY}` exists in refs.bib","author":"@Ar9av","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/Ar9av/PaperOrchestra/tree/main/skills/section-writing-agent","license":"MIT","category":"writing","lang":"en","tokens":2563,"stars":0,"calls30d":1,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[{"path":"references/figure-integration.md","size":3594,"sha256":"40950e1534ac32542ca79a33061ca8e2357966638d96b7c4d5537509fa412f39"},{"path":"references/latex-table-patterns.md","size":5541,"sha256":"42e5199a23743fe052a854be2b837b937c1c98ee37c2d7b598957e8a8741cb75"},{"path":"references/prompt.md","size":5410,"sha256":"a260bc0da378d0b967a4af2531522e70ba5cb2b8d05b11427c45ced1b8ac9928"},{"path":"scripts/extract_metrics.py","size":3879,"sha256":"c5f1649a7cac7e36f884c02c582f222155b80a4d638d248412252ef057a5a8ce"},{"path":"scripts/latex_sanity.py","size":3956,"sha256":"36bfc1bf06fcff4ec7dbbea430a85678c8fc5d047cec5bd2c257efd6771df97a"},{"path":"scripts/orphan_cite_gate.py","size":1912,"sha256":"5fbab45fa24eb472a047ce13ab59efb465a6ed22a4d3495a5f68def5f611e415"}],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[],"scannedAt":"2026-08-22","hasScripts":true,"networkEndpoints":[]}}