Major Architecture Refactor: Section-by-Section Processing
Complete refactor of the enrichment pipeline to process memo sections individually rather than as a single monolithic document. This eliminates API timeout issues and enables proper citation management with Perplexity Sonar Pro.
Changelog - 2025-11-20
Major Architecture Refactor: Section-by-Section Processing
Overview
Complete refactor of the enrichment pipeline to process memo sections individually rather than as a single monolithic document. This eliminates API timeout issues and enables proper citation management with Perplexity Sonar Pro.
Breaking Changes
Writer Agent (src/agents/writer.py)
CHANGED: No longer assembles full memo during writing phase
CHANGED: Returns empty
draft_sectionsdict instead offull_memoNow saves only individual section files to
2-sections/directorySection assembly moved to citation enrichment agent
Enrichment Agents
All enrichment agents now process section files directly instead of operating on state:
Citation Enrichment (src/agents/citation_enrichment.py)
CHANGED: Now loads sections from
2-sections/files instead of stateCHANGED: Citation format now uses markdown links:
[^1]: YYYY, MMM DD. [Title](URL). Published: YYYY-MM-DD | Updated: N/ACHANGED: Removed deprecated
URL: https://...suffixFIXED:
renumber_citations_globally()now consolidates ALL citations into ONE block at the endFIXED: Citations properly stripped from individual sections before consolidation
FIXED: Multiple citations separated by single space:
text. [^1] [^2]
Socials Enrichment (src/agents/socials_enrichment.py)
CHANGED: Processes Team section file (
04-team.md) directlyCHANGED: Uses
get_latest_output_dir()helper instead of version managerAdds LinkedIn links to team members in-place in section file
Link Enrichment (src/agents/link_enrichment.py)
CHANGED: Processes each section file independently
CHANGED: No longer attempts to process full 50k+ char memo (avoiding timeouts)
Each section enriched with organization/entity hyperlinks separately
Trademark Enrichment (src/agents/trademark_enrichment.py)
NEW: Creates
header.mdfile with company logo/trademarkCHANGED: No longer tries to insert into assembled memo
Header file used by finalizer during assembly
Visualization Enrichment (src/agents/visualization_enrichment.py)
DISABLED: Temporarily disabled pending refactor for section-by-section processing
Returns skip message until re-implemented
Finalizer (src/workflow.py)
CHANGED: No longer assembles sections (done by citation enrichment)
CHANGED: Now verifies
4-final-draft.mdexists instead of creating itCHANGED: Uses
get_latest_output_dir()helper
New Features
Version Resolution (src/utils.py)
NEW: Added
get_latest_output_dir()helper functionDynamically finds most recent output directory by scanning filesystem
Eliminates version sync issues between agents
All enrichment agents now use consistent version resolution
Version Manager (src/versioning.py)
NEW: Added
get_current_version()methodReturns latest version from
versions.jsonUsed alongside
get_next_version()for different use cases
Bug Fixes
Citation Format
FIXED: Citations now consistently use markdown link format
FIXED: Multiple citations properly spaced:
[^1] [^2]not[^1][^2]FIXED: Citation placement after punctuation with space:
text. [^1]FIXED: Consolidated citation block (ONE block at end, not duplicates)
Version Management
FIXED: Enrichment agents no longer fail due to version mismatches
FIXED: Dynamic directory resolution prevents "v0.0.2 vs v0.0.3" errors
FIXED: All agents now find same output directory consistently
API Timeout Prevention
FIXED: No more 50k+ character API payloads
FIXED: Each section processed independently (~5k chars each)
FIXED: Link enrichment no longer times out on large memos
Technical Details
Section-by-Section Flow
Writer: Saves 10 individual section files to
2-sections/Trademark: Creates
header.mdwith company logo (if provided)Socials: Enriches Team section with LinkedIn links
Link: Enriches each section with organization hyperlinks
Visualization: Skipped (pending refactor)
Citation:
Loads each section file
Enriches with Perplexity Sonar Pro citations
Saves enriched section back
Renumbers citations globally
Consolidates into ONE citation block
Saves assembled
4-final-draft.md
Validator: Validates final draft
Finalizer: Verifies draft exists, saves state
Citation Renumbering Algorithm
# Each section has local citations [^1][^2][^3]
# Section 1: [^1][^2] -> renumbered to [^1][^2]
# Section 2: [^1][^2][^3] -> renumbered to [^3][^4][^5]
# Section 3: [^1] -> renumbered to [^6]
# Result: Global sequence [^1][^2][^3][^4][^5][^6]
# All citation definitions consolidated into ONE block at endFiles Changed
Core Agents
src/agents/writer.py- Section-only saving, no assemblysrc/agents/citation_enrichment.py- Section-by-section + consolidationsrc/agents/socials_enrichment.py- File-based processingsrc/agents/link_enrichment.py- File-based processingsrc/agents/trademark_enrichment.py- Header file creationsrc/agents/visualization_enrichment.py- Temporary disable
Utilities
src/utils.py- NEW: Helper functionssrc/versioning.py- Addedget_current_version()
Workflow
src/workflow.py- Finalizer refactor
Configuration
CLAUDE.md- Updated troubleshooting notesREADME.md- Updated architecture documentation
Migration Notes
For Future Development
All enrichment agents MUST process section files, not state
Use
get_latest_output_dir()for consistent version resolutionCitation blocks MUST be stripped before assembly
Section headers added during assembly, not in section content
Deprecated Patterns
❌
draft_sections["full_memo"]["content"]- NO LONGER POPULATED❌
version_mgr.get_current_version()alone - Useget_latest_output_dir()instead❌ Processing full memo in enrichment - Process sections individually
Performance Improvements
Before
Single 50k+ char API call for citations → frequent timeouts
Full memo reassembled after each enrichment → memory intensive
Version sync issues → manual intervention required
After
10 separate ~5k char API calls → no timeouts
Sections enriched in-place → minimal memory overhead
Dynamic version resolution → zero manual intervention
Known Issues
Visualization Enrichment
Currently disabled, pending refactor for section-by-section processing
Will be re-enabled in future release
Section Headers
Duplicate headers may appear if section content includes its own header
Assembly process adds numbered headers (e.g.,
## 1. Executive Summary)Section files should contain content only, no headers
Testing
Tested on:
Avalanche VC Fund II memo (fund commitment, retrospective)
All 10 sections processed successfully
Citations properly formatted with markdown links
Single consolidated citation block at end
No API timeouts during link or citation enrichment
Contributors
Architecture refactor and bug fixes
Citation format standardization
Version resolution system
References
Issue: Citations losing format after pipeline execution
Issue: API timeouts on large memos (50k+ chars)
Issue: Version mismatch between enrichment agents
Issue: Duplicate citation blocks in final output