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¶
- Input Validation: Receives a phone number and validates it exists and is not empty
- Youth Data Retrieval: Looks up the youth entrepreneur's profile information from the database
- Chat History Collection: Gathers the last 30 chat messages between the youth and AI coaching system
- Business Data Gathering: Retrieves recent daily profit tracking data (sales, costs, micro-actions)
- Data Aggregation: Combines chat messages and business metrics into structured datasets
- AI Analysis: Uses an AI language model to analyze all data and generate a comprehensive business summary
- Summary Validation: Checks that the AI generated a valid summary
- 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 storagen8n_chat_histories: Chat conversation logsdailyProfitTracking: 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
cuHEGQjAfvuGwIODfor 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
Related Workflows¶
- Error handling workflow:
cuHEGQjAfvuGwIOD - Likely called by scheduling or monitoring workflows (not specified in current data)
Setup Instructions¶
1. Import Workflow¶
- Copy the workflow JSON
- In n8n, go to Workflows → Import from JSON
- Paste the JSON and save
2. Configure Database Connection¶
- Set up PostgreSQL credential in n8n
- Ensure database contains required tables:
youthEntrepreneursRealn8n_chat_historiesdailyProfitTracking
3. Configure OpenRouter API¶
- Create OpenRouter account and get API key
- Add OpenRouter credential in n8n
- Configure the "OpenRouter Chat Model" node with your preferred model
4. Test the Workflow¶
- Ensure you have test data in the database
- Execute workflow manually with a valid phone number
- Verify summary is generated and saved correctly
5. Integration¶
- Create calling workflows that pass phone numbers to this workflow
- Set up scheduling if regular summary generation is needed
- Configure the error workflow referenced in settings
The workflow is currently inactive and requires activation after proper configuration.