Skip to content

V4 - Create Business Summary

This workflow generates comprehensive business performance summaries for youth entrepreneurs by analyzing their chat history, business data, and profile information. It uses AI to create manager-friendly reports that help field staff quickly understand each youth's business progress, engagement levels, and key opportunities or risks.

Purpose

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

Based on the workflow structure, this appears to be part of a youth entrepreneurship program that: - Tracks daily business performance of young entrepreneurs - Provides AI-powered coaching through chat interactions - Generates regular business summaries for program managers - Helps field staff monitor multiple youth businesses efficiently

The workflow serves program managers and field staff who need quick, actionable insights about youth business performance without manually reviewing raw data.

How It Works

  1. Input Validation: Receives a phone number and validates it exists and is not empty
  2. Youth Data Retrieval: Looks up the youth entrepreneur's profile information from the database
  3. Chat History Collection: Gathers the last 30 chat messages between the youth and AI coaching system
  4. Business Data Gathering: Retrieves recent daily profit tracking data (sales, costs, micro-actions)
  5. Data Aggregation: Combines chat messages and business metrics into structured datasets
  6. AI Analysis: Uses an AI language model to analyze all data and generate a comprehensive business summary
  7. Summary Validation: Checks that the AI generated a valid summary
  8. Database Update: Saves the new business summary back to the youth's profile

The workflow creates a detailed report including business performance trends, engagement levels, key events timeline, and actionable recommendations for managers.

Workflow Diagram

graph TD
    A[When Executed by Another Workflow] --> B[If: Phone Number Valid?]
    B -->|Yes| C[get_chat_history]
    B -->|No| D[No Operation, do nothing]

    C --> E[get_youth_data]
    E --> F[If1: Youth Data Found?]
    F -->|Yes| G[set_yout_data]
    F -->|No| D

    G --> H[get_chat_history1]
    H --> I[aggregate_chat_history]
    I --> J[get_business_data]
    J --> K[aggregate_business_data]
    K --> L[generate_Summary]

    M[OpenRouter Chat Model] -.-> L

    L --> N[If2: Summary Generated?]
    N -->|Yes| O[summary]
    N -->|No| D

    O --> P[add_business_summary]

Trigger

Execute Workflow Trigger: This workflow is designed to be called by other workflows, receiving 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 workflow
If If, If1, If2 Validates input data and generated outputs
No Operation get_chat_history, No Operation do nothing Placeholder and termination nodes
Postgres get_youth_data, get_chat_history1, get_business_data, add_business_summary Database operations for retrieving and updating youth data
Set set_yout_data, summary Data transformation and variable assignment
Aggregate aggregate_chat_history, aggregate_business_data Combines multiple database records into structured datasets
Chain LLM generate_Summary AI-powered analysis and summary generation
OpenRouter Chat Model OpenRouter Chat Model Language model for generating business summaries

External Services & Credentials Required

Database Connection

  • PostgreSQL Database: Stores youth profiles, chat histories, and business tracking data
  • Required Tables:
    • youthEntrepreneursReal: Youth profile and summary storage
    • n8n_chat_histories: Chat conversation logs
    • dailyProfitTracking: Business performance metrics

AI Service

  • OpenRouter API: Provides access to language models for summary generation
  • Required Credentials: OpenRouter API key

Environment Variables

No specific environment variables are documented in the workflow configuration. Credentials are managed through n8n's credential system.

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, dates)
  • Current date for context

Output

  • Comprehensive business summary (300+ words) stored in database
  • Includes: performance analysis, engagement assessment, timeline of events, recommendations

Error Handling

The workflow includes several error handling mechanisms:

  • Input Validation: Multiple If nodes check for valid phone numbers and data existence
  • Database Retry Logic: PostgreSQL nodes configured with retry on failure (2 attempts, 3-second delays)
  • Graceful Termination: Invalid inputs route to "No Operation" nodes instead of failing
  • Error Workflow: References error workflow ID cuHEGQjAfvuGwIOD for handling unexpected failures

Known Limitations

  • Limited to last 30 chat messages and business records
  • Requires existing youth profile in database
  • AI summary generation depends on external OpenRouter service availability
  • No handling for multiple youth with same phone number
  • Summary quality depends on completeness of input data
  • Error handling workflow: cuHEGQjAfvuGwIOD
  • Likely called by scheduling or monitoring workflows (not specified in current data)

Setup Instructions

1. Import Workflow

  1. Copy the workflow JSON
  2. In n8n, go to Workflows → Import from JSON
  3. Paste the JSON and save

2. Configure Database Connection

  1. Set up PostgreSQL credential in n8n
  2. Ensure database contains required tables:
    • youthEntrepreneursReal
    • n8n_chat_histories
    • dailyProfitTracking

3. Configure OpenRouter API

  1. Create OpenRouter account and get API key
  2. Add OpenRouter credential in n8n
  3. Configure the "OpenRouter Chat Model" node with your preferred model

4. Test the Workflow

  1. Ensure you have test data in the database
  2. Execute workflow manually with a valid phone number
  3. Verify summary is generated and saved correctly

5. Integration

  1. Create calling workflows that pass phone numbers to this workflow
  2. Set up scheduling if regular summary generation is needed
  3. Configure the error workflow referenced in settings

The workflow is currently inactive and requires activation after proper configuration.