Back to .md Directory

NX-EDITOR8 AI AGENTS FLOW

Documents a three-agent LangChain pipeline that validates, analyzes, and generates video scenes from Kafka content sources.

May 2, 2026
0 downloads
0 views
ai agent llm prompt
View source

What this file does

Documents a three-agent LangChain pipeline that validates, analyzes, and generates video scenes from Kafka content sources.

When to use it

  • Designing a multi-agent AI pipeline for content transformation
  • Integrating LangChain with Kafka for asynchronous processing
  • Building a video generation system with scene-level AI orchestration
  • Implementing retry logic and fallback mechanisms in AI workflows

Assumes this stack

LangChainLiteLLMKafkaPython

NX-EDITOR8 AI AGENTS FLOW

Date: October 4, 2025
Status: ✅ LANGCHAIN ENABLED WITH AI AGENTS PIPELINE

🤖 AI AGENTS ARCHITECTURE

nx-editor8 uses LangChain and LiteLLM to implement a sophisticated multi-agent AI processing pipeline for content transformation.

🔄 AI AGENTS FLOW DIAGRAM

┌─────────────────────────────────────────────────────────────────────────┐
│                    KAFKA CONTENT SOURCES                                │
├─────────────────┬─────────────────┬─────────────────────────────────────┤
│ youtube_content │ tiktok_content  │ facebook_content                    │
└─────────────────┴─────────────────┴─────────────────────────────────────┘
                               │
                               ▼
┌─────────────────────────────────────────────────────────────────────────┐
│                     MESSAGE PROCESSOR                                   │
│                 (src/core/message_processor.py)                        │
└─────────────────────────────────────────────────────────────────────────┘
                               │
                               ▼
┌─────────────────────────────────────────────────────────────────────────┐
│                    🤖 AI AGENT 1: REQUIREMENTS VALIDATOR                │
│               (src/validation/requirements_validator.py)               │
├─────────────────────────────────────────────────────────────────────────┤
│ • Word/Character Count Validation                                       │
│ • Content Format Detection                                              │
│ • Language Validation                                                   │
│ • Quality Assessment                                                    │
│                                                                         │
│ 🔄 ENHANCEMENT LOOP (if requirements not met):                         │
│   └── LLM-Powered Content Enhancement                                   │
│       └── Retry Logic (max 3 attempts)                                 │
└─────────────────────────────────────────────────────────────────────────┘
                               │
                               ▼ (requirements met)
┌─────────────────────────────────────────────────────────────────────────┐
│                   🤖 AI AGENT 2: CONTENT ANALYZER                       │
│                    (_analyze_content method)                           │
├─────────────────────────────────────────────────────────────────────────┤
│ Prompt: src/ai/prompts/content_analysis.md                            │
│                                                                         │
│ AI Tasks:                                                              │
│ • Sentiment Analysis (positive/negative/neutral)                       │
│ • Topic Extraction                                                     │
│ • Key Points Identification                                            │
│ • Title Generation                                                     │
│ • Description Creation                                                 │
│ • SEO Keywords Generation                                              │
│ • Content Type Classification                                          │
│ • Quality Score Assessment                                             │
│                                                                         │
│ Output: ContentAnalysis model                                          │
└─────────────────────────────────────────────────────────────────────────┘
                               │
                               ▼
┌─────────────────────────────────────────────────────────────────────────┐
│                  🤖 AI AGENT 3: SCENE GENERATOR                         │
│                    (_generate_scenes method)                           │
├─────────────────────────────────────────────────────────────────────────┤
│ Prompt: src/ai/prompts/scene_generation.md                            │
│                                                                         │
│ AI Tasks:                                                              │
│ • Video Script Structure Creation                                      │
│ • Scene Type Assignment (title/text/image/outro)                      │
│ • TTS-Optimized Text Generation                                        │
│ • Visual Design (colors, duration)                                    │
│ • Scene Flow Optimization                                              │
│ • Engagement Optimization                                              │
│                                                                         │
│ Scene Types:                                                           │
│ ├─ title_scene: Opening with title/intro                             │
│ ├─ text_scene: Main content presentation                             │
│ ├─ image_scene: Visual content with text                             │
│ └─ outro_scene: Closing with CTA                                     │
│                                                                         │
│ Output: List[Scene] models                                             │
└─────────────────────────────────────────────────────────────────────────┘
                               │
                               ▼
┌─────────────────────────────────────────────────────────────────────────┐
│                     OUTPUT FORMATTER                                    │
│                 (_create_nx_maker8_input method)                      │
├─────────────────────────────────────────────────────────────────────────┤
│ • NXMaker8Input Model Creation                                         │
│ • Video Settings Configuration                                         │
│ • Storage and TTS Provider Setup                                      │
│ • Metadata Enrichment                                                 │
└─────────────────────────────────────────────────────────────────────────┘
                               │
                               ▼
┌─────────────────────────────────────────────────────────────────────────┐
│                      KAFKA PUBLISHER                                    │
│                (src/integrations/kafka_client.py)                     │
├─────────────────────────────────────────────────────────────────────────┤
│ • nx-maker8 Topic Publishing                                          │
│ • Video Request Formatting                                             │
│ • Success/Error Handling                                               │
└─────────────────────────────────────────────────────────────────────────┘
                               │
                               ▼
┌─────────────────────────────────────────────────────────────────────────┐
│                       NX-MAKER8 ECOSYSTEM                              │
│                    (Video Generation Pipeline)                         │
└─────────────────────────────────────────────────────────────────────────┘

🧠 AI AGENTS DETAILED CAPABILITIES

🤖 Agent 1: Requirements Validator

File: src/validation/requirements_validator.py
LangChain Integration: Content Enhancement via LLM

Core Functions:

  • verify_requirements() - Multi-criteria content validation
  • enhance_content_for_requirements() - LLM-powered content expansion
  • _validate_content_format() - Format compliance checking
  • _detect_language() - Language identification

AI Enhancement Logic:

# When content fails requirements:
enhanced_content = await self.llm_client.generate(
    prompt=enhancement_prompt,
    system_message="You are nx-editor8's content enhancement specialist..."
)

🤖 Agent 2: Content Analyzer

File: src/core/message_processor.py (_analyze_content method)
Prompt Template: src/ai/prompts/content_analysis.md

AI Capabilities:

  • Sentiment Analysis: positive/negative/neutral classification
  • Topic Extraction: Multi-topic identification and categorization
  • Key Points: Hierarchical content structure analysis
  • SEO Optimization: Title, description, and keyword generation
  • Quality Assessment: Content scoring for video suitability

JSON Output Structure:

{
  "sentiment": "positive|negative|neutral",
  "topics": ["topic1", "topic2"],
  "key_points": ["point1", "point2"],
  "suggested_title": "AI-generated engaging title",
  "suggested_description": "Compelling description",
  "suggested_keywords": ["kw1", "kw2"],
  "content_type": "educational|entertainment|news|tutorial",
  "quality_score": 0.85,
  "engagement_potential": "high|medium|low"
}

🤖 Agent 3: Scene Generator

File: src/core/message_processor.py (_generate_scenes method)
Prompt Template: src/ai/prompts/scene_generation.md

AI Capabilities:

  • Video Structure: Intelligent scene breakdown and flow
  • TTS Optimization: Text length and pronunciation optimization
  • Visual Design: Color schemes and timing coordination
  • Engagement Flow: Hook, content, and call-to-action structure

Scene Types Generated:

  1. title_scene: Opening hook with title and introduction
  2. text_scene: Main content delivery with optimized pacing
  3. image_scene: Visual content integration (when available)
  4. outro_scene: Conclusion with engagement prompts

🔧 LiteLLM CLIENT ARCHITECTURE

File: src/integrations/llm_client.py
Design Pattern: Singleton with async/await

Key Features:

  • EngineX Compatibility: Follows established xProjects patterns
  • Multi-Fallback Configuration: Environment variable hierarchy
  • Retry Logic: Exponential backoff with 3 attempts
  • JSON Parsing: Automatic structured response handling
  • Error Recovery: Graceful fallback mechanisms

Client Methods:

# Text generation
response = await llm_client.generate(prompt, system_message)

# Structured JSON generation  
data = await llm_client.generate_json(prompt, system_message)

📊 AI PROCESSING PIPELINE FLOW

Step-by-Step Execution:

  1. Message Ingestion: Kafka consumer receives content message
  2. Requirements Check: AI validates content against criteria
  3. Enhancement Loop: If needed, AI expands/improves content
  4. Content Analysis: AI extracts insights and metadata
  5. Scene Generation: AI creates structured video scenes
  6. Output Formatting: Data transformed to nx-maker8 format
  7. Publication: Structured video request published to Kafka

Retry and Error Handling:

  • Requirements Validation: Up to 3 enhancement attempts
  • LLM Requests: Exponential backoff retry logic
  • Fallback Mechanisms: Basic scene generation if AI fails
  • Error Publishing: Structured error reporting to Kafka topics

🎯 LangChain Integration Points

Current LangChain Usage:

  • Dependencies: langchain>=0.1.0,<0.2.0 and langchain-core>=0.1.7,<0.2.0
  • LangGraph: langgraph==0.0.26 for potential agent orchestration
  • Integration Patterns: Compatible with LangChain's agent framework

Potential LangChain Enhancements:

  • Agent Orchestration: LangGraph for complex multi-agent workflows
  • Memory Systems: Conversation memory for content context
  • Tool Integration: External tool calling for image search, data retrieval
  • Chain Composition: Sophisticated prompt chaining and conditional logic

🚀 Performance Characteristics

AI Processing Metrics:

  • Content Analysis: ~2-3 seconds per message
  • Scene Generation: ~3-5 seconds per message
  • Enhancement Cycles: ~2-4 seconds per retry
  • Total Processing: ~5-15 seconds end-to-end

Scalability Features:

  • Async Processing: Non-blocking I/O throughout pipeline
  • Singleton Clients: Resource-efficient client management
  • Configurable Limits: Adjustable retry counts and timeouts
  • Error Isolation: Failed messages don't block pipeline

nx-editor8 implements a sophisticated AI agents pipeline using LangChain and LiteLLM for intelligent content transformation and video scene generation! 🤖✨

What's inside

Architecture diagram, 3 agent descriptions, pipeline flow, retry logic, performance metrics, and code snippets.

Change this for your project

  • Replace nx-editor8 with your project name
  • Replace src/validation/requirements_validator.py with your own validation module path
  • Replace src/ai/prompts/content_analysis.md with your prompt template path
  • Replace nx-maker8 topic name with your output Kafka topic

Where it goes

Keep it in your repository where the agent or team that needs it will read it.

Worth borrowing

  • Three-agent pipeline with separate validation, analysis, and generation stages
  • Enhancement loop with max retry attempts before falling back to basic generation
  • Structured JSON output from each agent for downstream consumption

Related Documents