Skip to content

Create Business Summary Workflow

This workflow generates comprehensive business performance summaries for youth entrepreneurs by analyzing their chat history with AI assistants, business data, and personal information. It uses AI to create manager-friendly reports that help field managers quickly understand each youth's business progress, challenges, and opportunities.

Purpose

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

How It Works

  1. Input Validation: The workflow receives a phone number and validates it exists and is not empty
  2. Data Collection: Retrieves youth entrepreneur data from the database using the phone number
  3. Chat History Retrieval: Fetches the last 30 chat messages between the youth and AI support system
  4. Business Data Collection: Pulls recent business performance data including sales, costs, and micro-actions
  5. Data Aggregation: Combines chat history and business data into structured formats for analysis
  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 in the database with the generated business summary

The workflow includes multiple validation checkpoints to ensure data quality and handles cases where phone numbers are missing or invalid.

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 - AI Chain]
    M[OpenRouter Chat Model] --> L
    L --> N[If2 - Validate AI Response]
    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 and requires a phoneNumber input parameter.

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 phone number, youth data, and AI response
No Operation get_chat_history, No Operation do nothing Placeholder and termination nodes
PostgreSQL get_youth_data, get_chat_history1, get_business_data, add_business_summary Database operations for retrieving and updating data
Set set_yout_data, summary Data transformation and variable assignment
Aggregate aggregate_chat_history, aggregate_business_data Combines multiple data records into structured formats
LangChain LLM Chain generate_Summary AI-powered business analysis and summary generation
OpenRouter Chat Model OpenRouter Chat Model AI language model for generating summaries

External Services & Credentials Required

  • PostgreSQL Database: Stores youth entrepreneur data, chat histories, and business tracking information
    • Credential: "Postgres account" (ID: EJPqF6MDH1ZwAzyv)
  • OpenRouter API: Provides AI language model capabilities for summary generation
    • Credential: "sifa_create_business_summary" (ID: L6TxhiL6Rb3e91fb)

Environment Variables

No specific environment variables are configured in this workflow. All external service connections are managed through n8n credentials.

Data Flow

Input: - phoneNumber (string): Phone number of the youth entrepreneur

Processing: - Retrieves youth profile data from youthEntrepreneursReal table - Fetches last 30 chat messages from n8n_chat_histories table - Collects business performance data from dailyProfitTracking table - Aggregates and formats data for AI analysis

Output: - Updates the business_summary field in the youthEntrepreneursReal table with AI-generated analysis - Returns the generated summary text

Error Handling

The workflow includes several error handling mechanisms:

  • Retry Logic: Database operations have retry configurations (2 attempts with 3-second delays)
  • Validation Gates: Multiple If nodes validate data at each stage before proceeding
  • Graceful Termination: Invalid inputs or failed operations route to "No Operation" nodes
  • Continue on Error: The get_youth_data node is configured to continue even if errors occur

Known Limitations

No specific limitations documented in the provided context.

No related workflows mentioned in the provided context.

Setup Instructions

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

  2. Configure Database Credentials:

    • Create a PostgreSQL credential named "Postgres account"
    • Configure connection to database containing:
      • youthEntrepreneursReal table
      • n8n_chat_histories table
      • dailyProfitTracking table
  3. Configure AI Service:

    • Create an OpenRouter API credential named "sifa_create_business_summary"
    • Ensure the credential has access to chat completion models
  4. Database Schema Requirements:

    • Ensure all referenced database tables exist with the required columns
    • The workflow expects specific column names like phoneNumber, firstName, business_summary, etc.
  5. Test the Workflow:

    • Execute with a valid phone number that exists in your database
    • Verify the business summary is generated and stored correctly
  6. Integration:

    • Call this workflow from other workflows using the Execute Workflow node
    • Pass the required phoneNumber parameter