Skip to content

V4 - Create Business Summary

This workflow generates comprehensive business summaries for youth entrepreneurs by analyzing their chat history, business data, and performance metrics. It uses AI to create detailed reports that help field managers quickly understand each youth's business progress, engagement levels, and areas needing attention.

Purpose

No business context provided yet — add a context.md to enrich this documentation.

This workflow appears to be part of a youth entrepreneurship support program that tracks and analyzes business performance. The system generates AI-powered business summaries that help program managers monitor youth entrepreneurs' progress, identify successful patterns, and spot potential issues requiring intervention.

How It Works

  1. Input Validation: The workflow receives a phone number and validates it exists and is not empty
  2. Data Retrieval: Fetches youth entrepreneur data from the database using the phone number
  3. Chat History Collection: Retrieves the last 30 chat messages between the youth and the AI support system
  4. Business Data Gathering: Pulls recent business performance data including sales, costs, and micro-actions
  5. Data Aggregation: Combines chat history and business data into structured formats
  6. AI Analysis: Uses an AI model to analyze all collected data and generate a comprehensive business summary
  7. Summary Storage: Updates the youth's record with the generated business summary

The workflow includes multiple validation checkpoints to ensure data quality and only proceeds when valid phone numbers and data are available.

Workflow Diagram

graph TD
    A[When Executed by Another Workflow] --> B[If - Validate Phone Number]
    B -->|Valid| C[get_chat_history - NoOp]
    B -->|Invalid| D[No Operation, do nothing]
    C --> E[get_youth_data - PostgreSQL Query]
    E --> F[If1 - Validate Youth Data]
    F -->|Valid| G[set_yout_data - Set Variables]
    F -->|Invalid| D
    G --> H[get_chat_history1 - PostgreSQL Query]
    H --> I[aggregate_chat_history - Aggregate Data]
    I --> J[get_business_data - PostgreSQL Query]
    J --> K[aggregate_business_data - Aggregate Data]
    K --> L[generate_Summary - LangChain LLM]
    M[OpenRouter Chat Model] --> L
    L --> N[If2 - Validate Summary]
    N -->|Valid| O[summary - Set Variables]
    N -->|Invalid| D
    O --> P[add_business_summary - PostgreSQL Update]

Trigger

Execute Workflow Trigger: This workflow is designed to be called by other workflows, accepting a phoneNumber parameter as input.

Nodes Used

Node Type Node Name Purpose
Execute Workflow Trigger When Executed by Another Workflow Receives phone number input from calling workflows
If If, If1, If2 Validates phone number, youth data, and generated summary
No Operation get_chat_history, No Operation do nothing Placeholder and termination nodes
PostgreSQL get_youth_data Retrieves youth entrepreneur profile data
Set set_yout_data, summary Structures and prepares data for processing
PostgreSQL get_chat_history1 Fetches recent chat messages with AI assistant
PostgreSQL get_business_data Retrieves daily business performance metrics
Aggregate aggregate_chat_history, aggregate_business_data Combines multiple records into structured arrays
LangChain LLM generate_Summary AI-powered analysis and summary generation
OpenRouter Chat Model OpenRouter Chat Model Provides the AI language model for analysis
PostgreSQL add_business_summary Updates youth record with generated summary

External Services & Credentials Required

  • PostgreSQL Database (sifaV4Dev): Stores youth data, chat histories, and business metrics
  • OpenRouter API (OpenRouter account): Provides access to AI language models for summary generation

Environment Variables

No explicit environment variables are defined in this workflow. Configuration is handled through n8n credentials.

Data Flow

Input: - phoneNumber (string): Unique identifier for the youth entrepreneur

Processing Data: - Youth profile data (name, ward, business type, existing summary) - Chat history (last 30 messages with timestamps) - Business data (sales, costs, micro-actions for last 30 records)

Output: - Updated youth record with AI-generated business summary stored in database - Comprehensive analysis including business performance, engagement levels, and recommendations

Error Handling

The workflow includes several error handling mechanisms:

  • Retry Logic: Database operations have 2 retry attempts with 3-second delays
  • Validation Gates: Multiple If nodes ensure data exists before processing
  • Graceful Termination: Invalid inputs route to "No Operation" nodes instead of failing
  • Error Workflow: References error workflow cuHEGQjAfvuGwIOD for handling failures
  • Continue on Error: Some nodes are configured to continue execution even if they fail

Known Limitations

Based on the workflow structure, potential limitations include:

  • Limited to 30 recent chat messages and business records
  • Requires valid phone number in the youth database
  • Dependent on external AI service availability
  • Summary quality depends on the completeness of input data
  • No handling for concurrent executions on the same phone number

This workflow is designed to be called by other workflows in the system, likely as part of a larger business monitoring and reporting pipeline. The error workflow cuHEGQjAfvuGwIOD handles any execution failures.

Setup Instructions

  1. Import Workflow: Import the JSON configuration into your n8n instance

  2. Configure Database Credentials:

    • Set up PostgreSQL credential named sifaV4Dev
    • Ensure access to tables: youthEntrepreneursReal, n8n_chat_histories, dailyProfitTracking
  3. Configure AI Service:

    • Set up OpenRouter API credential named OpenRouter account
    • Ensure sufficient API credits for language model usage
  4. Database Schema Requirements:

    • youthEntrepreneursReal: Must include phoneNumber, firstName, youthWard, businessOwned, business_summary columns
    • n8n_chat_histories: Must include session_id, message, created_time columns
    • dailyProfitTracking: Must include phoneNumber, dateOfBusiness, sales, stockingCost, transportCost, otherCost columns
  5. Error Handling Setup:

    • Configure error workflow cuHEGQjAfvuGwIOD or update the reference
    • Test retry mechanisms with temporary database connectivity issues
  6. Testing:

    • Execute with a valid phone number from your youth database
    • Verify the generated summary is stored correctly
    • Test with invalid inputs to ensure graceful handling