Table of Contents Generator Agent
Added a new TOC Generator agent that automatically creates a Table of Contents with working anchor links for the final investment memo. The TOC includes main sections (h2) and subsections (h3) that function in both HTML and PDF exports.
Changelog: 2025-11-26_06
Table of Contents Generator Agent
Summary
Added a new TOC Generator agent that automatically creates a Table of Contents with working anchor links for the final investment memo. The TOC includes main sections (h2) and subsections (h3) that function in both HTML and PDF exports.
Changes
New File: src/agents/toc_generator.py
slugify(): Converts header text to URL-friendly anchors matching pandoc's algorithmLowercase, replaces spaces with hyphens, removes special characters
Strips leading section numbers (e.g., "01. " prefix)
extract_headers(): Extracts h2 and h3 headers from markdown contentSkips headers in the Citations section
Returns list of (level, header_text, anchor_slug) tuples
generate_toc_markdown(): Generates markdown TOC with anchor linksh2 headers at root level, h3 headers indented
insert_toc_after_header(): Inserts TOC after logo/horizontal ruletoc_generator_agent(): Main agent function integrated into workflow
Modified: src/workflow.py
Added import for
toc_generator_agentAdded
tocnode to workflow graphInserted between
citeandvalidate_citationsin pipeline:cite → toc → validate_citationsUpdated workflow comment to reflect current agent sequence
Modified: src/utils.py
Fixed
get_latest_output_dir()to only match directories, not filesChanged:
matching_dirs = [p for p in output_base.glob(f"{safe_name}-v*") if p.is_dir()]Prevents false matches on files like
Company-v0.0.1-state.json
Modified: cli/resume_from_interruption.py
Added
toc_generator_agentto agent sequenceAdded checkpoint detection for TOC presence in final draft
Updated resume logic to recognize TOC stage
Modified: src/agents/citation_enrichment.py
Fixed duplicate section headers (was adding
## Sectionwhen content already had# Section)Fixed header hierarchy: demotes
##to###for proper h2 → h3 subsectionsAdded regex to strip leading
#header from section content
Modified: CLAUDE.md
Updated Multi-Agent Pipeline section with TOC Generator (agent 9)
Added
src/agents/toc_generator.pyto Core Agents section
Workflow Position
The TOC generator runs after citation enrichment and before citation validation:
... → Citations → TOC → Citation Validator → Fact Check → Validate → ...TOC Output Format
## Table of Contents
- [01. Executive Summary](#executive-summary)
- [02. Business Overview](#business-overview)
- [Product Architecture](#product-architecture)
- [Revenue Model](#revenue-model)
- [03. Market Context](#market-context)
...Technical Notes
Anchor slugs match pandoc's default algorithm for HTML/PDF compatibility
TOC is inserted after the logo/trademark and horizontal rule
Skips generation if TOC already exists (idempotent)
Skips Citations section headers to avoid clutter