Implementation:ALwrity ALwrity EnhancedContentGenerator generate section
| Knowledge Sources | |
|---|---|
| Domains | Blog_Writer, Content_Generation, LLM |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Concrete tool for generating a single blog section with research grounding, inter-section transitions, and continuity metrics, provided by the ALwrity blog writer subsystem.
Description
The EnhancedContentGenerator.generate_section method is stage 3 of the blog writer pipeline. For a given outline section, it builds a research context from the section's mapped references, picks relevant source URLs, constructs a prompt that includes the previous sections' summary (via ContextMemory) for continuity, and calls llm_text_gen to generate the section content. After generation, TransitionGenerator produces a transition from the previous section and FlowAnalyzer assesses the continuity (cohesion) between sections. The result includes the content text, the section's sources, the transition, and continuity metrics. A ContextMemory with a 12-entry rolling window persists across sections within a single article.
Usage
Import this service when:
- The blog writer pipeline has an outline and needs to generate each section.
- Sections must flow into one another with explicit transitions.
- Continuity metrics are needed to flag sections that break the narrative thread.
- Research sources must be attached per section for grounding.
Code Reference
Source Location
- Repository: ALwrity
- File: backend/services/blog_writer/content/enhanced_content_generator.py (L25-67)
Signature
class EnhancedContentGenerator:
def __init__(self):
self.url_manager = SourceURLManager()
self.memory = ContextMemory(max_entries=12)
self.transitioner = TransitionGenerator()
self.flow = FlowAnalyzer()
async def generate_section(
self,
section: Any,
research: Any = None,
mode: str = "polished",
user_id: str = None,
competitive_advantage: str = "",
) -> Dict[str, Any]:
"""
Generate a single blog section with research grounding and transitions.
Args:
section: Outline section with heading, subheadings, key_points, references.
research: BlogResearchResponse for global context.
mode: Generation mode (e.g. 'polished').
user_id: Clerk user ID for LLM provider routing.
competitive_advantage: Differentiator to emphasise.
Returns:
Dict with 'content', 'sources', 'transition', 'continuity_metrics'.
"""
Import
from services.blog_writer.content.enhanced_content_generator import EnhancedContentGenerator
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| section | Any | Yes | Outline section (heading, subheadings, key_points, references) |
| research | Any | No | BlogResearchResponse for global context |
| mode | str | No | Generation mode (default 'polished') |
| user_id | str | Yes | Clerk user ID for LLM routing |
| competitive_advantage | str | No | Differentiator to emphasise |
Outputs
| Name | Type | Description |
|---|---|---|
| return | Dict[str, Any] | content (str), sources (list), transition (str), continuity_metrics (dict) |
| side effect | ContextMemory | Section added to rolling memory for subsequent sections |
Usage Examples
Generating sections in sequence
from services.blog_writer.content.enhanced_content_generator import EnhancedContentGenerator
generator = EnhancedContentGenerator()
for section in outline.sections:
result = await generator.generate_section(
section=section,
research=research_response,
user_id="clerk_user_123",
competitive_advantage="Open-source, no vendor lock-in",
)
print(f"== {section.heading} == ({len(result['content'])} chars)")
print(f"Transition: {result['transition']}")
print(f"Continuity score: {result['continuity_metrics']}")