Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:ALwrity ALwrity OutlineService generate outline

From Leeroopedia
Knowledge Sources
Domains Blog_Writer, Content_Planning, SEO
Last Updated 2026-10-24 00:00 GMT

Overview

Concrete tool for generating SEO-optimised blog outlines from research data with persistent caching, provided by the ALwrity blog writer subsystem.

Description

The OutlineService.generate_outline method is stage 2 of the blog writer pipeline. It accepts a BlogOutlineRequest (research data, persona, word count, custom instructions) and delegates to OutlineGenerator.generate to produce a BlogOutlineResponse with title options and structured outline sections (heading, subheadings, key points, references, target words). Results are cached by persistent_outline_cache keyed on keywords, industry, target audience, word count, and custom instructions so repeated requests for the same parameters return cached outlines without a new LLM call.

Usage

Import this service when:

  • The blog writer pipeline has research results and needs a structured outline.
  • A returning user with the same research parameters should hit the outline cache.
  • Word-count targets per section are needed for content generation budgeting.

Code Reference

Source Location

  • Repository: ALwrity
  • File: backend/services/blog_writer/outline/outline_service.py (L32-84)

Signature

class OutlineService:
    def __init__(self):
        self.outline_generator = OutlineGenerator()
        self.outline_optimizer = OutlineOptimizer()
        self.section_enhancer = SectionEnhancer()

    async def generate_outline(
        self,
        request: BlogOutlineRequest,
        user_id: str,
    ) -> BlogOutlineResponse:
        """
        Stage 2: Content Planning with AI-generated outline using research results.

        Args:
            request: BlogOutlineRequest with research data, persona, word_count,
                     custom_instructions.
            user_id: User ID (required for subscription checks and usage tracking).

        Returns:
            BlogOutlineResponse with title_options and structured outline sections.

        Raises:
            ValueError: If user_id is not provided.
        """

Import

from services.blog_writer.outline.outline_service import OutlineService

I/O Contract

Inputs

Name Type Required Description
request BlogOutlineRequest Yes research, persona, word_count, custom_instructions
user_id str Yes Clerk user ID for subscription checks

Outputs

Name Type Description
return BlogOutlineResponse title_options, outline sections (heading, subheadings, key_points, references, target_words)
side effect cache Outline cached by keywords/industry/audience/word_count key

Usage Examples

Generating an outline from research

from services.blog_writer.outline.outline_service import OutlineService
from models.blog_models import BlogOutlineRequest

service = OutlineService()
request = BlogOutlineRequest(
    research=research_response,       # BlogResearchResponse from stage 1
    persona=user_persona,             # writing persona from onboarding
    word_count=2000,
    custom_instructions="Focus on QLoRA and PEFT",
)

outline = await service.generate_outline(request, user_id="clerk_user_123")
print(outline.title_options)
for section in outline.sections:
    print(f"{section.heading} ({section.target_words} words)")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment