Youth Business Summary Generator¶
This workflow automatically generates comprehensive business performance summaries for youth entrepreneurs by analyzing their chat history with AI assistants, business data, and profile information. The generated summaries 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.
Based on the workflow structure, this appears to support a youth entrepreneurship program where: - Young entrepreneurs receive AI-powered business coaching through chat interactions - Their daily business activities (sales, costs, profits) are tracked in a database - Program managers need regular summaries to monitor progress and identify intervention opportunities - The workflow creates detailed reports that combine behavioral insights with financial performance data
How It Works¶
- Input Validation: The workflow receives a phone number and validates it exists and is not empty
- Data Retrieval: Fetches the youth's profile data from the database using their phone number
- Chat History Collection: Retrieves the last 30 chat messages between the youth and the AI assistant
- Business Data Gathering: Pulls recent business performance data (sales, costs, profits) for the youth
- Data Aggregation: Combines chat messages and business metrics into structured datasets
- AI Analysis: Uses an AI model to analyze all data and generate a comprehensive business summary
- Summary Storage: Saves the generated summary back to the youth's profile in the database
The workflow includes multiple validation checkpoints to ensure data quality and only processes valid phone numbers with existing youth records.
Workflow Diagram¶
graph TD
A[When Executed by Another Workflow] --> B[If: Validate Phone Number]
B -->|Valid| C[get_chat_history]
B -->|Invalid| D[No Operation, do nothing]
C --> E[get_youth_data]
E --> F[If1: Validate Youth Data]
F -->|Valid| G[set_yout_data]
F -->|Invalid| 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] -.->|AI Model| L
L --> N[If2: Validate Summary]
N -->|Valid| O[summary]
N -->|Invalid| D
O --> P[add_business_summary]
Trigger¶
Execute Workflow Trigger: This workflow is designed to be called by other workflows, requiring a phoneNumber input parameter. It does not run automatically but must be invoked programmatically.
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 generated summary |
| 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 storing 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 | generate_Summary | AI-powered analysis and summary generation |
| OpenRouter Chat Model | OpenRouter Chat Model | Provides the AI language model for analysis |
External Services & Credentials Required¶
Database Connection¶
- PostgreSQL Database: Stores youth profiles, chat histories, and business data
- Credential:
kdpTestEnv(PostgreSQL connection)
AI Service¶
- OpenRouter API: Provides access to language models for summary generation
- Credential:
OpenRouter KDP(OpenRouter API key)
Environment Variables¶
No explicit environment variables are referenced in this workflow. All configuration is handled through n8n credentials.
Data Flow¶
Input¶
phoneNumber(string): The phone number identifying the youth entrepreneur
Processing Data¶
- Youth profile data from
youthEntrepreneursRealtable - Chat messages from
n8n_chat_historiestable (last 30 messages) - Business performance data from
dailyProfitTrackingtable (last 30 records)
Output¶
- Comprehensive business summary stored in the
business_summaryfield of the youth's profile - Summary includes business performance analysis, engagement assessment, and manager recommendations
Error Handling¶
The workflow implements several error handling mechanisms:
- Input Validation: Multiple If nodes check for valid phone numbers and existing data
- Graceful Degradation: Invalid inputs route to "No Operation" nodes instead of failing
- Database Error Handling: The
get_youth_datanode hasalwaysOutputDataandcontinueRegularOutputenabled - Summary Validation: Checks that the AI-generated summary exists and is not empty before saving
Known Limitations¶
- Limited to processing one youth at a time (single phone number input)
- Chat history limited to last 30 messages
- Business data limited to last 30 records
- Requires existing youth profile in database
- Dependent on external AI service availability
- No retry mechanism for failed AI generation
Related Workflows¶
This workflow is designed to be called by other workflows but no specific related workflows are identified in the current configuration.
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 Credentials¶
- Create a PostgreSQL credential named
kdpTestEnv - Configure connection details for your database
- Ensure the following tables exist:
youthEntrepreneursRealn8n_chat_historiesdailyProfitTracking
3. Configure AI Service¶
- Create an OpenRouter API credential named
OpenRouter KDP - Add your OpenRouter API key
- Ensure you have access to the required language model
4. Database Schema Requirements¶
Ensure your database tables have the required columns:
- youthEntrepreneursReal: phoneNumber, firstName, youthWard, businessOwned, business_summary
- n8n_chat_histories: session_id, message, created_time
- dailyProfitTracking: phoneNumber, dateOfBusiness, sales, stockingCost, transportCost, otherCost
5. Test the Workflow¶
- Activate the workflow
- Call it from another workflow with a valid phone number
- Verify the summary is generated and stored correctly
6. Integration¶
To use this workflow, call it from other workflows using the "Execute Workflow" node and pass the required phoneNumber parameter.