Create Business Summary for Youth¶
This workflow generates comprehensive business performance summaries for youth entrepreneurs by analyzing their chat history, business data, and engagement patterns. 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¶
-
Input Validation: The workflow starts when triggered by another workflow with a phone number parameter and validates that the phone number exists and is not empty.
-
Youth Data Retrieval: Queries the youth entrepreneurs database to fetch the participant's profile information including name, ward, business type, and any existing business summary.
-
Chat History Collection: Retrieves the last 30 chat messages between the youth and the AI business support assistant, ordered by most recent first.
-
Business Data Gathering: Pulls the youth's daily business tracking data including sales, costs, and micro-actions from the profit tracking database.
-
Data Aggregation: Combines the chat history and business data into structured formats for AI analysis.
-
AI Analysis: Uses an OpenRouter language model to analyze all the collected data and generate a comprehensive business summary report including:
- Detailed narrative summary (~300 words)
- Manager quick brief (5-6 bullet points)
- Timeline of key events
- Business health assessment with recommendations
-
Summary Storage: Validates the AI-generated summary and updates the youth's record in the database with the new business summary.
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 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 and expects a single input parameter:
- phoneNumber (string): The phone number of the youth entrepreneur to analyze
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 inputs and controls flow based on data availability |
| 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 youth data |
| Set | set_yout_data, summary | Data transformation and preparation |
| Aggregate | aggregate_chat_history, aggregate_business_data | Combines multiple records into structured datasets |
| LangChain LLM Chain | generate_Summary | AI-powered analysis and summary generation |
| OpenRouter Chat Model | OpenRouter Chat Model | Language model provider for AI analysis |
External Services & Credentials Required¶
PostgreSQL Database¶
- Credential:
PostgresOnSupabase - Purpose: Access to youth entrepreneur data, chat histories, and business tracking data
- Tables Used:
youthEntrepreneursReal: Youth profiles and business summariesn8n_chat_histories: Chat conversations with AI assistantdailyProfitTracking: Daily business performance data
OpenRouter API¶
- Credential:
OpenRouter account - Purpose: AI language model access for generating business summaries
- Usage: Analyzes combined data to create structured business reports
Environment Variables¶
No specific environment variables are required beyond the database connection and API credentials configured in the credential store.
Data Flow¶
Input¶
phoneNumber: Phone number of the youth entrepreneur to analyze
Processing Data¶
- Youth profile data (name, ward, business type, existing summary)
- Chat message history (last 30 messages with timestamps)
- Business tracking data (sales, costs, micro-actions)
- Current date for temporal context
Output¶
- Updated youth record with new AI-generated business summary
- Summary includes detailed analysis, quick brief, timeline, and health assessment
Error Handling¶
The workflow includes several validation checkpoints:
- Phone Number Validation: Checks if phone number exists and is not empty before proceeding
- Youth Data Validation: Verifies youth record exists before continuing analysis
- Summary Validation: Ensures AI generates valid summary content before database update
- Database Error Handling: Youth data retrieval is configured to continue on error with
alwaysOutputDataenabled
Failed validations route to "No Operation" nodes that safely terminate the workflow without errors.
Known Limitations¶
- Limited to analyzing the last 30 chat messages and business records
- Requires existing youth record in database to proceed
- AI summary quality depends on data availability and completeness
- No retry mechanism for failed AI generation attempts
Related Workflows¶
This workflow is designed to be called by other workflows in the youth entrepreneur monitoring system. It does not directly call other workflows but serves as a data processing component.
Setup Instructions¶
-
Import Workflow: Import the JSON workflow definition into your n8n instance
-
Configure Database Credentials:
- Create PostgreSQL credential named "PostgresOnSupabase"
- Configure connection to database containing youth entrepreneur tables
- Ensure access to tables:
youthEntrepreneursReal,n8n_chat_histories,dailyProfitTracking
-
Configure OpenRouter API:
- Create OpenRouter API credential named "OpenRouter account"
- Add your OpenRouter API key for language model access
-
Test Workflow:
- Use the pinned test data with phone number "+254794443378"
- Verify database connections and AI model responses
- Check that business summary is properly generated and stored
-
Integration:
- Call this workflow from other workflows using the Execute Workflow node
- Pass the
phoneNumberparameter for the youth to analyze - Handle the workflow completion in your calling workflow
The workflow is ready to use once credentials are configured and database tables are accessible.