{"id":33329351,"url":"https://github.com/adityasinghz/smart-cpg-decision-agent","last_synced_at":"2026-04-30T12:32:06.190Z","repository":{"id":323826095,"uuid":"1094856327","full_name":"adityasinghz/smart-cpg-decision-agent","owner":"adityasinghz","description":"The Smart CPG Decision Support Agent is an intelligent analytics system that helps Consumer Packaged Goods (CPG) companies make data-driven decisions using Generative AI and Agentic AI.","archived":false,"fork":false,"pushed_at":"2025-11-28T05:26:24.000Z","size":476,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-30T06:48:33.935Z","etag":null,"topics":["databricks","huggingface","langchain","pyspark","python","streamlit"],"latest_commit_sha":null,"homepage":"https://smart-cpg-decision-agent-erpbalovxpuyczrpnpnhuz.streamlit.app/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adityasinghz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-12T09:08:28.000Z","updated_at":"2025-11-28T05:26:28.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/adityasinghz/smart-cpg-decision-agent","commit_stats":null,"previous_names":["adityasinghz/smart-cpg-decision-agent"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/adityasinghz/smart-cpg-decision-agent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adityasinghz%2Fsmart-cpg-decision-agent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adityasinghz%2Fsmart-cpg-decision-agent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adityasinghz%2Fsmart-cpg-decision-agent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adityasinghz%2Fsmart-cpg-decision-agent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adityasinghz","download_url":"https://codeload.github.com/adityasinghz/smart-cpg-decision-agent/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adityasinghz%2Fsmart-cpg-decision-agent/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32465009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"online","status_checked_at":"2026-04-30T02:00:05.929Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["databricks","huggingface","langchain","pyspark","python","streamlit"],"created_at":"2025-11-20T16:02:03.688Z","updated_at":"2026-04-30T12:32:06.183Z","avatar_url":"https://github.com/adityasinghz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Smart CPG Decision Agent - Simple Explanation (For 17-Year-Olds)\n\n## What is this project?\nAn app that helps businesses understand their sales data. Instead of complex spreadsheets, you ask questions in plain English and get answers.\n\n---\n\n## Main Files and How They Work\n\n### 1. Starting the App\n**File:** `src/ui/streamlit_app.py`\n- **Function:** `main()` - This starts everything\n- **Function:** `init_session_state()` - Sets up memory\n- **Function:** `render_sidebar()` - Shows navigation buttons\n\nWhen you run `streamlit run src/ui/streamlit_app.py`, it calls `main()` and opens the web interface.\n\n---\n\n### 2. Loading Your Data\n**File:** `src/data_loader.py`\n- **Function:** `load_cpg_data()` - Reads your CSV/Parquet file\n- **Function:** `get_data_summary()` - Calculates basic stats\n\n**File:** `src/ui/streamlit_app.py`\n- **Function:** `render_home()` - Shows the Overview page\n- When you click \"Load Data\", it calls `load_cpg_data()` and stores data in `st.session_state.data`\n\n---\n\n### 3. The AI Brain (Agent)\n**File:** `src/agent/agent_core.py`\n- **Class:** `CPGDecisionAgent` - This is the main brain\n- **Function:** `chat()` - Handles your questions\n- **Function:** `_plan_actions()` - Decides what to do\n- **Function:** `_execute_plan()` - Runs the tools\n- **Function:** `_generate_response()` - Creates the answer\n\n**How it works:**\n1. You ask: \"What are sales trends?\"\n2. `chat()` receives your question\n3. `_plan_actions()` classifies it as \"trend analysis\"\n4. `_execute_plan()` calls the trend tool\n5. `_generate_response()` uses AI to write the answer\n\n---\n\n### 4. The Tools (Analyzers)\n\n**File:** `src/tools/trend_analysis.py`\n- **Function:** `extract_trends()` - Finds if sales are going up/down\n- **Function:** `calculate_growth_rate()` - Calculates growth percentage\n\n**File:** `src/tools/anomaly_detection.py`\n- **Function:** `get_anomaly_summary()` - Finds weird numbers\n- Uses 3 methods: IQR, Z-score, Isolation Forest\n\n**File:** `src/tools/scenario_simulation.py`\n- **Function:** `simulate_price_change()` - \"What if we change price?\"\n- **Function:** `simulate_promotion()` - \"What if we run a sale?\"\n\n---\n\n### 5. The AI Connection\n**File:** `src/genai/llm_interface.py`\n- **Class:** `LLMInterface` - Talks to AI models\n- Connects to OpenAI, Azure, or HuggingFace\n- The agent uses this to generate answers\n\n---\n\n### 6. Memory System\n**File:** `src/agent/memory.py`\n- **Class:** `SessionMemory` - Remembers things\n- **Function:** `add_message()` - Saves conversations\n- **Function:** `update_context()` - Stores data info\n\nThis lets the app remember what you asked before!\n\n---\n\n## Complete Flow with File Names\n\n### When You Start the App:\n```\n1. You run: streamlit run src/ui/streamlit_app.py\n2. streamlit_app.py → main() function starts\n3. main() → calls init_session_state()\n4. main() → calls render_sidebar()\n5. main() → shows render_home() (Overview page)\n```\n\n### When You Load Data:\n```\n1. User clicks \"Load Data\" button\n2. render_home() → calls load_cpg_data() from data_loader.py\n3. load_cpg_data() → reads your file → returns DataFrame\n4. render_home() → stores in st.session_state.data\n5. render_home() → calls initialize_agent()\n6. initialize_agent() → creates CPGDecisionAgent\n7. Agent → calls load_data() → profiles the data\n8. Agent → stores profile in SessionMemory\n```\n\n### When You Ask a Question (AI Assistant):\n```\n1. User types question in render_chat()\n2. render_chat() → calls agent.chat(question)\n3. agent_core.py → chat() function:\n   ├─→ add_message('user', question) to memory\n   ├─→ _plan_actions(question) → decides what tool to use\n   ├─→ _execute_plan(plan) → calls the tool:\n   │   ├─→ If trend: calls extract_trends() from trend_analysis.py\n   │   ├─→ If anomaly: calls get_anomaly_summary() from anomaly_detection.py\n   │   └─→ If scenario: calls simulate_price_change() from scenario_simulation.py\n   ├─→ _generate_response() → uses LLMInterface to create answer\n   └─→ add_message('assistant', response) to memory\n4. render_chat() → displays the answer\n```\n\n### When You Use a Module (Like Anomaly Detection):\n```\n1. User clicks \"Anomaly Detection\" in sidebar\n2. main() → calls render_anomaly_detection()\n3. render_anomaly_detection() → user selects metric and method\n4. User clicks \"Detect\" button\n5. render_anomaly_detection() → calls get_anomaly_summary() from anomaly_detection.py\n6. get_anomaly_summary() → runs 3 detection methods\n7. Results displayed with charts (using Plotly)\n```\n\n---\n\n## All the Pages and Their Functions\n\n**File:** `src/ui/streamlit_app.py`\n\n1. **Overview Page**\n   - Function: `render_home()`\n   - What it does: Shows data loading, quick stats\n\n2. **AI Assistant Page**\n   - Function: `render_chat()`\n   - What it does: Chat interface, calls `agent.chat()`\n\n3. **Business Insights Page**\n   - Function: `render_smart_insights()`\n   - What it does: Auto-generates insights using agent\n\n4. **Anomaly Detection Page**\n   - Function: `render_anomaly_detection()`\n   - What it does: Calls `get_anomaly_summary()` from `anomaly_detection.py`\n\n5. **Data Comparison Page**\n   - Function: `render_comparison_tool()`\n   - What it does: Compares data segments\n\n6. **Forecasting Page**\n   - Function: `render_forecasting()`\n   - What it does: Predicts future sales\n\n7. **Custom Reports Page**\n   - Function: `render_custom_reports()`\n   - What it does: Creates custom reports\n\n8. **Alert Management Page**\n   - Function: `render_alert_system()`\n   - What it does: Sets up alerts\n\n9. **Dashboard Page**\n   - Function: `render_performance_dashboard()`\n   - What it does: Shows real-time KPIs\n\n---\n\n## File Structure Summary\n\n```\nsmart-cpg-decision-agent/\n├── src/\n│   ├── ui/\n│   │   └── streamlit_app.py          ← Main web interface (all pages)\n│   ├── agent/\n│   │   ├── agent_core.py            ← The AI brain (CPGDecisionAgent)\n│   │   └── memory.py                ← Remembers conversations\n│   ├── tools/\n│   │   ├── trend_analysis.py        ← Analyzes trends\n│   │   ├── anomaly_detection.py     ← Finds anomalies\n│   │   └── scenario_simulation.py    ← \"What-if\" scenarios\n│   ├── genai/\n│   │   └── llm_interface.py         ← Talks to AI models\n│   └── data_loader.py               ← Loads your data\n└── data/\n    └── cpg_sales_data.parquet        ← Your sales data file\n```\n\n---\n\n## Real Example with File Names\n\n**You ask:** \"What are the sales trends?\"\n\n**What happens:**\n1. `streamlit_app.py` → `render_chat()` receives your question\n2. `render_chat()` → calls `agent.chat(\"What are the sales trends?\")`\n3. `agent_core.py` → `chat()` function:\n   - Calls `_plan_actions()` → decides it's a \"trend\" question\n   - Calls `_execute_plan()` → runs `trend_analysis` tool\n4. `trend_analysis.py` → `extract_trends()` analyzes the data\n5. Returns: `{'direction': 'increasing', 'growth_rate': 12.5%}`\n6. `agent_core.py` → `_generate_response()` uses `LLMInterface`\n7. `llm_interface.py` → sends to AI model → gets answer\n8. `render_chat()` → displays the answer to you\n\n---\n\n## Key Functions to Remember\n\n**In `agent_core.py`:**\n- `chat()` - Main function that handles questions\n- `_plan_actions()` - Decides what to do\n- `_execute_plan()` - Runs the tools\n- `_generate_response()` - Creates the answer\n\n**In `streamlit_app.py`:**\n- `main()` - Starts the app\n- `render_home()` - Overview page\n- `render_chat()` - AI Assistant page\n- `render_anomaly_detection()` - Anomaly Detection page\n- (and 6 more render functions for other pages)\n\n**In tools:**\n- `extract_trends()` - Finds trends\n- `get_anomaly_summary()` - Finds anomalies\n- `simulate_price_change()` - Simulates scenarios\n\n---\n\n## Bottom Line\n\n- `streamlit_app.py` = The interface (buttons, pages)\n- `agent_core.py` = The brain (understands questions, coordinates tools)\n- `tools/` = The analyzers (do the math)\n- `llm_interface.py` = Talks to AI (generates answers)\n- `memory.py` = Remembers things (conversation history)\n\nWhen you ask a question, `agent_core.py` coordinates everything, calls the right tool, and uses `llm_interface.py` to give you an answer.\n\n---\n\n## Simple Analogy\n\nThink of it like a restaurant:\n- **`streamlit_app.py`** = The menu and waiter (what you see and interact with)\n- **`agent_core.py`** = The head chef (coordinates everything)\n- **`tools/`** = The kitchen staff (do the actual work)\n- **`llm_interface.py`** = The recipe book (knows how to make things)\n- **`memory.py`** = The order pad (remembers what you asked for)\n\nYou order food (ask a question) → Waiter takes order → Head chef decides what to cook → Kitchen staff prepares it → You get your meal (answer)!\n\n---\n\n## How to Run It\n\n1. **Start the app:**\n   ```bash\n   streamlit run src/ui/streamlit_app.py\n   ```\n\n2. **Load data:**\n   - Click \"Load Data\" button on Overview page\n   - Uses `load_cpg_data()` from `data_loader.py`\n\n3. **Ask questions:**\n   - Go to AI Assistant page\n   - Type your question\n   - `render_chat()` → `agent.chat()` → Tools → Answer!\n\n---\n\n## What Makes It Special\n\n✅ **Smart**: Automatically picks the right tool for your question  \n✅ **Remembers**: Knows what you asked before  \n✅ **Fast**: Answers in seconds  \n✅ **Easy**: Just ask in plain English  \n✅ **Accurate**: Checks everything against real data  \n\n---\n\n**Created for easy understanding - Share this with anyone who wants to know how the project works!**\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadityasinghz%2Fsmart-cpg-decision-agent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadityasinghz%2Fsmart-cpg-decision-agent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadityasinghz%2Fsmart-cpg-decision-agent/lists"}