$npx -y skills add Ar9av/PaperOrchestra --skill section-writing-agentStep 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
| 1 | # Section Writing Agent (Step 4) |
| 2 | |
| 3 | Faithful implementation of the Section Writing Agent from PaperOrchestra |
| 4 | (Song et al., 2026, arXiv:2604.05018, §4 Step 4, App. F.1 pp. 47–49). |
| 5 | |
| 6 | **Cost: ONE LLM call** (App. B: "Section Writing Agent (1 call): A single, |
| 7 | comprehensive multimodal call to draft and compile the complete LaTeX |
| 8 | manuscript"). Do NOT split this into per-section calls — the paper |
| 9 | explicitly designs it as one comprehensive call so the model can maintain |
| 10 | global coherence across sections. |
| 11 | |
| 12 | ## Inputs |
| 13 | |
| 14 | - `workspace/outline.json` — the master plan |
| 15 | - `workspace/inputs/idea.md` — technical details |
| 16 | - `workspace/inputs/experimental_log.md` — raw data for tables and qualitative analysis |
| 17 | - `workspace/drafts/intro_relwork.tex` — the template **with Intro + Related |
| 18 | Work already filled in by Step 3**. This is your starting point. The |
| 19 | preamble, package list, style, and the two pre-filled sections must be |
| 20 | preserved verbatim. |
| 21 | - `workspace/citation_pool.json` — the citation map (`{key, title, abstract}` |
| 22 | for each verified paper) |
| 23 | - `workspace/refs.bib` — the BibTeX file |
| 24 | - `workspace/inputs/conference_guidelines.md` — formatting rules |
| 25 | - `workspace/figures/` — the actual PNG files from Step 2 (used as |
| 26 | multimodal vision input!) |
| 27 | - `workspace/figures/captions.json` — caption text per figure_id |
| 28 | - `workspace/tex_profile.json` — TeX package availability flags (written by |
| 29 | `check_tex_packages.py` at Step 0). **Read this before generating any |
| 30 | LaTeX.** It tells you which packages are installed so you select the right |
| 31 | cross-reference pattern, font packages, etc. before you write — not after |
| 32 | you try to compile. |
| 33 | |
| 34 | ## Output |
| 35 | |
| 36 | - `workspace/drafts/paper.tex` — the complete LaTeX paper, with all sections |
| 37 | filled. The Step 5 Refinement Agent will iterate on this file. |
| 38 | |
| 39 | ## How to do it |
| 40 | |
| 41 | ### 0.5. Read tex_profile.json and select LaTeX patterns |
| 42 | |
| 43 | Before composing the prompt, read `workspace/tex_profile.json` and apply |
| 44 | these rules to every LaTeX choice in the generated paper: |
| 45 | |
| 46 | | Profile flag | True → use | False → use instead | |
| 47 | |---|---|---| |
| 48 | | `use_cleveref` | `\cref{fig:X}`, `\cref{tab:Y}` | `Figure~\ref{fig:X}`, `Table~\ref{tab:Y}` | |
| 49 | | `use_nicefrac` | `\nicefrac{a}{b}` | `$a/b$` | |
| 50 | | `use_microtype` | `\usepackage{microtype}` | omit the line | |
| 51 | | `use_t1_fontenc` | `\usepackage[T1]{fontenc}` | omit the line | |
| 52 | |
| 53 | If `tex_profile.json` does not exist (old workspace), default to the safe |
| 54 | fallback column (no cleveref, no nicefrac, no microtype, no T1 fontenc). |
| 55 | |
| 56 | ### 1. Pre-extract metrics from the experimental log |
| 57 | |
| 58 | Run the deterministic helper: |
| 59 | |
| 60 | ```bash |
| 61 | python skills/section-writing-agent/scripts/extract_metrics.py \ |
| 62 | --log workspace/inputs/experimental_log.md \ |
| 63 | --out workspace/metrics.json |
| 64 | ``` |
| 65 | |
| 66 | This parses the `## 2. Raw Numeric Data` section's markdown tables into |
| 67 | structured JSON. The Section Writing Agent uses this to construct LaTeX |
| 68 | booktabs tables without re-deriving values from raw text. Read |
| 69 | `references/latex-table-patterns.md` for the booktabs conventions. |
| 70 | |
| 71 | ### 2. Compose the prompt and make ONE multimodal call |
| 72 | |
| 73 | Load `references/prompt.md` (verbatim Section Writing Agent prompt from App. |
| 74 | F.1). Prepend the Anti-Leakage Prompt from |
| 75 | `../paper-orchestra/references/anti-leakage-prompt.md`. |
| 76 | |
| 77 | The user message contains: |
| 78 | |
| 79 | - `outline.json` — full content |
| 80 | - `idea.md` — full content |
| 81 | - `experimental_log.md` — full content (tables AND prose) |
| 82 | - `intro_relwork.tex` — full content (this becomes `template.tex` for the prompt) |
| 83 | - `citation_pool.json` — full content (becomes `citation_map.json`) |
| 84 | - `conference_guidelines.md` — full content |
| 85 | - `figures_list` — array of `{figure_id, filename, caption}` from |
| 86 | `captions.json` and the file listing |
| 87 | - **The actual figure PNGs** as multimodal image inputs, so the model can |
| 88 | visually inspect them and write accurate descriptions / refer to them |
| 89 | correctly in the prose. |
| 90 | |
| 91 | If your host LLM has no vision input, fall back to text-only mode: pass the |
| 92 | captions in `captions.json` as descriptions and tell the agent it cannot see |
| 93 | the images directly. Quality drops noticeably (the paper notes that visual |
| 94 | grounding measurably improves figure-text alignment), but the pipeline |
| 95 | still completes. |
| 96 | |
| 97 | ### 3. Save the output |
| 98 | |
| 99 | The agent's response is wrapped in `\`\`\`latex ... \`\`\`` fences. Extract |
| 100 | the LaTeX code and save to `workspace/drafts/paper.tex`. |
| 101 | |
| 102 | ### 4. Run the deterministic gates |
| 103 | |
| 104 | ```bash |
| 105 | # Orphan citation gate: ever |