Spaces:
Runtime error
Runtime error
levisstrauss commited on
Commit ·
ea1c770
1
Parent(s): 92bdf98
Initial deployment of AI Project Planner
Browse files- .gitignore +1 -0
- README.md +120 -8
- app.py +1143 -0
- base_agents.py +525 -0
- requirements.txt +14 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.idea/
|
README.md
CHANGED
|
@@ -1,14 +1,126 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
-
pinned:
|
| 10 |
license: mit
|
| 11 |
-
short_description:
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: AI Project Planner
|
| 3 |
+
emoji: 🚀
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.0.0
|
| 8 |
app_file: app.py
|
| 9 |
+
pinned: true
|
| 10 |
license: mit
|
| 11 |
+
short_description: Transform product specs into comprehensive project plans using AI agents
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# 🚀 AI Project Planner
|
| 15 |
+
|
| 16 |
+
**Transform product specifications into comprehensive project plans using orchestrated AI agents.**
|
| 17 |
+
|
| 18 |
+
[](https://huggingface.co/spaces)
|
| 19 |
+
[](https://www.python.org/downloads/)
|
| 20 |
+
[](https://opensource.org/licenses/MIT)
|
| 21 |
+
|
| 22 |
+
## What This Does
|
| 23 |
+
|
| 24 |
+
Upload any product specification and watch as specialized AI agents collaborate to generate:
|
| 25 |
+
|
| 26 |
+
- **👤 User Stories** - Persona-based requirements in "As a... I want... So that..." format
|
| 27 |
+
- **📦 Product Features** - Logically grouped capabilities with descriptions and user benefits
|
| 28 |
+
- **🔧 Engineering Tasks** - Detailed development work breakdown with dependencies and estimates
|
| 29 |
+
|
| 30 |
+
## How It Works
|
| 31 |
+
|
| 32 |
+
```
|
| 33 |
+
Product Spec → Action Planner → Routing Agent → Specialized Teams → Project Plan
|
| 34 |
+
│
|
| 35 |
+
┌─────────────────┼─────────────────┐
|
| 36 |
+
↓ ↓ ↓
|
| 37 |
+
Product Manager Program Manager Dev Engineer
|
| 38 |
+
(User Stories) (Features) (Tasks)
|
| 39 |
+
│ │ │
|
| 40 |
+
└────────────────►│◄────────────────┘
|
| 41 |
+
Evaluation Agents
|
| 42 |
+
(Quality Assurance Loop)
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
### The Agent Architecture
|
| 46 |
+
|
| 47 |
+
| Agent | Role | Output |
|
| 48 |
+
|-------|------|--------|
|
| 49 |
+
| **Action Planning Agent** | Breaks down high-level goals into workflow steps | Task sequence |
|
| 50 |
+
| **Routing Agent** | Directs each step to the appropriate specialist using semantic similarity | Agent selection |
|
| 51 |
+
| **Product Manager Team** | Knowledge Agent + Evaluation Agent for user stories | Validated stories |
|
| 52 |
+
| **Program Manager Team** | Knowledge Agent + Evaluation Agent for features | Validated features |
|
| 53 |
+
| **Dev Engineer Team** | Knowledge Agent + Evaluation Agent for tasks | Validated tasks |
|
| 54 |
+
|
| 55 |
+
## Quick Start
|
| 56 |
+
|
| 57 |
+
1. **Enter your OpenAI API key** (required for AI agents to function)
|
| 58 |
+
2. **Upload or paste** a product specification (or use an example)
|
| 59 |
+
3. **Click Generate** and watch the workflow execute
|
| 60 |
+
4. **Download** your project plan in Markdown or JSON format
|
| 61 |
+
|
| 62 |
+
## Example Output
|
| 63 |
+
|
| 64 |
+
### User Story
|
| 65 |
+
```
|
| 66 |
+
As a Customer Support Representative, I want the Email Router system
|
| 67 |
+
to automate responses to routine inquiries so that I can focus on
|
| 68 |
+
addressing complex customer issues efficiently.
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
### Product Feature
|
| 72 |
+
```
|
| 73 |
+
Feature Name: Intelligent Email Classification
|
| 74 |
+
Description: NLP-powered analysis for categorizing incoming emails
|
| 75 |
+
Key Functionality: Content analysis, intent detection, priority assignment
|
| 76 |
+
User Benefit: Reduced manual triage time by 70%
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
### Engineering Task
|
| 80 |
+
```
|
| 81 |
+
Task ID: EMAIL-001
|
| 82 |
+
Task Title: Implement NLP classification engine
|
| 83 |
+
Related User Story: US-001
|
| 84 |
+
Description: Develop ML pipeline for email content analysis
|
| 85 |
+
Acceptance Criteria: Classification accuracy >95%
|
| 86 |
+
Estimated Effort: 3 weeks
|
| 87 |
+
Dependencies: Email preprocessing module
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## Technical Details
|
| 91 |
+
|
| 92 |
+
- **Model**: GPT-3.5-turbo for text generation
|
| 93 |
+
- **Embeddings**: text-embedding-3-large for semantic routing
|
| 94 |
+
- **Framework**: Gradio for the web interface
|
| 95 |
+
- **Quality Control**: Iterative evaluation loops with up to 5 refinement cycles
|
| 96 |
+
|
| 97 |
+
## Use Cases
|
| 98 |
+
|
| 99 |
+
- **Product Managers**: Quickly generate user stories from feature ideas
|
| 100 |
+
- **Technical Program Managers**: Create comprehensive project plans
|
| 101 |
+
- **Engineering Leads**: Break down requirements into actionable tasks
|
| 102 |
+
- **Startups**: Transform product vision into development roadmaps
|
| 103 |
+
|
| 104 |
+
## Privacy & Security
|
| 105 |
+
|
| 106 |
+
- Your API key is **never stored** - it's only used for the current session
|
| 107 |
+
- Product specifications are **not retained** after processing
|
| 108 |
+
- All processing happens in real-time with no data persistence
|
| 109 |
+
|
| 110 |
+
## Built With
|
| 111 |
+
|
| 112 |
+
- [Gradio](https://gradio.app/) - Web interface framework
|
| 113 |
+
- [OpenAI API](https://openai.com/) - AI capabilities
|
| 114 |
+
- [NumPy](https://numpy.org/) - Vector operations for semantic routing
|
| 115 |
+
|
| 116 |
+
## Author
|
| 117 |
+
|
| 118 |
+
Built as part of the Udacity AI Programming curriculum, extended with production deployment capabilities.
|
| 119 |
+
|
| 120 |
+
## License
|
| 121 |
+
|
| 122 |
+
MIT License - feel free to use, modify, and distribute.
|
| 123 |
+
|
| 124 |
+
---
|
| 125 |
+
|
| 126 |
+
**⭐ If you find this useful, please star the repository!**
|
app.py
ADDED
|
@@ -0,0 +1,1143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
AI Project Planner - Agentic Workflow for Technical Project Management
|
| 3 |
+
|
| 4 |
+
A professional Gradio application that transforms product specifications into
|
| 5 |
+
comprehensive project plans using orchestrated AI agents.
|
| 6 |
+
|
| 7 |
+
Author: AI Workflow Architect
|
| 8 |
+
License: MIT
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import gradio as gr
|
| 12 |
+
import json
|
| 13 |
+
import time
|
| 14 |
+
from datetime import datetime
|
| 15 |
+
from typing import Generator, Tuple, Dict, Any, List
|
| 16 |
+
import os
|
| 17 |
+
|
| 18 |
+
# Import the agent library
|
| 19 |
+
from base_agents import (
|
| 20 |
+
ActionPlanningAgent,
|
| 21 |
+
KnowledgeAugmentedPromptAgent,
|
| 22 |
+
EvaluationAgent,
|
| 23 |
+
RoutingAgent
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# ============================================================================
|
| 27 |
+
# CUSTOM CSS FOR PROFESSIONAL STYLING
|
| 28 |
+
# ============================================================================
|
| 29 |
+
|
| 30 |
+
CUSTOM_CSS = """
|
| 31 |
+
/* Import Google Fonts */
|
| 32 |
+
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');
|
| 33 |
+
|
| 34 |
+
/* Root Variables */
|
| 35 |
+
:root {
|
| 36 |
+
--primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 37 |
+
--secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
| 38 |
+
--success-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
|
| 39 |
+
--dark-bg: #0f0f1a;
|
| 40 |
+
--card-bg: #1a1a2e;
|
| 41 |
+
--card-border: #2d2d44;
|
| 42 |
+
--text-primary: #ffffff;
|
| 43 |
+
--text-secondary: #a0a0b0;
|
| 44 |
+
--accent-purple: #667eea;
|
| 45 |
+
--accent-pink: #f093fb;
|
| 46 |
+
--accent-cyan: #00f2fe;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
/* Global Styles */
|
| 50 |
+
.gradio-container {
|
| 51 |
+
font-family: 'Space Grotesk', sans-serif !important;
|
| 52 |
+
background: var(--dark-bg) !important;
|
| 53 |
+
max-width: 1400px !important;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/* Header Styling */
|
| 57 |
+
.header-container {
|
| 58 |
+
background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
|
| 59 |
+
border: 1px solid var(--card-border);
|
| 60 |
+
border-radius: 20px;
|
| 61 |
+
padding: 2rem;
|
| 62 |
+
margin-bottom: 1.5rem;
|
| 63 |
+
position: relative;
|
| 64 |
+
overflow: hidden;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.header-container::before {
|
| 68 |
+
content: '';
|
| 69 |
+
position: absolute;
|
| 70 |
+
top: 0;
|
| 71 |
+
left: 0;
|
| 72 |
+
right: 0;
|
| 73 |
+
height: 3px;
|
| 74 |
+
background: var(--primary-gradient);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
.header-title {
|
| 78 |
+
font-size: 2.5rem;
|
| 79 |
+
font-weight: 700;
|
| 80 |
+
background: var(--primary-gradient);
|
| 81 |
+
-webkit-background-clip: text;
|
| 82 |
+
-webkit-text-fill-color: transparent;
|
| 83 |
+
background-clip: text;
|
| 84 |
+
margin-bottom: 0.5rem;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
.header-subtitle {
|
| 88 |
+
color: var(--text-secondary);
|
| 89 |
+
font-size: 1.1rem;
|
| 90 |
+
font-weight: 400;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
/* Card Styling */
|
| 94 |
+
.input-card, .output-card, .workflow-card {
|
| 95 |
+
background: var(--card-bg) !important;
|
| 96 |
+
border: 1px solid var(--card-border) !important;
|
| 97 |
+
border-radius: 16px !important;
|
| 98 |
+
padding: 1.5rem !important;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/* Workflow Progress */
|
| 102 |
+
.workflow-step {
|
| 103 |
+
display: flex;
|
| 104 |
+
align-items: center;
|
| 105 |
+
padding: 1rem;
|
| 106 |
+
margin: 0.5rem 0;
|
| 107 |
+
border-radius: 12px;
|
| 108 |
+
background: rgba(255, 255, 255, 0.02);
|
| 109 |
+
border: 1px solid transparent;
|
| 110 |
+
transition: all 0.3s ease;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.workflow-step.active {
|
| 114 |
+
background: rgba(102, 126, 234, 0.1);
|
| 115 |
+
border-color: var(--accent-purple);
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
.workflow-step.completed {
|
| 119 |
+
background: rgba(0, 242, 254, 0.1);
|
| 120 |
+
border-color: var(--accent-cyan);
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
.step-icon {
|
| 124 |
+
width: 40px;
|
| 125 |
+
height: 40px;
|
| 126 |
+
border-radius: 50%;
|
| 127 |
+
display: flex;
|
| 128 |
+
align-items: center;
|
| 129 |
+
justify-content: center;
|
| 130 |
+
margin-right: 1rem;
|
| 131 |
+
font-size: 1.2rem;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
.step-icon.waiting {
|
| 135 |
+
background: rgba(255, 255, 255, 0.1);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
.step-icon.active {
|
| 139 |
+
background: var(--primary-gradient);
|
| 140 |
+
animation: pulse 2s infinite;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
.step-icon.completed {
|
| 144 |
+
background: var(--success-gradient);
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
@keyframes pulse {
|
| 148 |
+
0%, 100% { transform: scale(1); opacity: 1; }
|
| 149 |
+
50% { transform: scale(1.05); opacity: 0.8; }
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
/* Button Styling */
|
| 153 |
+
.primary-btn {
|
| 154 |
+
background: var(--primary-gradient) !important;
|
| 155 |
+
border: none !important;
|
| 156 |
+
border-radius: 12px !important;
|
| 157 |
+
padding: 1rem 2rem !important;
|
| 158 |
+
font-weight: 600 !important;
|
| 159 |
+
font-size: 1rem !important;
|
| 160 |
+
transition: all 0.3s ease !important;
|
| 161 |
+
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3) !important;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
.primary-btn:hover {
|
| 165 |
+
transform: translateY(-2px) !important;
|
| 166 |
+
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4) !important;
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
.secondary-btn {
|
| 170 |
+
background: transparent !important;
|
| 171 |
+
border: 1px solid var(--card-border) !important;
|
| 172 |
+
border-radius: 12px !important;
|
| 173 |
+
color: var(--text-secondary) !important;
|
| 174 |
+
transition: all 0.3s ease !important;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
.secondary-btn:hover {
|
| 178 |
+
border-color: var(--accent-purple) !important;
|
| 179 |
+
color: var(--accent-purple) !important;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
/* Tab Styling */
|
| 183 |
+
.tabs {
|
| 184 |
+
border: none !important;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.tab-nav {
|
| 188 |
+
background: transparent !important;
|
| 189 |
+
border-bottom: 1px solid var(--card-border) !important;
|
| 190 |
+
gap: 0.5rem !important;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
.tab-nav button {
|
| 194 |
+
background: transparent !important;
|
| 195 |
+
border: none !important;
|
| 196 |
+
border-radius: 8px 8px 0 0 !important;
|
| 197 |
+
color: var(--text-secondary) !important;
|
| 198 |
+
padding: 0.75rem 1.5rem !important;
|
| 199 |
+
font-weight: 500 !important;
|
| 200 |
+
transition: all 0.3s ease !important;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
.tab-nav button.selected {
|
| 204 |
+
background: rgba(102, 126, 234, 0.2) !important;
|
| 205 |
+
color: var(--accent-purple) !important;
|
| 206 |
+
border-bottom: 2px solid var(--accent-purple) !important;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
/* Textbox Styling */
|
| 210 |
+
.textbox textarea {
|
| 211 |
+
background: rgba(0, 0, 0, 0.3) !important;
|
| 212 |
+
border: 1px solid var(--card-border) !important;
|
| 213 |
+
border-radius: 12px !important;
|
| 214 |
+
color: var(--text-primary) !important;
|
| 215 |
+
font-family: 'JetBrains Mono', monospace !important;
|
| 216 |
+
font-size: 0.9rem !important;
|
| 217 |
+
padding: 1rem !important;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
.textbox textarea:focus {
|
| 221 |
+
border-color: var(--accent-purple) !important;
|
| 222 |
+
box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2) !important;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
/* Markdown Styling */
|
| 226 |
+
.markdown-text {
|
| 227 |
+
color: var(--text-primary) !important;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
.markdown-text h1, .markdown-text h2, .markdown-text h3 {
|
| 231 |
+
color: var(--text-primary) !important;
|
| 232 |
+
font-weight: 600 !important;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
.markdown-text code {
|
| 236 |
+
background: rgba(102, 126, 234, 0.2) !important;
|
| 237 |
+
color: var(--accent-cyan) !important;
|
| 238 |
+
padding: 0.2rem 0.5rem !important;
|
| 239 |
+
border-radius: 4px !important;
|
| 240 |
+
font-family: 'JetBrains Mono', monospace !important;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
/* Stats Card */
|
| 244 |
+
.stats-container {
|
| 245 |
+
display: grid;
|
| 246 |
+
grid-template-columns: repeat(4, 1fr);
|
| 247 |
+
gap: 1rem;
|
| 248 |
+
margin-top: 1rem;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
.stat-card {
|
| 252 |
+
background: rgba(255, 255, 255, 0.02);
|
| 253 |
+
border: 1px solid var(--card-border);
|
| 254 |
+
border-radius: 12px;
|
| 255 |
+
padding: 1rem;
|
| 256 |
+
text-align: center;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
.stat-value {
|
| 260 |
+
font-size: 1.5rem;
|
| 261 |
+
font-weight: 700;
|
| 262 |
+
background: var(--primary-gradient);
|
| 263 |
+
-webkit-background-clip: text;
|
| 264 |
+
-webkit-text-fill-color: transparent;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
.stat-label {
|
| 268 |
+
font-size: 0.85rem;
|
| 269 |
+
color: var(--text-secondary);
|
| 270 |
+
margin-top: 0.25rem;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
/* Agent Badge */
|
| 274 |
+
.agent-badge {
|
| 275 |
+
display: inline-flex;
|
| 276 |
+
align-items: center;
|
| 277 |
+
padding: 0.25rem 0.75rem;
|
| 278 |
+
border-radius: 20px;
|
| 279 |
+
font-size: 0.8rem;
|
| 280 |
+
font-weight: 500;
|
| 281 |
+
margin-right: 0.5rem;
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
.agent-badge.product-manager {
|
| 285 |
+
background: rgba(102, 126, 234, 0.2);
|
| 286 |
+
color: #667eea;
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
.agent-badge.program-manager {
|
| 290 |
+
background: rgba(240, 147, 251, 0.2);
|
| 291 |
+
color: #f093fb;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
.agent-badge.dev-engineer {
|
| 295 |
+
background: rgba(0, 242, 254, 0.2);
|
| 296 |
+
color: #00f2fe;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
/* Accordion Styling */
|
| 300 |
+
.accordion {
|
| 301 |
+
border: 1px solid var(--card-border) !important;
|
| 302 |
+
border-radius: 12px !important;
|
| 303 |
+
background: var(--card-bg) !important;
|
| 304 |
+
margin-bottom: 0.5rem !important;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
/* File Upload */
|
| 308 |
+
.file-upload {
|
| 309 |
+
border: 2px dashed var(--card-border) !important;
|
| 310 |
+
border-radius: 12px !important;
|
| 311 |
+
background: rgba(0, 0, 0, 0.2) !important;
|
| 312 |
+
transition: all 0.3s ease !important;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
.file-upload:hover {
|
| 316 |
+
border-color: var(--accent-purple) !important;
|
| 317 |
+
background: rgba(102, 126, 234, 0.05) !important;
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
/* Scrollbar */
|
| 321 |
+
::-webkit-scrollbar {
|
| 322 |
+
width: 8px;
|
| 323 |
+
height: 8px;
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
::-webkit-scrollbar-track {
|
| 327 |
+
background: var(--dark-bg);
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
::-webkit-scrollbar-thumb {
|
| 331 |
+
background: var(--card-border);
|
| 332 |
+
border-radius: 4px;
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
::-webkit-scrollbar-thumb:hover {
|
| 336 |
+
background: var(--accent-purple);
|
| 337 |
+
}
|
| 338 |
+
|
| 339 |
+
/* Loading Animation */
|
| 340 |
+
.loading-dots {
|
| 341 |
+
display: inline-flex;
|
| 342 |
+
gap: 4px;
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
.loading-dots span {
|
| 346 |
+
width: 8px;
|
| 347 |
+
height: 8px;
|
| 348 |
+
border-radius: 50%;
|
| 349 |
+
background: var(--accent-purple);
|
| 350 |
+
animation: bounce 1.4s infinite ease-in-out both;
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
|
| 354 |
+
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }
|
| 355 |
+
|
| 356 |
+
@keyframes bounce {
|
| 357 |
+
0%, 80%, 100% { transform: scale(0); }
|
| 358 |
+
40% { transform: scale(1); }
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
/* Progress Bar */
|
| 362 |
+
.progress-bar {
|
| 363 |
+
height: 4px;
|
| 364 |
+
background: var(--card-border);
|
| 365 |
+
border-radius: 2px;
|
| 366 |
+
overflow: hidden;
|
| 367 |
+
margin-top: 0.5rem;
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
.progress-bar-fill {
|
| 371 |
+
height: 100%;
|
| 372 |
+
background: var(--primary-gradient);
|
| 373 |
+
border-radius: 2px;
|
| 374 |
+
transition: width 0.5s ease;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
/* Example Card */
|
| 378 |
+
.example-card {
|
| 379 |
+
background: rgba(255, 255, 255, 0.02);
|
| 380 |
+
border: 1px solid var(--card-border);
|
| 381 |
+
border-radius: 12px;
|
| 382 |
+
padding: 1rem;
|
| 383 |
+
cursor: pointer;
|
| 384 |
+
transition: all 0.3s ease;
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
.example-card:hover {
|
| 388 |
+
border-color: var(--accent-purple);
|
| 389 |
+
transform: translateY(-2px);
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
.example-title {
|
| 393 |
+
font-weight: 600;
|
| 394 |
+
color: var(--text-primary);
|
| 395 |
+
margin-bottom: 0.5rem;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
.example-desc {
|
| 399 |
+
font-size: 0.85rem;
|
| 400 |
+
color: var(--text-secondary);
|
| 401 |
+
}
|
| 402 |
+
"""
|
| 403 |
+
|
| 404 |
+
# ============================================================================
|
| 405 |
+
# EXAMPLE PRODUCT SPECIFICATIONS
|
| 406 |
+
# ============================================================================
|
| 407 |
+
|
| 408 |
+
EXAMPLE_SPECS = {
|
| 409 |
+
"Email Router": """# Email Router Product Specification
|
| 410 |
+
|
| 411 |
+
## Executive Summary
|
| 412 |
+
The Email Router is an intelligent email management system designed to automatically classify, route, and respond to incoming emails using advanced NLP and machine learning capabilities.
|
| 413 |
+
|
| 414 |
+
## Target Users
|
| 415 |
+
- Customer Support Representatives
|
| 416 |
+
- IT Administrators
|
| 417 |
+
- Subject Matter Experts (SMEs)
|
| 418 |
+
- Business Operations Teams
|
| 419 |
+
|
| 420 |
+
## Core Features
|
| 421 |
+
|
| 422 |
+
### 1. Intelligent Email Classification
|
| 423 |
+
- Automatic categorization of incoming emails by intent, urgency, and topic
|
| 424 |
+
- Support for custom classification rules and machine learning models
|
| 425 |
+
- Real-time processing with sub-second latency requirements
|
| 426 |
+
|
| 427 |
+
### 2. Smart Routing Engine
|
| 428 |
+
- Rule-based routing to appropriate departments or individuals
|
| 429 |
+
- Load balancing across support teams
|
| 430 |
+
- Escalation workflows for high-priority items
|
| 431 |
+
- Integration with existing ticketing systems
|
| 432 |
+
|
| 433 |
+
### 3. Automated Response System
|
| 434 |
+
- Template-based auto-replies for common inquiries
|
| 435 |
+
- AI-generated response suggestions for complex queries
|
| 436 |
+
- Sentiment analysis to adjust tone appropriately
|
| 437 |
+
- Multi-language support
|
| 438 |
+
|
| 439 |
+
### 4. Analytics Dashboard
|
| 440 |
+
- Real-time metrics on email volume, response times, and resolution rates
|
| 441 |
+
- Historical trend analysis and forecasting
|
| 442 |
+
- Agent performance tracking
|
| 443 |
+
- Customer satisfaction scoring
|
| 444 |
+
|
| 445 |
+
### 5. Administration Console
|
| 446 |
+
- User and role management
|
| 447 |
+
- Routing rule configuration
|
| 448 |
+
- Knowledge base management
|
| 449 |
+
- System health monitoring
|
| 450 |
+
|
| 451 |
+
## Technical Requirements
|
| 452 |
+
- Process 10,000+ emails per hour
|
| 453 |
+
- 99.9% uptime SLA
|
| 454 |
+
- Integration via SMTP, IMAP, and REST APIs
|
| 455 |
+
- SOC 2 Type II compliance
|
| 456 |
+
- GDPR and CCPA data handling
|
| 457 |
+
|
| 458 |
+
## Success Metrics
|
| 459 |
+
- 70% reduction in manual email triage time
|
| 460 |
+
- 50% improvement in first-response time
|
| 461 |
+
- 90% customer satisfaction score
|
| 462 |
+
- 95% routing accuracy
|
| 463 |
+
""",
|
| 464 |
+
|
| 465 |
+
"Task Management App": """# Task Management Application Specification
|
| 466 |
+
|
| 467 |
+
## Product Vision
|
| 468 |
+
A modern, collaborative task management platform that helps teams organize work, track progress, and meet deadlines efficiently.
|
| 469 |
+
|
| 470 |
+
## Target Users
|
| 471 |
+
- Project Managers
|
| 472 |
+
- Team Members
|
| 473 |
+
- Executives/Stakeholders
|
| 474 |
+
- Remote Teams
|
| 475 |
+
|
| 476 |
+
## Core Features
|
| 477 |
+
|
| 478 |
+
### 1. Task Creation & Organization
|
| 479 |
+
- Create tasks with titles, descriptions, due dates, and priorities
|
| 480 |
+
- Organize tasks into projects and workspaces
|
| 481 |
+
- Support for subtasks and checklists
|
| 482 |
+
- File attachments and rich text descriptions
|
| 483 |
+
|
| 484 |
+
### 2. Collaboration Tools
|
| 485 |
+
- Assign tasks to team members
|
| 486 |
+
- Comment threads on tasks
|
| 487 |
+
- @mentions and notifications
|
| 488 |
+
- Real-time updates and sync
|
| 489 |
+
|
| 490 |
+
### 3. Views & Visualization
|
| 491 |
+
- List view for detailed task management
|
| 492 |
+
- Kanban board for workflow visualization
|
| 493 |
+
- Calendar view for deadline tracking
|
| 494 |
+
- Gantt chart for project timeline
|
| 495 |
+
|
| 496 |
+
### 4. Automation
|
| 497 |
+
- Recurring task creation
|
| 498 |
+
- Due date reminders
|
| 499 |
+
- Status change triggers
|
| 500 |
+
- Integration webhooks
|
| 501 |
+
|
| 502 |
+
### 5. Reporting & Analytics
|
| 503 |
+
- Project progress dashboards
|
| 504 |
+
- Team workload distribution
|
| 505 |
+
- Time tracking and estimates
|
| 506 |
+
- Custom report generation
|
| 507 |
+
|
| 508 |
+
## Technical Requirements
|
| 509 |
+
- Web, iOS, and Android applications
|
| 510 |
+
- Real-time synchronization
|
| 511 |
+
- Offline mode support
|
| 512 |
+
- Third-party integrations (Slack, GitHub, Google Calendar)
|
| 513 |
+
- Enterprise SSO support
|
| 514 |
+
|
| 515 |
+
## Success Metrics
|
| 516 |
+
- 30% improvement in project delivery time
|
| 517 |
+
- 50% reduction in missed deadlines
|
| 518 |
+
- 85% daily active user rate
|
| 519 |
+
- 4.5+ app store rating
|
| 520 |
+
""",
|
| 521 |
+
|
| 522 |
+
"E-Commerce Platform": """# E-Commerce Platform Specification
|
| 523 |
+
|
| 524 |
+
## Product Overview
|
| 525 |
+
A scalable e-commerce platform enabling businesses to create online stores, manage inventory, process payments, and fulfill orders.
|
| 526 |
+
|
| 527 |
+
## Target Users
|
| 528 |
+
- Small Business Owners
|
| 529 |
+
- E-commerce Managers
|
| 530 |
+
- Warehouse Staff
|
| 531 |
+
- Customer Service Teams
|
| 532 |
+
|
| 533 |
+
## Core Features
|
| 534 |
+
|
| 535 |
+
### 1. Store Management
|
| 536 |
+
- Customizable storefront templates
|
| 537 |
+
- Product catalog management
|
| 538 |
+
- Category and collection organization
|
| 539 |
+
- SEO optimization tools
|
| 540 |
+
|
| 541 |
+
### 2. Inventory System
|
| 542 |
+
- Real-time stock tracking
|
| 543 |
+
- Multi-warehouse support
|
| 544 |
+
- Low stock alerts
|
| 545 |
+
- Supplier management
|
| 546 |
+
|
| 547 |
+
### 3. Order Processing
|
| 548 |
+
- Shopping cart functionality
|
| 549 |
+
- Multiple payment gateways
|
| 550 |
+
- Order status tracking
|
| 551 |
+
- Return and refund handling
|
| 552 |
+
|
| 553 |
+
### 4. Customer Management
|
| 554 |
+
- Customer accounts and profiles
|
| 555 |
+
- Order history
|
| 556 |
+
- Wishlist functionality
|
| 557 |
+
- Loyalty program support
|
| 558 |
+
|
| 559 |
+
### 5. Analytics & Reports
|
| 560 |
+
- Sales dashboards
|
| 561 |
+
- Customer behavior analytics
|
| 562 |
+
- Inventory reports
|
| 563 |
+
- Financial summaries
|
| 564 |
+
|
| 565 |
+
## Technical Requirements
|
| 566 |
+
- Support 100,000+ concurrent users
|
| 567 |
+
- PCI DSS compliance
|
| 568 |
+
- Mobile-responsive design
|
| 569 |
+
- API for third-party integrations
|
| 570 |
+
- Multi-currency and multi-language
|
| 571 |
+
|
| 572 |
+
## Success Metrics
|
| 573 |
+
- 99.99% checkout availability
|
| 574 |
+
- <2 second page load time
|
| 575 |
+
- 3% conversion rate
|
| 576 |
+
- <1% cart abandonment from technical issues
|
| 577 |
+
"""
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
# ============================================================================
|
| 581 |
+
# WORKFLOW KNOWLEDGE DEFINITIONS
|
| 582 |
+
# ============================================================================
|
| 583 |
+
|
| 584 |
+
KNOWLEDGE_ACTION_PLANNING = """
|
| 585 |
+
Stories are defined from a product spec by identifying a persona, an action, and a desired outcome for each story.
|
| 586 |
+
Each story represents a specific functionality of the product described in the specification.
|
| 587 |
+
Features are defined by grouping related user stories into cohesive capabilities.
|
| 588 |
+
Tasks are defined for each story and represent the engineering work required to develop the product.
|
| 589 |
+
A development Plan for a product contains all these components organized in a logical structure.
|
| 590 |
+
"""
|
| 591 |
+
|
| 592 |
+
PERSONA_PRODUCT_MANAGER = "You are a Product Manager responsible for defining user stories for a product."
|
| 593 |
+
PERSONA_PROGRAM_MANAGER = "You are a Program Manager responsible for defining product features."
|
| 594 |
+
PERSONA_DEV_ENGINEER = "You are a Development Engineer responsible for defining engineering tasks."
|
| 595 |
+
|
| 596 |
+
EVALUATION_CRITERIA_USER_STORIES = (
|
| 597 |
+
"The answer should be stories that follow the following structure: "
|
| 598 |
+
"As a [type of user], I want [an action or feature] so that [benefit/value]."
|
| 599 |
+
)
|
| 600 |
+
|
| 601 |
+
EVALUATION_CRITERIA_FEATURES = (
|
| 602 |
+
"The answer should be product features that follow the following structure: "
|
| 603 |
+
"Feature Name: A clear, concise title that identifies the capability\n"
|
| 604 |
+
"Description: A brief explanation of what the feature does and its purpose\n"
|
| 605 |
+
"Key Functionality: The specific capabilities or actions the feature provides\n"
|
| 606 |
+
"User Benefit: How this feature creates value for the user"
|
| 607 |
+
)
|
| 608 |
+
|
| 609 |
+
EVALUATION_CRITERIA_TASKS = (
|
| 610 |
+
"The answer should be tasks following this exact structure: "
|
| 611 |
+
"Task ID: A unique identifier for tracking purposes\n"
|
| 612 |
+
"Task Title: Brief description of the specific development work\n"
|
| 613 |
+
"Related User Story: Reference to the parent user story\n"
|
| 614 |
+
"Description: Detailed explanation of the technical work required\n"
|
| 615 |
+
"Acceptance Criteria: Specific requirements that must be met for completion\n"
|
| 616 |
+
"Estimated Effort: Time or complexity estimation\n"
|
| 617 |
+
"Dependencies: Any tasks that must be completed first"
|
| 618 |
+
)
|
| 619 |
+
|
| 620 |
+
# ============================================================================
|
| 621 |
+
# WORKFLOW ENGINE
|
| 622 |
+
# ============================================================================
|
| 623 |
+
|
| 624 |
+
class ProjectPlannerWorkflow:
|
| 625 |
+
"""
|
| 626 |
+
Orchestrates the multi-agent workflow for generating project plans.
|
| 627 |
+
"""
|
| 628 |
+
|
| 629 |
+
def __init__(self, api_key: str):
|
| 630 |
+
self.api_key = api_key
|
| 631 |
+
self.agents_initialized = False
|
| 632 |
+
self.workflow_log = []
|
| 633 |
+
self.stats = {
|
| 634 |
+
"user_stories": 0,
|
| 635 |
+
"features": 0,
|
| 636 |
+
"tasks": 0,
|
| 637 |
+
"iterations": 0
|
| 638 |
+
}
|
| 639 |
+
|
| 640 |
+
def log(self, message: str, level: str = "info"):
|
| 641 |
+
"""Add a message to the workflow log."""
|
| 642 |
+
timestamp = datetime.now().strftime("%H:%M:%S")
|
| 643 |
+
self.workflow_log.append({
|
| 644 |
+
"timestamp": timestamp,
|
| 645 |
+
"level": level,
|
| 646 |
+
"message": message
|
| 647 |
+
})
|
| 648 |
+
|
| 649 |
+
def initialize_agents(self, product_spec: str):
|
| 650 |
+
"""Initialize all agents with the product specification."""
|
| 651 |
+
self.log("Initializing AI agents...")
|
| 652 |
+
|
| 653 |
+
# Action Planning Agent
|
| 654 |
+
self.action_planning_agent = ActionPlanningAgent(
|
| 655 |
+
self.api_key,
|
| 656 |
+
KNOWLEDGE_ACTION_PLANNING
|
| 657 |
+
)
|
| 658 |
+
|
| 659 |
+
# Product Manager Team
|
| 660 |
+
knowledge_pm = (
|
| 661 |
+
"Stories are defined by writing sentences with a persona, an action, and a desired outcome. "
|
| 662 |
+
"The sentences always start with: As a "
|
| 663 |
+
"Write several stories for the product spec below, where the personas are the different users of the product. "
|
| 664 |
+
f"\n\nProduct Specification:\n{product_spec}"
|
| 665 |
+
)
|
| 666 |
+
|
| 667 |
+
self.product_manager_agent = KnowledgeAugmentedPromptAgent(
|
| 668 |
+
self.api_key,
|
| 669 |
+
PERSONA_PRODUCT_MANAGER,
|
| 670 |
+
knowledge_pm
|
| 671 |
+
)
|
| 672 |
+
|
| 673 |
+
self.product_manager_evaluator = EvaluationAgent(
|
| 674 |
+
openai_api_key=self.api_key,
|
| 675 |
+
persona="You are an evaluation agent that checks the answers of other worker agents",
|
| 676 |
+
evaluation_criteria=EVALUATION_CRITERIA_USER_STORIES,
|
| 677 |
+
worker_agent=self.product_manager_agent,
|
| 678 |
+
max_interactions=5
|
| 679 |
+
)
|
| 680 |
+
|
| 681 |
+
# Program Manager Team
|
| 682 |
+
knowledge_pgm = (
|
| 683 |
+
"Features of a product are defined by organizing similar user stories into cohesive groups. "
|
| 684 |
+
f"\n\nProduct Specification:\n{product_spec}"
|
| 685 |
+
)
|
| 686 |
+
|
| 687 |
+
self.program_manager_agent = KnowledgeAugmentedPromptAgent(
|
| 688 |
+
self.api_key,
|
| 689 |
+
PERSONA_PROGRAM_MANAGER,
|
| 690 |
+
knowledge_pgm
|
| 691 |
+
)
|
| 692 |
+
|
| 693 |
+
self.program_manager_evaluator = EvaluationAgent(
|
| 694 |
+
openai_api_key=self.api_key,
|
| 695 |
+
persona="You are an evaluation agent that checks the answers of other worker agents",
|
| 696 |
+
evaluation_criteria=EVALUATION_CRITERIA_FEATURES,
|
| 697 |
+
worker_agent=self.program_manager_agent,
|
| 698 |
+
max_interactions=5
|
| 699 |
+
)
|
| 700 |
+
|
| 701 |
+
# Development Engineer Team
|
| 702 |
+
knowledge_dev = (
|
| 703 |
+
"Development tasks are defined by identifying what needs to be built to implement each user story. "
|
| 704 |
+
f"\n\nProduct Specification:\n{product_spec}"
|
| 705 |
+
)
|
| 706 |
+
|
| 707 |
+
self.dev_engineer_agent = KnowledgeAugmentedPromptAgent(
|
| 708 |
+
self.api_key,
|
| 709 |
+
PERSONA_DEV_ENGINEER,
|
| 710 |
+
knowledge_dev
|
| 711 |
+
)
|
| 712 |
+
|
| 713 |
+
self.dev_engineer_evaluator = EvaluationAgent(
|
| 714 |
+
openai_api_key=self.api_key,
|
| 715 |
+
persona="You are an evaluation agent that checks the answers of other worker agents",
|
| 716 |
+
evaluation_criteria=EVALUATION_CRITERIA_TASKS,
|
| 717 |
+
worker_agent=self.dev_engineer_agent,
|
| 718 |
+
max_interactions=5
|
| 719 |
+
)
|
| 720 |
+
|
| 721 |
+
# Routing Agent
|
| 722 |
+
routes = [
|
| 723 |
+
{
|
| 724 |
+
"name": "Product Manager",
|
| 725 |
+
"description": "Responsible for defining product personas and user stories only.",
|
| 726 |
+
"func": self._product_manager_handler
|
| 727 |
+
},
|
| 728 |
+
{
|
| 729 |
+
"name": "Program Manager",
|
| 730 |
+
"description": "Responsible for defining product features by grouping related user stories.",
|
| 731 |
+
"func": self._program_manager_handler
|
| 732 |
+
},
|
| 733 |
+
{
|
| 734 |
+
"name": "Development Engineer",
|
| 735 |
+
"description": "Responsible for defining development tasks and engineering work.",
|
| 736 |
+
"func": self._dev_engineer_handler
|
| 737 |
+
}
|
| 738 |
+
]
|
| 739 |
+
|
| 740 |
+
self.routing_agent = RoutingAgent(self.api_key, routes)
|
| 741 |
+
|
| 742 |
+
self.agents_initialized = True
|
| 743 |
+
self.log("All agents initialized successfully", "success")
|
| 744 |
+
|
| 745 |
+
def _product_manager_handler(self, query: str) -> str:
|
| 746 |
+
"""Handle Product Manager routing."""
|
| 747 |
+
self.log("Product Manager generating user stories...")
|
| 748 |
+
response = self.product_manager_agent.respond(query)
|
| 749 |
+
result = self.product_manager_evaluator.evaluate(response)
|
| 750 |
+
self.stats["iterations"] += result.get("iterations", 1)
|
| 751 |
+
return result["final_response"]
|
| 752 |
+
|
| 753 |
+
def _program_manager_handler(self, query: str) -> str:
|
| 754 |
+
"""Handle Program Manager routing."""
|
| 755 |
+
self.log("Program Manager defining features...")
|
| 756 |
+
response = self.program_manager_agent.respond(query)
|
| 757 |
+
result = self.program_manager_evaluator.evaluate(response)
|
| 758 |
+
self.stats["iterations"] += result.get("iterations", 1)
|
| 759 |
+
return result["final_response"]
|
| 760 |
+
|
| 761 |
+
def _dev_engineer_handler(self, query: str) -> str:
|
| 762 |
+
"""Handle Development Engineer routing."""
|
| 763 |
+
self.log("Development Engineer creating tasks...")
|
| 764 |
+
response = self.dev_engineer_agent.respond(query)
|
| 765 |
+
result = self.dev_engineer_evaluator.evaluate(response)
|
| 766 |
+
self.stats["iterations"] += result.get("iterations", 1)
|
| 767 |
+
return result["final_response"]
|
| 768 |
+
|
| 769 |
+
def run_workflow(self, product_spec: str) -> Generator[Tuple[str, str, str, str, str], None, None]:
|
| 770 |
+
"""
|
| 771 |
+
Execute the full workflow and yield progress updates.
|
| 772 |
+
|
| 773 |
+
Yields tuples of:
|
| 774 |
+
(workflow_status, user_stories, features, tasks, full_plan)
|
| 775 |
+
"""
|
| 776 |
+
self.workflow_log = []
|
| 777 |
+
self.stats = {"user_stories": 0, "features": 0, "tasks": 0, "iterations": 0}
|
| 778 |
+
|
| 779 |
+
# Initialize agents
|
| 780 |
+
yield ("⏳ Initializing agents...", "", "", "", "")
|
| 781 |
+
self.initialize_agents(product_spec)
|
| 782 |
+
|
| 783 |
+
# Extract workflow steps
|
| 784 |
+
yield ("🔍 Planning workflow steps...", "", "", "", "")
|
| 785 |
+
self.log("Action Planning Agent analyzing product specification...")
|
| 786 |
+
|
| 787 |
+
workflow_prompt = (
|
| 788 |
+
"Create a comprehensive project plan including: "
|
| 789 |
+
"1) User stories for all personas, "
|
| 790 |
+
"2) Key product features grouped logically, "
|
| 791 |
+
"3) Development tasks for implementation"
|
| 792 |
+
)
|
| 793 |
+
|
| 794 |
+
steps = self.action_planning_agent.extract_steps_from_prompt(workflow_prompt)
|
| 795 |
+
self.log(f"Identified {len(steps)} workflow steps", "success")
|
| 796 |
+
|
| 797 |
+
# Process each step
|
| 798 |
+
user_stories = ""
|
| 799 |
+
features = ""
|
| 800 |
+
tasks = ""
|
| 801 |
+
|
| 802 |
+
# Generate User Stories
|
| 803 |
+
yield ("👤 Generating user stories...", "", "", "", "")
|
| 804 |
+
self.log("Routing to Product Manager team...")
|
| 805 |
+
|
| 806 |
+
user_stories_prompt = "Define comprehensive user stories for all personas in the product specification"
|
| 807 |
+
user_stories = self._product_manager_handler(user_stories_prompt)
|
| 808 |
+
self.stats["user_stories"] = user_stories.count("As a")
|
| 809 |
+
self.log(f"Generated {self.stats['user_stories']} user stories", "success")
|
| 810 |
+
|
| 811 |
+
yield ("✅ User stories complete", user_stories, "", "", "")
|
| 812 |
+
|
| 813 |
+
# Generate Features
|
| 814 |
+
yield ("📦 Defining product features...", user_stories, "", "", "")
|
| 815 |
+
self.log("Routing to Program Manager team...")
|
| 816 |
+
|
| 817 |
+
features_prompt = f"Based on these user stories, define the key product features:\n\n{user_stories}"
|
| 818 |
+
features = self._program_manager_handler(features_prompt)
|
| 819 |
+
self.stats["features"] = features.lower().count("feature name")
|
| 820 |
+
self.log(f"Defined {self.stats['features']} product features", "success")
|
| 821 |
+
|
| 822 |
+
yield ("✅ Features complete", user_stories, features, "", "")
|
| 823 |
+
|
| 824 |
+
# Generate Tasks
|
| 825 |
+
yield ("🔧 Creating engineering tasks...", user_stories, features, "", "")
|
| 826 |
+
self.log("Routing to Development Engineer team...")
|
| 827 |
+
|
| 828 |
+
tasks_prompt = f"Create detailed engineering tasks to implement these features:\n\n{features}"
|
| 829 |
+
tasks = self._dev_engineer_handler(tasks_prompt)
|
| 830 |
+
self.stats["tasks"] = tasks.lower().count("task id")
|
| 831 |
+
self.log(f"Created {self.stats['tasks']} engineering tasks", "success")
|
| 832 |
+
|
| 833 |
+
yield ("✅ Tasks complete", user_stories, features, tasks, "")
|
| 834 |
+
|
| 835 |
+
# Generate Full Plan
|
| 836 |
+
yield ("📋 Compiling final plan...", user_stories, features, tasks, "")
|
| 837 |
+
|
| 838 |
+
full_plan = self._compile_full_plan(user_stories, features, tasks)
|
| 839 |
+
self.log("Project plan compilation complete!", "success")
|
| 840 |
+
|
| 841 |
+
yield ("✅ Project plan ready!", user_stories, features, tasks, full_plan)
|
| 842 |
+
|
| 843 |
+
def _compile_full_plan(self, user_stories: str, features: str, tasks: str) -> str:
|
| 844 |
+
"""Compile all outputs into a formatted project plan."""
|
| 845 |
+
plan = f"""# 📋 Project Plan
|
| 846 |
+
|
| 847 |
+
## Generated: {datetime.now().strftime("%Y-%m-%d %H:%M")}
|
| 848 |
+
|
| 849 |
+
---
|
| 850 |
+
|
| 851 |
+
## 📊 Summary Statistics
|
| 852 |
+
|
| 853 |
+
| Metric | Count |
|
| 854 |
+
|--------|-------|
|
| 855 |
+
| User Stories | {self.stats['user_stories']} |
|
| 856 |
+
| Product Features | {self.stats['features']} |
|
| 857 |
+
| Engineering Tasks | {self.stats['tasks']} |
|
| 858 |
+
| Evaluation Iterations | {self.stats['iterations']} |
|
| 859 |
+
|
| 860 |
+
---
|
| 861 |
+
|
| 862 |
+
## 👤 User Stories
|
| 863 |
+
|
| 864 |
+
{user_stories}
|
| 865 |
+
|
| 866 |
+
---
|
| 867 |
+
|
| 868 |
+
## 📦 Product Features
|
| 869 |
+
|
| 870 |
+
{features}
|
| 871 |
+
|
| 872 |
+
---
|
| 873 |
+
|
| 874 |
+
## 🔧 Engineering Tasks
|
| 875 |
+
|
| 876 |
+
{tasks}
|
| 877 |
+
|
| 878 |
+
---
|
| 879 |
+
|
| 880 |
+
## 📝 Workflow Log
|
| 881 |
+
|
| 882 |
+
| Time | Level | Message |
|
| 883 |
+
|------|-------|---------|
|
| 884 |
+
"""
|
| 885 |
+
for log_entry in self.workflow_log:
|
| 886 |
+
plan += f"| {log_entry['timestamp']} | {log_entry['level']} | {log_entry['message']} |\n"
|
| 887 |
+
|
| 888 |
+
return plan
|
| 889 |
+
|
| 890 |
+
|
| 891 |
+
# ============================================================================
|
| 892 |
+
# GRADIO INTERFACE
|
| 893 |
+
# ============================================================================
|
| 894 |
+
|
| 895 |
+
def create_interface():
|
| 896 |
+
"""Create the Gradio interface."""
|
| 897 |
+
|
| 898 |
+
workflow = None
|
| 899 |
+
|
| 900 |
+
def validate_api_key(api_key: str) -> str:
|
| 901 |
+
"""Validate the API key format."""
|
| 902 |
+
if not api_key or len(api_key) < 20:
|
| 903 |
+
return "❌ Please enter a valid API key"
|
| 904 |
+
return "✅ API key accepted"
|
| 905 |
+
|
| 906 |
+
def load_example(example_name: str) -> str:
|
| 907 |
+
"""Load an example product specification."""
|
| 908 |
+
return EXAMPLE_SPECS.get(example_name, "")
|
| 909 |
+
|
| 910 |
+
def run_planner(
|
| 911 |
+
api_key: str,
|
| 912 |
+
product_spec: str,
|
| 913 |
+
progress=gr.Progress()
|
| 914 |
+
) -> Tuple[str, str, str, str, str]:
|
| 915 |
+
"""Run the project planner workflow."""
|
| 916 |
+
|
| 917 |
+
if not api_key or len(api_key) < 20:
|
| 918 |
+
return (
|
| 919 |
+
"❌ Error: Please enter a valid OpenAI API key",
|
| 920 |
+
"", "", "", ""
|
| 921 |
+
)
|
| 922 |
+
|
| 923 |
+
if not product_spec or len(product_spec) < 100:
|
| 924 |
+
return (
|
| 925 |
+
"❌ Error: Please provide a product specification (minimum 100 characters)",
|
| 926 |
+
"", "", "", ""
|
| 927 |
+
)
|
| 928 |
+
|
| 929 |
+
try:
|
| 930 |
+
planner = ProjectPlannerWorkflow(api_key)
|
| 931 |
+
|
| 932 |
+
results = ("", "", "", "", "")
|
| 933 |
+
progress(0, desc="Starting workflow...")
|
| 934 |
+
|
| 935 |
+
step_progress = [0.1, 0.2, 0.4, 0.6, 0.8, 0.9, 1.0]
|
| 936 |
+
step_idx = 0
|
| 937 |
+
|
| 938 |
+
for status, stories, features, tasks, plan in planner.run_workflow(product_spec):
|
| 939 |
+
if step_idx < len(step_progress):
|
| 940 |
+
progress(step_progress[step_idx], desc=status)
|
| 941 |
+
step_idx += 1
|
| 942 |
+
results = (status, stories, features, tasks, plan)
|
| 943 |
+
|
| 944 |
+
return results
|
| 945 |
+
|
| 946 |
+
except Exception as e:
|
| 947 |
+
return (
|
| 948 |
+
f"❌ Error: {str(e)}",
|
| 949 |
+
"", "", "", ""
|
| 950 |
+
)
|
| 951 |
+
|
| 952 |
+
def export_markdown(user_stories: str, features: str, tasks: str) -> str:
|
| 953 |
+
"""Export results as markdown."""
|
| 954 |
+
if not any([user_stories, features, tasks]):
|
| 955 |
+
return None
|
| 956 |
+
|
| 957 |
+
content = f"""# Project Plan Export
|
| 958 |
+
Generated: {datetime.now().strftime("%Y-%m-%d %H:%M")}
|
| 959 |
+
|
| 960 |
+
## User Stories
|
| 961 |
+
{user_stories}
|
| 962 |
+
|
| 963 |
+
## Product Features
|
| 964 |
+
{features}
|
| 965 |
+
|
| 966 |
+
## Engineering Tasks
|
| 967 |
+
{tasks}
|
| 968 |
+
"""
|
| 969 |
+
# Save to temp file
|
| 970 |
+
filename = f"project_plan_{datetime.now().strftime('%Y%m%d_%H%M%S')}.md"
|
| 971 |
+
with open(filename, "w") as f:
|
| 972 |
+
f.write(content)
|
| 973 |
+
return filename
|
| 974 |
+
|
| 975 |
+
def export_json(user_stories: str, features: str, tasks: str) -> str:
|
| 976 |
+
"""Export results as JSON."""
|
| 977 |
+
if not any([user_stories, features, tasks]):
|
| 978 |
+
return None
|
| 979 |
+
|
| 980 |
+
data = {
|
| 981 |
+
"generated_at": datetime.now().isoformat(),
|
| 982 |
+
"user_stories": user_stories,
|
| 983 |
+
"features": features,
|
| 984 |
+
"tasks": tasks
|
| 985 |
+
}
|
| 986 |
+
|
| 987 |
+
filename = f"project_plan_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
|
| 988 |
+
with open(filename, "w") as f:
|
| 989 |
+
json.dump(data, f, indent=2)
|
| 990 |
+
return filename
|
| 991 |
+
|
| 992 |
+
# Build the interface
|
| 993 |
+
with gr.Blocks(css=CUSTOM_CSS, title="AI Project Planner", theme=gr.themes.Base()) as app:
|
| 994 |
+
|
| 995 |
+
# Header
|
| 996 |
+
gr.HTML("""
|
| 997 |
+
<div class="header-container">
|
| 998 |
+
<div class="header-title">🚀 AI Project Planner</div>
|
| 999 |
+
<div class="header-subtitle">
|
| 1000 |
+
Transform product specifications into comprehensive project plans using orchestrated AI agents
|
| 1001 |
+
</div>
|
| 1002 |
+
</div>
|
| 1003 |
+
""")
|
| 1004 |
+
|
| 1005 |
+
with gr.Row():
|
| 1006 |
+
# Left Column - Input
|
| 1007 |
+
with gr.Column(scale=1):
|
| 1008 |
+
gr.Markdown("### ⚙️ Configuration")
|
| 1009 |
+
|
| 1010 |
+
api_key_input = gr.Textbox(
|
| 1011 |
+
label="OpenAI API Key",
|
| 1012 |
+
placeholder="sk-...",
|
| 1013 |
+
type="password",
|
| 1014 |
+
info="Your API key is not stored and only used for this session"
|
| 1015 |
+
)
|
| 1016 |
+
|
| 1017 |
+
api_status = gr.Markdown("Enter your API key to begin")
|
| 1018 |
+
|
| 1019 |
+
api_key_input.change(
|
| 1020 |
+
fn=validate_api_key,
|
| 1021 |
+
inputs=[api_key_input],
|
| 1022 |
+
outputs=[api_status]
|
| 1023 |
+
)
|
| 1024 |
+
|
| 1025 |
+
gr.Markdown("### 📄 Product Specification")
|
| 1026 |
+
|
| 1027 |
+
with gr.Accordion("📚 Load Example", open=False):
|
| 1028 |
+
example_dropdown = gr.Dropdown(
|
| 1029 |
+
choices=list(EXAMPLE_SPECS.keys()),
|
| 1030 |
+
label="Select Example",
|
| 1031 |
+
value="Email Router"
|
| 1032 |
+
)
|
| 1033 |
+
load_example_btn = gr.Button("Load Example", variant="secondary")
|
| 1034 |
+
|
| 1035 |
+
spec_input = gr.Textbox(
|
| 1036 |
+
label="Product Specification",
|
| 1037 |
+
placeholder="Paste your product specification here...",
|
| 1038 |
+
lines=15,
|
| 1039 |
+
max_lines=30
|
| 1040 |
+
)
|
| 1041 |
+
|
| 1042 |
+
load_example_btn.click(
|
| 1043 |
+
fn=load_example,
|
| 1044 |
+
inputs=[example_dropdown],
|
| 1045 |
+
outputs=[spec_input]
|
| 1046 |
+
)
|
| 1047 |
+
|
| 1048 |
+
generate_btn = gr.Button(
|
| 1049 |
+
"🎯 Generate Project Plan",
|
| 1050 |
+
variant="primary",
|
| 1051 |
+
elem_classes=["primary-btn"]
|
| 1052 |
+
)
|
| 1053 |
+
|
| 1054 |
+
# Right Column - Output
|
| 1055 |
+
with gr.Column(scale=2):
|
| 1056 |
+
gr.Markdown("### 📊 Results")
|
| 1057 |
+
|
| 1058 |
+
workflow_status = gr.Markdown("Ready to generate project plan")
|
| 1059 |
+
|
| 1060 |
+
with gr.Tabs():
|
| 1061 |
+
with gr.Tab("👤 User Stories"):
|
| 1062 |
+
user_stories_output = gr.Markdown(
|
| 1063 |
+
label="User Stories",
|
| 1064 |
+
elem_classes=["output-content"]
|
| 1065 |
+
)
|
| 1066 |
+
|
| 1067 |
+
with gr.Tab("📦 Features"):
|
| 1068 |
+
features_output = gr.Markdown(
|
| 1069 |
+
label="Product Features",
|
| 1070 |
+
elem_classes=["output-content"]
|
| 1071 |
+
)
|
| 1072 |
+
|
| 1073 |
+
with gr.Tab("🔧 Tasks"):
|
| 1074 |
+
tasks_output = gr.Markdown(
|
| 1075 |
+
label="Engineering Tasks",
|
| 1076 |
+
elem_classes=["output-content"]
|
| 1077 |
+
)
|
| 1078 |
+
|
| 1079 |
+
with gr.Tab("📋 Full Plan"):
|
| 1080 |
+
full_plan_output = gr.Markdown(
|
| 1081 |
+
label="Complete Project Plan",
|
| 1082 |
+
elem_classes=["output-content"]
|
| 1083 |
+
)
|
| 1084 |
+
|
| 1085 |
+
gr.Markdown("### 📥 Export")
|
| 1086 |
+
|
| 1087 |
+
with gr.Row():
|
| 1088 |
+
export_md_btn = gr.Button("📄 Download Markdown", variant="secondary")
|
| 1089 |
+
export_json_btn = gr.Button("📊 Download JSON", variant="secondary")
|
| 1090 |
+
|
| 1091 |
+
export_file = gr.File(label="Download", visible=False)
|
| 1092 |
+
|
| 1093 |
+
# Footer
|
| 1094 |
+
gr.HTML("""
|
| 1095 |
+
<div style="text-align: center; margin-top: 2rem; padding: 1rem; border-top: 1px solid #2d2d44;">
|
| 1096 |
+
<p style="color: #a0a0b0; font-size: 0.9rem;">
|
| 1097 |
+
Built with ❤️ using Gradio • Powered by OpenAI GPT-3.5 •
|
| 1098 |
+
<a href="https://github.com" style="color: #667eea;">View on GitHub</a>
|
| 1099 |
+
</p>
|
| 1100 |
+
</div>
|
| 1101 |
+
""")
|
| 1102 |
+
|
| 1103 |
+
# Event handlers
|
| 1104 |
+
generate_btn.click(
|
| 1105 |
+
fn=run_planner,
|
| 1106 |
+
inputs=[api_key_input, spec_input],
|
| 1107 |
+
outputs=[
|
| 1108 |
+
workflow_status,
|
| 1109 |
+
user_stories_output,
|
| 1110 |
+
features_output,
|
| 1111 |
+
tasks_output,
|
| 1112 |
+
full_plan_output
|
| 1113 |
+
],
|
| 1114 |
+
show_progress=True
|
| 1115 |
+
)
|
| 1116 |
+
|
| 1117 |
+
export_md_btn.click(
|
| 1118 |
+
fn=export_markdown,
|
| 1119 |
+
inputs=[user_stories_output, features_output, tasks_output],
|
| 1120 |
+
outputs=[export_file]
|
| 1121 |
+
)
|
| 1122 |
+
|
| 1123 |
+
export_json_btn.click(
|
| 1124 |
+
fn=export_json,
|
| 1125 |
+
inputs=[user_stories_output, features_output, tasks_output],
|
| 1126 |
+
outputs=[export_file]
|
| 1127 |
+
)
|
| 1128 |
+
|
| 1129 |
+
return app
|
| 1130 |
+
|
| 1131 |
+
|
| 1132 |
+
# ============================================================================
|
| 1133 |
+
# MAIN ENTRY POINT
|
| 1134 |
+
# ============================================================================
|
| 1135 |
+
|
| 1136 |
+
if __name__ == "__main__":
|
| 1137 |
+
app = create_interface()
|
| 1138 |
+
app.launch(
|
| 1139 |
+
server_name="0.0.0.0",
|
| 1140 |
+
server_port=7860,
|
| 1141 |
+
share=False,
|
| 1142 |
+
show_error=True
|
| 1143 |
+
)
|
base_agents.py
ADDED
|
@@ -0,0 +1,525 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Base Agents Library for AI Project Planner
|
| 3 |
+
|
| 4 |
+
A collection of reusable AI agents for building agentic workflows.
|
| 5 |
+
Optimized for web deployment with proper error handling and logging.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from openai import OpenAI
|
| 9 |
+
import numpy as np
|
| 10 |
+
from typing import Dict, Any, List, Optional, Callable
|
| 11 |
+
import logging
|
| 12 |
+
|
| 13 |
+
# Configure logging
|
| 14 |
+
logging.basicConfig(level=logging.INFO)
|
| 15 |
+
logger = logging.getLogger(__name__)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class DirectPromptAgent:
|
| 19 |
+
"""
|
| 20 |
+
A Direct Prompt Agent that relays user input directly to the LLM
|
| 21 |
+
without additional context, memory, or specialized tools.
|
| 22 |
+
|
| 23 |
+
This is the most straightforward method for interacting with an LLM.
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
def __init__(self, openai_api_key: str, base_url: str = None):
|
| 27 |
+
"""
|
| 28 |
+
Initialize the DirectPromptAgent.
|
| 29 |
+
|
| 30 |
+
Args:
|
| 31 |
+
openai_api_key: The OpenAI API key for authentication.
|
| 32 |
+
base_url: Optional custom base URL for API calls.
|
| 33 |
+
"""
|
| 34 |
+
self.openai_api_key = openai_api_key
|
| 35 |
+
self.base_url = base_url
|
| 36 |
+
|
| 37 |
+
def _get_client(self) -> OpenAI:
|
| 38 |
+
"""Create and return an OpenAI client instance."""
|
| 39 |
+
if self.base_url:
|
| 40 |
+
return OpenAI(api_key=self.openai_api_key, base_url=self.base_url)
|
| 41 |
+
return OpenAI(api_key=self.openai_api_key)
|
| 42 |
+
|
| 43 |
+
def respond(self, prompt: str) -> str:
|
| 44 |
+
"""
|
| 45 |
+
Generate a response by passing the user prompt directly to the LLM.
|
| 46 |
+
|
| 47 |
+
Args:
|
| 48 |
+
prompt: The user's input prompt.
|
| 49 |
+
|
| 50 |
+
Returns:
|
| 51 |
+
The textual content of the LLM's response.
|
| 52 |
+
"""
|
| 53 |
+
try:
|
| 54 |
+
client = self._get_client()
|
| 55 |
+
|
| 56 |
+
response = client.chat.completions.create(
|
| 57 |
+
model="gpt-3.5-turbo",
|
| 58 |
+
messages=[
|
| 59 |
+
{"role": "user", "content": prompt}
|
| 60 |
+
],
|
| 61 |
+
temperature=0
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
return response.choices[0].message.content
|
| 65 |
+
|
| 66 |
+
except Exception as e:
|
| 67 |
+
logger.error(f"DirectPromptAgent error: {str(e)}")
|
| 68 |
+
raise
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
class AugmentedPromptAgent:
|
| 72 |
+
"""
|
| 73 |
+
An Augmented Prompt Agent that responds according to a predefined persona.
|
| 74 |
+
|
| 75 |
+
This agent explicitly adopts a persona via a system prompt, leading to
|
| 76 |
+
more targeted and contextually relevant outputs.
|
| 77 |
+
"""
|
| 78 |
+
|
| 79 |
+
def __init__(self, openai_api_key: str, persona: str, base_url: str = None):
|
| 80 |
+
"""
|
| 81 |
+
Initialize the AugmentedPromptAgent.
|
| 82 |
+
|
| 83 |
+
Args:
|
| 84 |
+
openai_api_key: The OpenAI API key for authentication.
|
| 85 |
+
persona: The persona the agent should assume.
|
| 86 |
+
base_url: Optional custom base URL for API calls.
|
| 87 |
+
"""
|
| 88 |
+
self.openai_api_key = openai_api_key
|
| 89 |
+
self.persona = persona
|
| 90 |
+
self.base_url = base_url
|
| 91 |
+
|
| 92 |
+
def _get_client(self) -> OpenAI:
|
| 93 |
+
"""Create and return an OpenAI client instance."""
|
| 94 |
+
if self.base_url:
|
| 95 |
+
return OpenAI(api_key=self.openai_api_key, base_url=self.base_url)
|
| 96 |
+
return OpenAI(api_key=self.openai_api_key)
|
| 97 |
+
|
| 98 |
+
def respond(self, input_text: str) -> str:
|
| 99 |
+
"""
|
| 100 |
+
Generate a response using the defined persona.
|
| 101 |
+
|
| 102 |
+
Args:
|
| 103 |
+
input_text: The user's input prompt.
|
| 104 |
+
|
| 105 |
+
Returns:
|
| 106 |
+
The textual content of the LLM's response.
|
| 107 |
+
"""
|
| 108 |
+
try:
|
| 109 |
+
client = self._get_client()
|
| 110 |
+
|
| 111 |
+
system_prompt = f"{self.persona} Forget all previous conversational context."
|
| 112 |
+
|
| 113 |
+
response = client.chat.completions.create(
|
| 114 |
+
model="gpt-3.5-turbo",
|
| 115 |
+
messages=[
|
| 116 |
+
{"role": "system", "content": system_prompt},
|
| 117 |
+
{"role": "user", "content": input_text}
|
| 118 |
+
],
|
| 119 |
+
temperature=1.0
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
return response.choices[0].message.content
|
| 123 |
+
|
| 124 |
+
except Exception as e:
|
| 125 |
+
logger.error(f"AugmentedPromptAgent error: {str(e)}")
|
| 126 |
+
raise
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
class KnowledgeAugmentedPromptAgent:
|
| 130 |
+
"""
|
| 131 |
+
A Knowledge Augmented Prompt Agent that incorporates specific knowledge
|
| 132 |
+
alongside a defined persona when responding to prompts.
|
| 133 |
+
|
| 134 |
+
This agent ensures answers are based on explicitly provided information
|
| 135 |
+
rather than the LLM's inherent knowledge.
|
| 136 |
+
"""
|
| 137 |
+
|
| 138 |
+
def __init__(
|
| 139 |
+
self,
|
| 140 |
+
openai_api_key: str,
|
| 141 |
+
persona: str,
|
| 142 |
+
knowledge: str,
|
| 143 |
+
base_url: str = None
|
| 144 |
+
):
|
| 145 |
+
"""
|
| 146 |
+
Initialize the KnowledgeAugmentedPromptAgent.
|
| 147 |
+
|
| 148 |
+
Args:
|
| 149 |
+
openai_api_key: The OpenAI API key for authentication.
|
| 150 |
+
persona: The persona the agent should assume.
|
| 151 |
+
knowledge: The specific knowledge to use for responses.
|
| 152 |
+
base_url: Optional custom base URL for API calls.
|
| 153 |
+
"""
|
| 154 |
+
self.openai_api_key = openai_api_key
|
| 155 |
+
self.persona = persona
|
| 156 |
+
self.knowledge = knowledge
|
| 157 |
+
self.base_url = base_url
|
| 158 |
+
|
| 159 |
+
def _get_client(self) -> OpenAI:
|
| 160 |
+
"""Create and return an OpenAI client instance."""
|
| 161 |
+
if self.base_url:
|
| 162 |
+
return OpenAI(api_key=self.openai_api_key, base_url=self.base_url)
|
| 163 |
+
return OpenAI(api_key=self.openai_api_key)
|
| 164 |
+
|
| 165 |
+
def respond(self, input_text: str) -> str:
|
| 166 |
+
"""
|
| 167 |
+
Generate a response using the persona and provided knowledge only.
|
| 168 |
+
|
| 169 |
+
Args:
|
| 170 |
+
input_text: The user's input prompt.
|
| 171 |
+
|
| 172 |
+
Returns:
|
| 173 |
+
The textual content of the LLM's response.
|
| 174 |
+
"""
|
| 175 |
+
try:
|
| 176 |
+
client = self._get_client()
|
| 177 |
+
|
| 178 |
+
system_prompt = (
|
| 179 |
+
f"You are {self.persona} knowledge-based assistant. Forget all previous context. "
|
| 180 |
+
f"Use only the following knowledge to answer, do not use your own knowledge: {self.knowledge} "
|
| 181 |
+
f"Answer the prompt based on this knowledge, not your own."
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
response = client.chat.completions.create(
|
| 185 |
+
model="gpt-3.5-turbo",
|
| 186 |
+
messages=[
|
| 187 |
+
{"role": "system", "content": system_prompt},
|
| 188 |
+
{"role": "user", "content": input_text}
|
| 189 |
+
],
|
| 190 |
+
temperature=0
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
return response.choices[0].message.content
|
| 194 |
+
|
| 195 |
+
except Exception as e:
|
| 196 |
+
logger.error(f"KnowledgeAugmentedPromptAgent error: {str(e)}")
|
| 197 |
+
raise
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
class EvaluationAgent:
|
| 201 |
+
"""
|
| 202 |
+
An Evaluation Agent that assesses responses from a worker agent
|
| 203 |
+
against given criteria, potentially refining through iterative feedback.
|
| 204 |
+
|
| 205 |
+
This agent implements a feedback loop to ensure quality outputs.
|
| 206 |
+
"""
|
| 207 |
+
|
| 208 |
+
def __init__(
|
| 209 |
+
self,
|
| 210 |
+
openai_api_key: str,
|
| 211 |
+
persona: str,
|
| 212 |
+
evaluation_criteria: str,
|
| 213 |
+
worker_agent: Any,
|
| 214 |
+
max_interactions: int = 10,
|
| 215 |
+
base_url: str = None
|
| 216 |
+
):
|
| 217 |
+
"""
|
| 218 |
+
Initialize the EvaluationAgent.
|
| 219 |
+
|
| 220 |
+
Args:
|
| 221 |
+
openai_api_key: The OpenAI API key for authentication.
|
| 222 |
+
persona: The evaluator's persona.
|
| 223 |
+
evaluation_criteria: Criteria for evaluating responses.
|
| 224 |
+
worker_agent: The agent whose responses will be evaluated.
|
| 225 |
+
max_interactions: Maximum refinement iterations.
|
| 226 |
+
base_url: Optional custom base URL for API calls.
|
| 227 |
+
"""
|
| 228 |
+
self.openai_api_key = openai_api_key
|
| 229 |
+
self.persona = persona
|
| 230 |
+
self.evaluation_criteria = evaluation_criteria
|
| 231 |
+
self.worker_agent = worker_agent
|
| 232 |
+
self.max_interactions = max_interactions
|
| 233 |
+
self.base_url = base_url
|
| 234 |
+
|
| 235 |
+
def _get_client(self) -> OpenAI:
|
| 236 |
+
"""Create and return an OpenAI client instance."""
|
| 237 |
+
if self.base_url:
|
| 238 |
+
return OpenAI(api_key=self.openai_api_key, base_url=self.base_url)
|
| 239 |
+
return OpenAI(api_key=self.openai_api_key)
|
| 240 |
+
|
| 241 |
+
def evaluate(self, prompt_to_evaluate: str) -> Dict[str, Any]:
|
| 242 |
+
"""
|
| 243 |
+
Evaluate and potentially refine a response through iteration.
|
| 244 |
+
|
| 245 |
+
Args:
|
| 246 |
+
prompt_to_evaluate: The initial prompt to evaluate.
|
| 247 |
+
|
| 248 |
+
Returns:
|
| 249 |
+
Dictionary containing final_response, evaluation, and iterations.
|
| 250 |
+
"""
|
| 251 |
+
try:
|
| 252 |
+
client = self._get_client()
|
| 253 |
+
initial_prompt = prompt_to_evaluate
|
| 254 |
+
response_from_worker = ""
|
| 255 |
+
evaluation = ""
|
| 256 |
+
|
| 257 |
+
for i in range(self.max_interactions):
|
| 258 |
+
logger.info(f"Evaluation iteration {i + 1}/{self.max_interactions}")
|
| 259 |
+
|
| 260 |
+
# Step 1: Get response from worker agent
|
| 261 |
+
response_from_worker = self.worker_agent.respond(prompt_to_evaluate)
|
| 262 |
+
|
| 263 |
+
# Step 2: Evaluate the response
|
| 264 |
+
eval_prompt = (
|
| 265 |
+
f"Does the following answer: {response_from_worker}\n"
|
| 266 |
+
f"Meet this criteria: {self.evaluation_criteria}\n"
|
| 267 |
+
f"Respond Yes or No, and the reason why it does or doesn't meet the criteria."
|
| 268 |
+
)
|
| 269 |
+
|
| 270 |
+
response = client.chat.completions.create(
|
| 271 |
+
model="gpt-3.5-turbo",
|
| 272 |
+
messages=[
|
| 273 |
+
{"role": "system", "content": self.persona},
|
| 274 |
+
{"role": "user", "content": eval_prompt}
|
| 275 |
+
],
|
| 276 |
+
temperature=0
|
| 277 |
+
)
|
| 278 |
+
|
| 279 |
+
evaluation = response.choices[0].message.content.strip()
|
| 280 |
+
|
| 281 |
+
# Step 3: Check if evaluation passes
|
| 282 |
+
if evaluation.lower().startswith("yes"):
|
| 283 |
+
logger.info("Evaluation passed!")
|
| 284 |
+
break
|
| 285 |
+
|
| 286 |
+
# Step 4: Generate correction instructions
|
| 287 |
+
instruction_prompt = (
|
| 288 |
+
f"Provide instructions to fix an answer based on these reasons "
|
| 289 |
+
f"why it is incorrect: {evaluation}"
|
| 290 |
+
)
|
| 291 |
+
|
| 292 |
+
response = client.chat.completions.create(
|
| 293 |
+
model="gpt-3.5-turbo",
|
| 294 |
+
messages=[
|
| 295 |
+
{"role": "system", "content": "You are a helpful assistant that provides clear correction instructions."},
|
| 296 |
+
{"role": "user", "content": instruction_prompt}
|
| 297 |
+
],
|
| 298 |
+
temperature=0
|
| 299 |
+
)
|
| 300 |
+
|
| 301 |
+
instructions = response.choices[0].message.content.strip()
|
| 302 |
+
|
| 303 |
+
# Step 5: Prepare refined prompt
|
| 304 |
+
prompt_to_evaluate = (
|
| 305 |
+
f"The original prompt was: {initial_prompt}\n"
|
| 306 |
+
f"The response to that prompt was: {response_from_worker}\n"
|
| 307 |
+
f"It has been evaluated as incorrect.\n"
|
| 308 |
+
f"Make only these corrections, do not alter content validity: {instructions}"
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
return {
|
| 312 |
+
"final_response": response_from_worker,
|
| 313 |
+
"evaluation": evaluation,
|
| 314 |
+
"iterations": i + 1
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
except Exception as e:
|
| 318 |
+
logger.error(f"EvaluationAgent error: {str(e)}")
|
| 319 |
+
raise
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
class RoutingAgent:
|
| 323 |
+
"""
|
| 324 |
+
A Routing Agent that directs user prompts to the most appropriate
|
| 325 |
+
specialized agent based on semantic similarity.
|
| 326 |
+
|
| 327 |
+
Uses embeddings to match prompts with agent descriptions.
|
| 328 |
+
"""
|
| 329 |
+
|
| 330 |
+
def __init__(
|
| 331 |
+
self,
|
| 332 |
+
openai_api_key: str,
|
| 333 |
+
agents: List[Dict[str, Any]],
|
| 334 |
+
base_url: str = None
|
| 335 |
+
):
|
| 336 |
+
"""
|
| 337 |
+
Initialize the RoutingAgent.
|
| 338 |
+
|
| 339 |
+
Args:
|
| 340 |
+
openai_api_key: The OpenAI API key for authentication.
|
| 341 |
+
agents: List of agent dictionaries with name, description, and func.
|
| 342 |
+
base_url: Optional custom base URL for API calls.
|
| 343 |
+
"""
|
| 344 |
+
self.openai_api_key = openai_api_key
|
| 345 |
+
self.agents = agents
|
| 346 |
+
self.base_url = base_url
|
| 347 |
+
self._embedding_cache = {}
|
| 348 |
+
|
| 349 |
+
def _get_client(self) -> OpenAI:
|
| 350 |
+
"""Create and return an OpenAI client instance."""
|
| 351 |
+
if self.base_url:
|
| 352 |
+
return OpenAI(api_key=self.openai_api_key, base_url=self.base_url)
|
| 353 |
+
return OpenAI(api_key=self.openai_api_key)
|
| 354 |
+
|
| 355 |
+
def get_embedding(self, text: str) -> List[float]:
|
| 356 |
+
"""
|
| 357 |
+
Calculate the embedding of text using the text-embedding-3-large model.
|
| 358 |
+
|
| 359 |
+
Args:
|
| 360 |
+
text: The text to embed.
|
| 361 |
+
|
| 362 |
+
Returns:
|
| 363 |
+
The embedding vector.
|
| 364 |
+
"""
|
| 365 |
+
# Check cache first
|
| 366 |
+
if text in self._embedding_cache:
|
| 367 |
+
return self._embedding_cache[text]
|
| 368 |
+
|
| 369 |
+
try:
|
| 370 |
+
client = self._get_client()
|
| 371 |
+
|
| 372 |
+
response = client.embeddings.create(
|
| 373 |
+
model="text-embedding-3-large",
|
| 374 |
+
input=text,
|
| 375 |
+
encoding_format="float"
|
| 376 |
+
)
|
| 377 |
+
|
| 378 |
+
embedding = response.data[0].embedding
|
| 379 |
+
self._embedding_cache[text] = embedding
|
| 380 |
+
|
| 381 |
+
return embedding
|
| 382 |
+
|
| 383 |
+
except Exception as e:
|
| 384 |
+
logger.error(f"Embedding error: {str(e)}")
|
| 385 |
+
raise
|
| 386 |
+
|
| 387 |
+
def route(self, user_input: str) -> Any:
|
| 388 |
+
"""
|
| 389 |
+
Route user prompts to the most appropriate agent based on similarity.
|
| 390 |
+
|
| 391 |
+
Args:
|
| 392 |
+
user_input: The user's input prompt.
|
| 393 |
+
|
| 394 |
+
Returns:
|
| 395 |
+
The response from the selected agent's function.
|
| 396 |
+
"""
|
| 397 |
+
try:
|
| 398 |
+
input_emb = self.get_embedding(user_input)
|
| 399 |
+
best_agent = None
|
| 400 |
+
best_score = -1
|
| 401 |
+
|
| 402 |
+
for agent in self.agents:
|
| 403 |
+
agent_emb = self.get_embedding(agent["description"])
|
| 404 |
+
|
| 405 |
+
if agent_emb is None:
|
| 406 |
+
continue
|
| 407 |
+
|
| 408 |
+
# Calculate cosine similarity
|
| 409 |
+
similarity = np.dot(input_emb, agent_emb) / (
|
| 410 |
+
np.linalg.norm(input_emb) * np.linalg.norm(agent_emb)
|
| 411 |
+
)
|
| 412 |
+
|
| 413 |
+
logger.info(f"Agent '{agent['name']}' similarity: {similarity:.3f}")
|
| 414 |
+
|
| 415 |
+
if similarity > best_score:
|
| 416 |
+
best_score = similarity
|
| 417 |
+
best_agent = agent
|
| 418 |
+
|
| 419 |
+
if best_agent is None:
|
| 420 |
+
return "Sorry, no suitable agent could be selected."
|
| 421 |
+
|
| 422 |
+
logger.info(f"Selected agent: {best_agent['name']} (score={best_score:.3f})")
|
| 423 |
+
|
| 424 |
+
return best_agent["func"](user_input)
|
| 425 |
+
|
| 426 |
+
except Exception as e:
|
| 427 |
+
logger.error(f"RoutingAgent error: {str(e)}")
|
| 428 |
+
raise
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
class ActionPlanningAgent:
|
| 432 |
+
"""
|
| 433 |
+
An Action Planning Agent that extracts and lists actionable steps
|
| 434 |
+
from a user's prompt based on provided knowledge.
|
| 435 |
+
|
| 436 |
+
Crucial for constructing agentic workflows by breaking down complex tasks.
|
| 437 |
+
"""
|
| 438 |
+
|
| 439 |
+
def __init__(
|
| 440 |
+
self,
|
| 441 |
+
openai_api_key: str,
|
| 442 |
+
knowledge: str,
|
| 443 |
+
base_url: str = None
|
| 444 |
+
):
|
| 445 |
+
"""
|
| 446 |
+
Initialize the ActionPlanningAgent.
|
| 447 |
+
|
| 448 |
+
Args:
|
| 449 |
+
openai_api_key: The OpenAI API key for authentication.
|
| 450 |
+
knowledge: The knowledge base for extracting action steps.
|
| 451 |
+
base_url: Optional custom base URL for API calls.
|
| 452 |
+
"""
|
| 453 |
+
self.openai_api_key = openai_api_key
|
| 454 |
+
self.knowledge = knowledge
|
| 455 |
+
self.base_url = base_url
|
| 456 |
+
|
| 457 |
+
def _get_client(self) -> OpenAI:
|
| 458 |
+
"""Create and return an OpenAI client instance."""
|
| 459 |
+
if self.base_url:
|
| 460 |
+
return OpenAI(api_key=self.openai_api_key, base_url=self.base_url)
|
| 461 |
+
return OpenAI(api_key=self.openai_api_key)
|
| 462 |
+
|
| 463 |
+
def extract_steps_from_prompt(self, prompt: str) -> List[str]:
|
| 464 |
+
"""
|
| 465 |
+
Extract actionable steps from a user prompt using provided knowledge.
|
| 466 |
+
|
| 467 |
+
Args:
|
| 468 |
+
prompt: The user's input prompt describing a task.
|
| 469 |
+
|
| 470 |
+
Returns:
|
| 471 |
+
A clean list of action steps.
|
| 472 |
+
"""
|
| 473 |
+
try:
|
| 474 |
+
client = self._get_client()
|
| 475 |
+
|
| 476 |
+
system_prompt = (
|
| 477 |
+
f"You are an action planning agent. Using your knowledge, you extract from the user prompt "
|
| 478 |
+
f"the steps requested to complete the action the user is asking for. You return the steps as a list. "
|
| 479 |
+
f"Only return the steps in your knowledge. Forget any previous context. "
|
| 480 |
+
f"This is your knowledge: {self.knowledge}"
|
| 481 |
+
)
|
| 482 |
+
|
| 483 |
+
response = client.chat.completions.create(
|
| 484 |
+
model="gpt-3.5-turbo",
|
| 485 |
+
messages=[
|
| 486 |
+
{"role": "system", "content": system_prompt},
|
| 487 |
+
{"role": "user", "content": prompt}
|
| 488 |
+
],
|
| 489 |
+
temperature=0
|
| 490 |
+
)
|
| 491 |
+
|
| 492 |
+
response_text = response.choices[0].message.content
|
| 493 |
+
|
| 494 |
+
# Clean and format the extracted steps
|
| 495 |
+
steps = response_text.split("\n")
|
| 496 |
+
cleaned_steps = [step.strip() for step in steps if step.strip()]
|
| 497 |
+
|
| 498 |
+
logger.info(f"Extracted {len(cleaned_steps)} action steps")
|
| 499 |
+
|
| 500 |
+
return cleaned_steps
|
| 501 |
+
|
| 502 |
+
except Exception as e:
|
| 503 |
+
logger.error(f"ActionPlanningAgent error: {str(e)}")
|
| 504 |
+
raise
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
# ============================================================================
|
| 508 |
+
# UTILITY FUNCTIONS
|
| 509 |
+
# ============================================================================
|
| 510 |
+
|
| 511 |
+
def cosine_similarity(vec1: List[float], vec2: List[float]) -> float:
|
| 512 |
+
"""
|
| 513 |
+
Calculate cosine similarity between two vectors.
|
| 514 |
+
|
| 515 |
+
Args:
|
| 516 |
+
vec1: First vector.
|
| 517 |
+
vec2: Second vector.
|
| 518 |
+
|
| 519 |
+
Returns:
|
| 520 |
+
Cosine similarity score between 0 and 1.
|
| 521 |
+
"""
|
| 522 |
+
vec1 = np.array(vec1)
|
| 523 |
+
vec2 = np.array(vec2)
|
| 524 |
+
|
| 525 |
+
return np.dot(vec1, vec2) / (np.linalg.norm(vec1) * np.linalg.norm(vec2))
|
requirements.txt
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AI Project Planner - Dependencies
|
| 2 |
+
# For Hugging Face Spaces deployment
|
| 3 |
+
|
| 4 |
+
# Core Framework
|
| 5 |
+
gradio>=4.0.0
|
| 6 |
+
|
| 7 |
+
# OpenAI API
|
| 8 |
+
openai>=1.0.0
|
| 9 |
+
|
| 10 |
+
# Data Processing
|
| 11 |
+
numpy>=1.24.0
|
| 12 |
+
|
| 13 |
+
# Environment Management
|
| 14 |
+
python-dotenv>=1.0.0
|