Spaces:
Running
Running
Commit
·
18efc55
1
Parent(s):
52c4f6d
Add environment configuration template, enhance .gitignore, and refactor configuration loading. Removed deprecated scripts and improved setup process with a new setup script.
Browse files- .env.example +93 -0
- .gitignore +84 -3
- README.md +130 -9
- agentgraph/input/parsers/demo.py +0 -158
- agentgraph/methods/production/openai_structured_extractor.py +2 -5
- agentgraph/reconstruction/example_rag_usage.py +0 -100
- backend/services/platform/langfuse_downloader.py +6 -8
- debug_env.py +0 -185
- deploy.sh +0 -0
- extraction_analysis/cot_extraction_20250909_172744_855dfc94.json +0 -139
- frontend/Dockerfile.dev +0 -18
- main.py +28 -20
- pyproject.toml +0 -4
- setup.sh +213 -0
- utils/config.py +75 -6
.env.example
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AgentGraph Environment Configuration Template
|
| 2 |
+
# Copy this file to .env and fill in your actual values
|
| 3 |
+
|
| 4 |
+
# =============================================================================
|
| 5 |
+
# 🔑 REQUIRED CONFIGURATION
|
| 6 |
+
# =============================================================================
|
| 7 |
+
|
| 8 |
+
# OpenAI API Configuration (REQUIRED for knowledge extraction)
|
| 9 |
+
OPENAI_API_KEY=sk-your-openai-api-key-here
|
| 10 |
+
OPENAI_MODEL_NAME=gpt-4o-mini
|
| 11 |
+
|
| 12 |
+
# =============================================================================
|
| 13 |
+
# 🔧 OPTIONAL CONFIGURATION
|
| 14 |
+
# =============================================================================
|
| 15 |
+
|
| 16 |
+
# Azure OpenAI Configuration (Alternative to OpenAI)
|
| 17 |
+
# Uncomment and configure if using Azure OpenAI instead
|
| 18 |
+
# AZURE_API_KEY=your-azure-api-key
|
| 19 |
+
# AZURE_API_BASE=https://your-resource.openai.azure.com/
|
| 20 |
+
# AZURE_API_VERSION=2023-12-01-preview
|
| 21 |
+
|
| 22 |
+
# Anthropic Configuration (Optional)
|
| 23 |
+
# ANTHROPIC_API_KEY=your-anthropic-api-key
|
| 24 |
+
|
| 25 |
+
# =============================================================================
|
| 26 |
+
# 📊 AI OBSERVABILITY PLATFORMS
|
| 27 |
+
# =============================================================================
|
| 28 |
+
|
| 29 |
+
# Langfuse Configuration (Optional - for AI monitoring)
|
| 30 |
+
# LANGFUSE_PUBLIC_KEY=pk_lf_your-public-key
|
| 31 |
+
# LANGFUSE_SECRET_KEY=sk_lf_your-secret-key
|
| 32 |
+
# LANGFUSE_HOST=https://cloud.langfuse.com
|
| 33 |
+
|
| 34 |
+
# LangSmith Configuration (Optional - for trace monitoring)
|
| 35 |
+
# LANGSMITH_API_KEY=your-langsmith-api-key
|
| 36 |
+
# LANGSMITH_PROJECT=your-project-name
|
| 37 |
+
|
| 38 |
+
# =============================================================================
|
| 39 |
+
# 🗄️ DATABASE CONFIGURATION
|
| 40 |
+
# =============================================================================
|
| 41 |
+
|
| 42 |
+
# Database URI (SQLite by default, can use PostgreSQL/MySQL)
|
| 43 |
+
DB_URI=sqlite:///agent_monitoring.db
|
| 44 |
+
|
| 45 |
+
# PostgreSQL Example:
|
| 46 |
+
# DB_URI=postgresql://username:password@localhost:5432/agentgraph
|
| 47 |
+
|
| 48 |
+
# MySQL Example:
|
| 49 |
+
# DB_URI=mysql://username:password@localhost:3306/agentgraph
|
| 50 |
+
|
| 51 |
+
# =============================================================================
|
| 52 |
+
# 🚀 SERVER CONFIGURATION
|
| 53 |
+
# =============================================================================
|
| 54 |
+
|
| 55 |
+
# Server Settings
|
| 56 |
+
HOST=0.0.0.0
|
| 57 |
+
PORT=7860
|
| 58 |
+
LOG_LEVEL=INFO
|
| 59 |
+
|
| 60 |
+
# Python Path (usually set automatically)
|
| 61 |
+
PYTHONPATH=/app
|
| 62 |
+
|
| 63 |
+
# =============================================================================
|
| 64 |
+
# 🔒 SECURITY CONFIGURATION
|
| 65 |
+
# =============================================================================
|
| 66 |
+
|
| 67 |
+
# Encryption key for storing sensitive data (auto-generated if not set)
|
| 68 |
+
# ENCRYPTION_KEY=your-32-character-encryption-key
|
| 69 |
+
|
| 70 |
+
# =============================================================================
|
| 71 |
+
# 🧪 DEVELOPMENT CONFIGURATION
|
| 72 |
+
# =============================================================================
|
| 73 |
+
|
| 74 |
+
# Development mode settings
|
| 75 |
+
# DEBUG=false
|
| 76 |
+
# RELOAD=false
|
| 77 |
+
|
| 78 |
+
# =============================================================================
|
| 79 |
+
# 📈 PERFORMANCE CONFIGURATION
|
| 80 |
+
# =============================================================================
|
| 81 |
+
|
| 82 |
+
# Processing settings
|
| 83 |
+
# MAX_WORKERS=4
|
| 84 |
+
# BATCH_SIZE=10
|
| 85 |
+
# TIMEOUT_SECONDS=300
|
| 86 |
+
|
| 87 |
+
# =============================================================================
|
| 88 |
+
# 🌐 HUGGING FACE SPACES CONFIGURATION
|
| 89 |
+
# =============================================================================
|
| 90 |
+
|
| 91 |
+
# If deploying to Hugging Face Spaces, these are automatically set:
|
| 92 |
+
# SPACE_ID=your-username/space-name
|
| 93 |
+
# SPACE_HOST=https://your-username-space-name.hf.space
|
.gitignore
CHANGED
|
@@ -1,13 +1,94 @@
|
|
|
|
|
| 1 |
__pycache__/
|
| 2 |
*.py[cod]
|
| 3 |
*.class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
logs/
|
| 5 |
*.log
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
datasets/db/
|
| 7 |
datasets/knowledge_graphs/
|
| 8 |
datasets/test_results/
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# Allow example_traces data for Gallery
|
| 10 |
!datasets/example_traces/
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
__pycache__/
|
| 3 |
*.py[cod]
|
| 4 |
*.class
|
| 5 |
+
*.so
|
| 6 |
+
.Python
|
| 7 |
+
build/
|
| 8 |
+
develop-eggs/
|
| 9 |
+
dist/
|
| 10 |
+
downloads/
|
| 11 |
+
eggs/
|
| 12 |
+
.eggs/
|
| 13 |
+
lib/
|
| 14 |
+
lib64/
|
| 15 |
+
parts/
|
| 16 |
+
sdist/
|
| 17 |
+
var/
|
| 18 |
+
wheels/
|
| 19 |
+
*.egg-info/
|
| 20 |
+
.installed.cfg
|
| 21 |
+
*.egg
|
| 22 |
+
|
| 23 |
+
# Environment and configuration
|
| 24 |
+
.env
|
| 25 |
+
.env.local
|
| 26 |
+
.env.*.local
|
| 27 |
+
*.envrc
|
| 28 |
+
|
| 29 |
+
# Logs and temporary files
|
| 30 |
logs/
|
| 31 |
*.log
|
| 32 |
+
.DS_Store
|
| 33 |
+
Thumbs.db
|
| 34 |
+
|
| 35 |
+
# Database and cache files
|
| 36 |
+
db/
|
| 37 |
+
cache/
|
| 38 |
+
*.db
|
| 39 |
+
*.sqlite
|
| 40 |
+
*.sqlite3
|
| 41 |
+
|
| 42 |
+
# Analysis and test results
|
| 43 |
+
evaluation_results/
|
| 44 |
+
extraction_analysis/
|
| 45 |
datasets/db/
|
| 46 |
datasets/knowledge_graphs/
|
| 47 |
datasets/test_results/
|
| 48 |
+
test_output/
|
| 49 |
+
*.analysis.json
|
| 50 |
+
*_extraction_*.json
|
| 51 |
+
|
| 52 |
# Allow example_traces data for Gallery
|
| 53 |
!datasets/example_traces/
|
| 54 |
+
|
| 55 |
+
# IDE and editor files
|
| 56 |
+
.vscode/
|
| 57 |
+
.idea/
|
| 58 |
+
*.swp
|
| 59 |
+
*.swo
|
| 60 |
+
*~
|
| 61 |
+
.project
|
| 62 |
+
.pydevproject
|
| 63 |
+
|
| 64 |
+
# OS generated files
|
| 65 |
+
.DS_Store
|
| 66 |
+
.DS_Store?
|
| 67 |
+
._*
|
| 68 |
+
.Spotlight-V100
|
| 69 |
+
.Trashes
|
| 70 |
+
ehthumbs.db
|
| 71 |
+
Thumbs.db
|
| 72 |
+
|
| 73 |
+
# Docker and deployment
|
| 74 |
+
.dockerignore
|
| 75 |
+
docker-compose.override.yml
|
| 76 |
+
|
| 77 |
+
# Node.js (frontend)
|
| 78 |
+
node_modules/
|
| 79 |
+
npm-debug.log*
|
| 80 |
+
yarn-debug.log*
|
| 81 |
+
yarn-error.log*
|
| 82 |
+
.npm
|
| 83 |
+
.yarn-integrity
|
| 84 |
+
|
| 85 |
+
# Frontend build outputs
|
| 86 |
+
frontend/dist/
|
| 87 |
+
frontend/build/
|
| 88 |
+
|
| 89 |
+
# Temporary development files
|
| 90 |
+
temp/
|
| 91 |
+
tmp/
|
| 92 |
+
*.tmp
|
| 93 |
+
*.bak
|
| 94 |
+
*.backup
|
README.md
CHANGED
|
@@ -13,26 +13,147 @@ app_port: 7860
|
|
| 13 |
|
| 14 |
A comprehensive agent monitoring and knowledge graph extraction system for understanding AI agent behavior and decision-making processes.
|
| 15 |
|
| 16 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
- 📊 **Real-time Agent Monitoring**: Track agent behavior and performance metrics
|
| 19 |
- 🕸️ **Knowledge Graph Extraction**: Extract and visualize knowledge graphs from agent traces
|
| 20 |
- 📈 **Interactive Dashboards**: Comprehensive monitoring and analytics interface
|
| 21 |
- 🔄 **Trace Analysis**: Analyze agent execution flows and decision patterns
|
| 22 |
- 🎨 **Graph Visualization**: Beautiful interactive knowledge graph visualizations
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
##
|
| 25 |
|
| 26 |
-
|
| 27 |
-
2. **Extract Knowledge**: Automatically generate knowledge graphs
|
| 28 |
-
3. **Analyze & Visualize**: Explore graphs and patterns
|
| 29 |
-
4. **Monitor Performance**: Track system health and metrics
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
- **Frontend**: React + TypeScript + Vite
|
| 35 |
- **Knowledge Extraction**: Multi-agent CrewAI system
|
| 36 |
-
- **Visualization**:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
Built with ❤️ for AI agent research and monitoring.
|
|
|
|
| 13 |
|
| 14 |
A comprehensive agent monitoring and knowledge graph extraction system for understanding AI agent behavior and decision-making processes.
|
| 15 |
|
| 16 |
+
## 🚀 Quick Start
|
| 17 |
+
|
| 18 |
+
### Option 1: Automated Setup (Recommended)
|
| 19 |
+
|
| 20 |
+
The easiest way to get started is using our setup script:
|
| 21 |
+
|
| 22 |
+
```bash
|
| 23 |
+
# 1. Clone the repository
|
| 24 |
+
git clone <repository-url>
|
| 25 |
+
cd AgentGraph
|
| 26 |
+
|
| 27 |
+
# 2. Run the setup script
|
| 28 |
+
./setup.sh
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
The script will:
|
| 32 |
+
|
| 33 |
+
- Guide you through environment configuration
|
| 34 |
+
- Prompt for your OpenAI API key
|
| 35 |
+
- Choose between Docker or local development setup
|
| 36 |
+
- Automatically handle all dependencies and services
|
| 37 |
+
|
| 38 |
+
### Option 2: Manual Docker Setup
|
| 39 |
+
|
| 40 |
+
If you prefer manual control:
|
| 41 |
+
|
| 42 |
+
```bash
|
| 43 |
+
# 1. Clone and setup environment
|
| 44 |
+
git clone <repository-url>
|
| 45 |
+
cd AgentGraph
|
| 46 |
+
cp .env.example .env
|
| 47 |
+
# Edit .env and add your OpenAI API key
|
| 48 |
+
|
| 49 |
+
# 2. Build and run with Docker
|
| 50 |
+
docker build -t agentgraph .
|
| 51 |
+
docker run -d --name agentgraph-app -p 7860:7860 --env-file .env agentgraph
|
| 52 |
+
|
| 53 |
+
# 3. Access the application
|
| 54 |
+
open http://localhost:7860
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
### Option 3: Local Development
|
| 58 |
+
|
| 59 |
+
For development work:
|
| 60 |
+
|
| 61 |
+
```bash
|
| 62 |
+
# 1. Setup environment
|
| 63 |
+
cp .env.example .env
|
| 64 |
+
# Edit .env with your API keys
|
| 65 |
+
|
| 66 |
+
# 2. Quick setup (installs dependencies and starts development server)
|
| 67 |
+
python main.py --first-run
|
| 68 |
+
|
| 69 |
+
# Or step by step:
|
| 70 |
+
python main.py --setup # Set up environment
|
| 71 |
+
python main.py --init-db # Initialize database
|
| 72 |
+
python main.py --dev # Start development servers
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
## 🔧 Configuration
|
| 76 |
+
|
| 77 |
+
### Required Environment Variables
|
| 78 |
+
|
| 79 |
+
- `OPENAI_API_KEY`: Your OpenAI API key (required for knowledge extraction)
|
| 80 |
+
|
| 81 |
+
### Optional Environment Variables
|
| 82 |
+
|
| 83 |
+
- `LANGFUSE_PUBLIC_KEY` / `LANGFUSE_SECRET_KEY`: For AI monitoring integration
|
| 84 |
+
- `OPENAI_MODEL_NAME`: Model to use (default: gpt-4o-mini)
|
| 85 |
+
- `DB_URI`: Database connection string (default: SQLite)
|
| 86 |
+
|
| 87 |
+
See `.env.example` for all available configuration options.
|
| 88 |
+
|
| 89 |
+
## 📋 Features
|
| 90 |
|
| 91 |
- 📊 **Real-time Agent Monitoring**: Track agent behavior and performance metrics
|
| 92 |
- 🕸️ **Knowledge Graph Extraction**: Extract and visualize knowledge graphs from agent traces
|
| 93 |
- 📈 **Interactive Dashboards**: Comprehensive monitoring and analytics interface
|
| 94 |
- 🔄 **Trace Analysis**: Analyze agent execution flows and decision patterns
|
| 95 |
- 🎨 **Graph Visualization**: Beautiful interactive knowledge graph visualizations
|
| 96 |
+
- 🔬 **Causal Analysis**: Advanced causal inference and component analysis
|
| 97 |
+
- 🧪 **Perturbation Testing**: Security and robustness evaluation
|
| 98 |
+
- 🔗 **Platform Integration**: Connect to LangSmith, Langfuse, and other monitoring platforms
|
| 99 |
|
| 100 |
+
## 🏗️ Architecture
|
| 101 |
|
| 102 |
+
AgentGraph follows a 5-stage pipeline architecture:
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
+
1. **Input Processing**: Trace upload, analysis, and chunking
|
| 105 |
+
2. **Knowledge Extraction**: Multi-agent CrewAI-based extraction
|
| 106 |
+
3. **Prompt Reconstruction**: Template extraction and context resolution
|
| 107 |
+
4. **Perturbation Testing**: Robustness and security evaluation
|
| 108 |
+
5. **Causal Analysis**: Causal inference and relationship analysis
|
| 109 |
|
| 110 |
+
## 🛠️ Technology Stack
|
| 111 |
+
|
| 112 |
+
- **Backend**: FastAPI + Python 3.11+
|
| 113 |
- **Frontend**: React + TypeScript + Vite
|
| 114 |
- **Knowledge Extraction**: Multi-agent CrewAI system
|
| 115 |
+
- **Visualization**: Cytoscape, D3.js, React Force Graph
|
| 116 |
+
- **AI Integration**: OpenAI, LiteLLM, Langfuse, LangSmith
|
| 117 |
+
- **Database**: SQLAlchemy (SQLite/PostgreSQL/MySQL)
|
| 118 |
+
- **Deployment**: Docker, Hugging Face Spaces ready
|
| 119 |
+
|
| 120 |
+
## 📖 Usage
|
| 121 |
+
|
| 122 |
+
1. **Upload Traces**: Import agent execution traces in various formats
|
| 123 |
+
2. **Configure Processing**: Choose extraction methods and parameters
|
| 124 |
+
3. **Extract Knowledge**: Automatically generate knowledge graphs
|
| 125 |
+
4. **Analyze & Visualize**: Explore graphs, relationships, and patterns
|
| 126 |
+
5. **Test Robustness**: Run perturbation tests and security evaluations
|
| 127 |
+
6. **Causal Analysis**: Understand causal relationships and component influences
|
| 128 |
+
|
| 129 |
+
## 🐛 Troubleshooting
|
| 130 |
+
|
| 131 |
+
### Environment Variable Issues
|
| 132 |
+
|
| 133 |
+
If you see "Invalid API key" errors:
|
| 134 |
+
|
| 135 |
+
```bash
|
| 136 |
+
# Check your configuration
|
| 137 |
+
python -c "from utils.config import debug_config; debug_config()"
|
| 138 |
+
|
| 139 |
+
# Restart Docker container after updating .env
|
| 140 |
+
docker restart agentgraph-app
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
### Common Issues
|
| 144 |
+
|
| 145 |
+
- **Missing Dependencies**: Run `python main.py --first-run` for automatic setup
|
| 146 |
+
- **Port Conflicts**: Change the port with `--port 8080`
|
| 147 |
+
- **API Key Problems**: Ensure your `.env` file has the correct format (no quotes or extra spaces)
|
| 148 |
+
|
| 149 |
+
## 🤝 Contributing
|
| 150 |
+
|
| 151 |
+
We welcome contributions! Please see our contributing guidelines for details.
|
| 152 |
+
|
| 153 |
+
## 📄 License
|
| 154 |
+
|
| 155 |
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
| 156 |
+
|
| 157 |
+
---
|
| 158 |
|
| 159 |
Built with ❤️ for AI agent research and monitoring.
|
agentgraph/input/parsers/demo.py
DELETED
|
@@ -1,158 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
Demo Script for LangSmith Parser System
|
| 4 |
-
|
| 5 |
-
This script demonstrates how the rule-based parser system automatically detects
|
| 6 |
-
trace sources and injects appropriate context documents to enhance knowledge
|
| 7 |
-
extraction.
|
| 8 |
-
|
| 9 |
-
Usage:
|
| 10 |
-
python demo.py [--trace-file path/to/trace.json]
|
| 11 |
-
"""
|
| 12 |
-
|
| 13 |
-
import sys
|
| 14 |
-
import json
|
| 15 |
-
import logging
|
| 16 |
-
from pathlib import Path
|
| 17 |
-
|
| 18 |
-
# Add project root to path for imports
|
| 19 |
-
project_root = Path(__file__).parent.parent.parent.parent
|
| 20 |
-
sys.path.insert(0, str(project_root))
|
| 21 |
-
|
| 22 |
-
from agentgraph.input.parsers import (
|
| 23 |
-
detect_trace_source,
|
| 24 |
-
parse_trace_with_context,
|
| 25 |
-
get_context_documents_for_source,
|
| 26 |
-
create_parser
|
| 27 |
-
)
|
| 28 |
-
|
| 29 |
-
# Setup logging
|
| 30 |
-
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
|
| 31 |
-
logger = logging.getLogger(__name__)
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
def demo_langsmith_detection():
|
| 35 |
-
"""Demonstrate LangSmith trace detection and parsing"""
|
| 36 |
-
|
| 37 |
-
print("🔍 Demo: LangSmith Trace Detection & Parsing")
|
| 38 |
-
print("=" * 50)
|
| 39 |
-
|
| 40 |
-
# Sample LangSmith trace structure (placeholder)
|
| 41 |
-
sample_langsmith_trace = {
|
| 42 |
-
"run_id": "12345678-1234-1234-1234-123456789012",
|
| 43 |
-
"project_name": "My Agent Project",
|
| 44 |
-
"trace_id": "trace_123",
|
| 45 |
-
"export_timestamp": "2025-01-15T10:30:00Z",
|
| 46 |
-
"total_traces": 3,
|
| 47 |
-
"traces": [
|
| 48 |
-
{
|
| 49 |
-
"run_type": "llm",
|
| 50 |
-
"name": "ChatBot Agent",
|
| 51 |
-
"inputs": {"messages": [{"role": "user", "content": "Hello"}]},
|
| 52 |
-
"outputs": {"content": "Hi there!"},
|
| 53 |
-
"start_time": "2025-01-15T10:30:01Z",
|
| 54 |
-
"end_time": "2025-01-15T10:30:02Z"
|
| 55 |
-
},
|
| 56 |
-
{
|
| 57 |
-
"run_type": "tool",
|
| 58 |
-
"name": "web_search",
|
| 59 |
-
"inputs": {"query": "weather today"},
|
| 60 |
-
"outputs": {"results": []},
|
| 61 |
-
"start_time": "2025-01-15T10:30:03Z",
|
| 62 |
-
"end_time": "2025-01-15T10:30:04Z"
|
| 63 |
-
},
|
| 64 |
-
{
|
| 65 |
-
"run_type": "chain",
|
| 66 |
-
"name": "Response Generator",
|
| 67 |
-
"inputs": {"context": "weather data"},
|
| 68 |
-
"outputs": {"response": "Today is sunny"},
|
| 69 |
-
"start_time": "2025-01-15T10:30:05Z",
|
| 70 |
-
"end_time": "2025-01-15T10:30:06Z"
|
| 71 |
-
}
|
| 72 |
-
]
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
trace_content = json.dumps(sample_langsmith_trace, indent=2)
|
| 76 |
-
trace_metadata = {
|
| 77 |
-
"platform": "langsmith",
|
| 78 |
-
"processing_type": "langsmith_processed_import"
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
print("1. 🎯 Source Detection")
|
| 82 |
-
detected_source = detect_trace_source(trace_content, trace_metadata)
|
| 83 |
-
print(f" Detected platform: {detected_source}")
|
| 84 |
-
|
| 85 |
-
print("\n2. 🏗️ Parser Creation")
|
| 86 |
-
parser = create_parser(detected_source)
|
| 87 |
-
if parser:
|
| 88 |
-
print(f" Created parser: {parser.__class__.__name__}")
|
| 89 |
-
print(f" Supported types: {parser.supported_trace_types}")
|
| 90 |
-
else:
|
| 91 |
-
print(" No parser available")
|
| 92 |
-
return
|
| 93 |
-
|
| 94 |
-
print("\n3. 📋 Context Document Generation")
|
| 95 |
-
context_docs = get_context_documents_for_source(detected_source)
|
| 96 |
-
print(f" Generated {len(context_docs)} context documents:")
|
| 97 |
-
for i, doc in enumerate(context_docs, 1):
|
| 98 |
-
print(f" {i}. {doc['document_type']}: {doc['title']}")
|
| 99 |
-
|
| 100 |
-
print("\n4. 🔄 Full Parsing with Context")
|
| 101 |
-
parsed_metadata, enhanced_context = parse_trace_with_context(trace_content, trace_metadata)
|
| 102 |
-
|
| 103 |
-
if parsed_metadata:
|
| 104 |
-
print(f" Platform: {parsed_metadata.platform}")
|
| 105 |
-
print(f" Confidence: {parsed_metadata.confidence:.2f}")
|
| 106 |
-
print(f" Agents found: {len(parsed_metadata.agents)}")
|
| 107 |
-
print(f" Tools found: {len(parsed_metadata.tools)}")
|
| 108 |
-
if parsed_metadata.workflow:
|
| 109 |
-
print(f" Project: {parsed_metadata.workflow.project_name}")
|
| 110 |
-
|
| 111 |
-
print(f" Enhanced context: {len(enhanced_context)} documents")
|
| 112 |
-
|
| 113 |
-
print("\n✅ Demo complete - The parser system is ready!")
|
| 114 |
-
print("\nNext steps:")
|
| 115 |
-
print("1. Implement actual LangSmith parsing logic in langsmith_parser.py")
|
| 116 |
-
print("2. Add more specific context documents based on detected patterns")
|
| 117 |
-
print("3. Enhance the knowledge extractor to use parsed metadata")
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
def demo_integration_flow():
|
| 121 |
-
"""Demonstrate how the parser integrates with the knowledge extraction flow"""
|
| 122 |
-
|
| 123 |
-
print("\n🚀 Integration Flow Demo")
|
| 124 |
-
print("=" * 50)
|
| 125 |
-
|
| 126 |
-
print("The parser system integrates automatically:")
|
| 127 |
-
print("1. 📥 Trace imported from LangSmith via observability connection")
|
| 128 |
-
print("2. 🔍 SlidingWindowMonitor detects trace source automatically")
|
| 129 |
-
print("3. 📋 Platform-specific context documents injected")
|
| 130 |
-
print("4. 🧠 Multi-agent knowledge extractor uses enhanced context")
|
| 131 |
-
print("5. 📊 Better extraction results with platform knowledge")
|
| 132 |
-
|
| 133 |
-
print("\nKey benefits:")
|
| 134 |
-
print("✓ Zero configuration required")
|
| 135 |
-
print("✓ Automatic platform detection")
|
| 136 |
-
print("✓ Structured metadata extraction")
|
| 137 |
-
print("✓ Context-aware knowledge extraction")
|
| 138 |
-
print("✓ Extensible to new platforms")
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
def main():
|
| 142 |
-
"""Run the demo"""
|
| 143 |
-
print("🎭 LangSmith Parser System Demo")
|
| 144 |
-
print("=" * 60)
|
| 145 |
-
|
| 146 |
-
try:
|
| 147 |
-
demo_langsmith_detection()
|
| 148 |
-
demo_integration_flow()
|
| 149 |
-
|
| 150 |
-
except Exception as e:
|
| 151 |
-
logger.error(f"Demo failed: {e}")
|
| 152 |
-
return 1
|
| 153 |
-
|
| 154 |
-
return 0
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
if __name__ == "__main__":
|
| 158 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
agentgraph/methods/production/openai_structured_extractor.py
CHANGED
|
@@ -12,7 +12,7 @@ import logging
|
|
| 12 |
from typing import Optional, List, Dict, Any
|
| 13 |
import uuid
|
| 14 |
from datetime import datetime
|
| 15 |
-
from
|
| 16 |
from openai import OpenAI
|
| 17 |
from pydantic import BaseModel
|
| 18 |
|
|
@@ -28,9 +28,6 @@ class KnowledgeGraphReasoning(BaseModel):
|
|
| 28 |
steps: List[Step]
|
| 29 |
final_answer: KnowledgeGraph
|
| 30 |
|
| 31 |
-
# Load environment variables (searches current directory and parents)
|
| 32 |
-
load_dotenv()
|
| 33 |
-
|
| 34 |
# Configure logging
|
| 35 |
logger = logging.getLogger(__name__)
|
| 36 |
|
|
@@ -48,7 +45,7 @@ class OpenAIStructuredExtractor:
|
|
| 48 |
model: OpenAI model to use (must support structured outputs)
|
| 49 |
"""
|
| 50 |
self.model = model
|
| 51 |
-
self.client = OpenAI(api_key=
|
| 52 |
logger.info(f"OpenAI Structured Extractor initialized with model: {model}")
|
| 53 |
|
| 54 |
def extract_knowledge_graph(self, input_data: str, context_documents: Optional[List[Dict[str, Any]]] = None) -> KnowledgeGraph:
|
|
|
|
| 12 |
from typing import Optional, List, Dict, Any
|
| 13 |
import uuid
|
| 14 |
from datetime import datetime
|
| 15 |
+
from utils.config import OPENAI_API_KEY, OPENAI_MODEL_NAME
|
| 16 |
from openai import OpenAI
|
| 17 |
from pydantic import BaseModel
|
| 18 |
|
|
|
|
| 28 |
steps: List[Step]
|
| 29 |
final_answer: KnowledgeGraph
|
| 30 |
|
|
|
|
|
|
|
|
|
|
| 31 |
# Configure logging
|
| 32 |
logger = logging.getLogger(__name__)
|
| 33 |
|
|
|
|
| 45 |
model: OpenAI model to use (must support structured outputs)
|
| 46 |
"""
|
| 47 |
self.model = model
|
| 48 |
+
self.client = OpenAI(api_key=OPENAI_API_KEY)
|
| 49 |
logger.info(f"OpenAI Structured Extractor initialized with model: {model}")
|
| 50 |
|
| 51 |
def extract_knowledge_graph(self, input_data: str, context_documents: Optional[List[Dict[str, Any]]] = None) -> KnowledgeGraph:
|
agentgraph/reconstruction/example_rag_usage.py
DELETED
|
@@ -1,100 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
Example usage of the RAG-based Prompt Reconstructor
|
| 4 |
-
|
| 5 |
-
This example demonstrates how to use the new RAG-based reconstruction method
|
| 6 |
-
as an alternative to the traditional content reference approach.
|
| 7 |
-
"""
|
| 8 |
-
|
| 9 |
-
from agentgraph.reconstruction import (
|
| 10 |
-
reconstruct_prompts_from_knowledge_graph_rag,
|
| 11 |
-
enrich_knowledge_graph_with_prompts_rag,
|
| 12 |
-
RagPromptReconstructor
|
| 13 |
-
)
|
| 14 |
-
|
| 15 |
-
def example_usage():
|
| 16 |
-
"""Example of how to use the RAG-based prompt reconstructor."""
|
| 17 |
-
|
| 18 |
-
# Sample knowledge graph data
|
| 19 |
-
knowledge_graph = {
|
| 20 |
-
"entities": [
|
| 21 |
-
{
|
| 22 |
-
"id": "user_001",
|
| 23 |
-
"name": "User inquiry about document loader",
|
| 24 |
-
"type": "Input",
|
| 25 |
-
"raw_prompt": "What is a document loader?"
|
| 26 |
-
},
|
| 27 |
-
{
|
| 28 |
-
"id": "agent_001",
|
| 29 |
-
"name": "Stereotypical Robot Named Robbie",
|
| 30 |
-
"type": "Agent",
|
| 31 |
-
"raw_prompt": "You are a stereotypical robot named Robbie..."
|
| 32 |
-
}
|
| 33 |
-
],
|
| 34 |
-
"relations": [
|
| 35 |
-
{
|
| 36 |
-
"id": "rel_001",
|
| 37 |
-
"source": "user_001",
|
| 38 |
-
"target": "agent_001",
|
| 39 |
-
"type": "PERFORMS",
|
| 40 |
-
"interaction_prompt": "What is a document loader?"
|
| 41 |
-
}
|
| 42 |
-
]
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
# Sample original trace content
|
| 46 |
-
original_trace = """
|
| 47 |
-
User: What is a document loader?
|
| 48 |
-
|
| 49 |
-
Agent: BEEP BOOP! Hello human! A document loader is a component in
|
| 50 |
-
LangChain that helps load documents from various sources. BEEP!
|
| 51 |
-
|
| 52 |
-
There are many types like TextLoader, PDFLoader, CSVLoader, etc.
|
| 53 |
-
Each one is designed for specific file formats. BOOP BEEP!
|
| 54 |
-
|
| 55 |
-
Would you like me to explain any specific type? BEEP BOOP!
|
| 56 |
-
"""
|
| 57 |
-
|
| 58 |
-
# Method 1: Using the pure function
|
| 59 |
-
print("=== Using Pure Function ===")
|
| 60 |
-
reconstructed_relations = reconstruct_prompts_from_knowledge_graph_rag(
|
| 61 |
-
knowledge_graph=knowledge_graph,
|
| 62 |
-
original_trace=original_trace,
|
| 63 |
-
llm_config={"model": "gpt-5-mini", "temperature": 0.1}
|
| 64 |
-
)
|
| 65 |
-
|
| 66 |
-
for relation in reconstructed_relations:
|
| 67 |
-
print(f"Relation: {relation['id']}")
|
| 68 |
-
print(f"Type: {relation['type']}")
|
| 69 |
-
print(f"Reconstructed Prompt:")
|
| 70 |
-
print(relation['prompt'])
|
| 71 |
-
print(f"Search Queries Used: {relation.get('search_queries_used', [])}")
|
| 72 |
-
print("-" * 50)
|
| 73 |
-
|
| 74 |
-
# Method 2: Using the class directly
|
| 75 |
-
print("\n=== Using RagPromptReconstructor Class ===")
|
| 76 |
-
reconstructor = RagPromptReconstructor(
|
| 77 |
-
knowledge_graph=knowledge_graph,
|
| 78 |
-
original_trace=original_trace,
|
| 79 |
-
llm_config={"model": "gpt-5-mini", "temperature": 0.1}
|
| 80 |
-
)
|
| 81 |
-
|
| 82 |
-
# Reconstruct a specific relation
|
| 83 |
-
specific_reconstruction = reconstructor.reconstruct_relation_prompt("rel_001")
|
| 84 |
-
print(f"Specific Reconstruction:")
|
| 85 |
-
print(f"Prompt: {specific_reconstruction['reconstructed_prompt']}")
|
| 86 |
-
print(f"Method: {specific_reconstruction['reconstruction_method']}")
|
| 87 |
-
|
| 88 |
-
# Method 3: Enrich entire knowledge graph
|
| 89 |
-
print("\n=== Enriching Knowledge Graph ===")
|
| 90 |
-
enriched_kg = enrich_knowledge_graph_with_prompts_rag(
|
| 91 |
-
knowledge_graph=knowledge_graph,
|
| 92 |
-
original_trace=original_trace
|
| 93 |
-
)
|
| 94 |
-
|
| 95 |
-
print(f"Original KG had {len(knowledge_graph.get('relations', []))} relations")
|
| 96 |
-
print(f"Enriched KG has {len(enriched_kg.get('prompt_reconstructions', []))} reconstructed prompts")
|
| 97 |
-
print(f"Reconstruction metadata: {enriched_kg.get('reconstruction_metadata', {})}")
|
| 98 |
-
|
| 99 |
-
if __name__ == "__main__":
|
| 100 |
-
example_usage()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backend/services/platform/langfuse_downloader.py
CHANGED
|
@@ -4,12 +4,12 @@ from datetime import datetime
|
|
| 4 |
from typing import Any, Dict, List, Optional, Union
|
| 5 |
|
| 6 |
import fire
|
| 7 |
-
from
|
| 8 |
from langfuse import Langfuse
|
| 9 |
|
| 10 |
from backend.routers.observe_models import LangFuseSession
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
|
| 15 |
class LangfuseDownloader:
|
|
@@ -38,18 +38,16 @@ class LangfuseDownloader:
|
|
| 38 |
os.environ["LANGFUSE_HOST"] = "https://cloud.langfuse.com"
|
| 39 |
|
| 40 |
# Check if credentials are available
|
| 41 |
-
if not
|
| 42 |
raise ValueError(
|
| 43 |
"Missing credentials. Provide secret_key and public_key parameters "
|
| 44 |
"or set LANGFUSE_SECRET_KEY and LANGFUSE_PUBLIC_KEY environment variables."
|
| 45 |
)
|
| 46 |
|
| 47 |
# Debug: Print environment variables to verify they're set correctly
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
print(f"LangfuseDownloader init -
|
| 51 |
-
print(f"LangfuseDownloader init - SECRET_KEY: {secret_key_val[:8] if secret_key_val else 'None'}...")
|
| 52 |
-
print(f"LangfuseDownloader init - HOST: {os.getenv('LANGFUSE_HOST')}")
|
| 53 |
|
| 54 |
# Initialize Langfuse client - it uses environment variables automatically
|
| 55 |
self.client = Langfuse()
|
|
|
|
| 4 |
from typing import Any, Dict, List, Optional, Union
|
| 5 |
|
| 6 |
import fire
|
| 7 |
+
from utils.config import LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, LANGFUSE_HOST
|
| 8 |
from langfuse import Langfuse
|
| 9 |
|
| 10 |
from backend.routers.observe_models import LangFuseSession
|
| 11 |
|
| 12 |
+
# Environment variables loaded via utils.config
|
| 13 |
|
| 14 |
|
| 15 |
class LangfuseDownloader:
|
|
|
|
| 38 |
os.environ["LANGFUSE_HOST"] = "https://cloud.langfuse.com"
|
| 39 |
|
| 40 |
# Check if credentials are available
|
| 41 |
+
if not LANGFUSE_SECRET_KEY or not LANGFUSE_PUBLIC_KEY:
|
| 42 |
raise ValueError(
|
| 43 |
"Missing credentials. Provide secret_key and public_key parameters "
|
| 44 |
"or set LANGFUSE_SECRET_KEY and LANGFUSE_PUBLIC_KEY environment variables."
|
| 45 |
)
|
| 46 |
|
| 47 |
# Debug: Print environment variables to verify they're set correctly
|
| 48 |
+
print(f"LangfuseDownloader init - PUBLIC_KEY: {LANGFUSE_PUBLIC_KEY[:8] if LANGFUSE_PUBLIC_KEY else 'None'}...")
|
| 49 |
+
print(f"LangfuseDownloader init - SECRET_KEY: {LANGFUSE_SECRET_KEY[:8] if LANGFUSE_SECRET_KEY else 'None'}...")
|
| 50 |
+
print(f"LangfuseDownloader init - HOST: {LANGFUSE_HOST}")
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# Initialize Langfuse client - it uses environment variables automatically
|
| 53 |
self.client = Langfuse()
|
debug_env.py
DELETED
|
@@ -1,185 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
Environment Variables Debug Script for HF Spaces
|
| 4 |
-
Helps diagnose the 'str expected, not NoneType' error
|
| 5 |
-
"""
|
| 6 |
-
|
| 7 |
-
import os
|
| 8 |
-
import sys
|
| 9 |
-
from pathlib import Path
|
| 10 |
-
|
| 11 |
-
def check_environment():
|
| 12 |
-
"""Check all required environment variables and configurations"""
|
| 13 |
-
print("🔍 AgentGraph Environment Debug Report")
|
| 14 |
-
print("=" * 50)
|
| 15 |
-
print()
|
| 16 |
-
|
| 17 |
-
# Critical environment variables
|
| 18 |
-
env_vars = {
|
| 19 |
-
"OPENAI_API_KEY": "❌ REQUIRED - OpenAI API access",
|
| 20 |
-
"LANGFUSE_PUBLIC_KEY": "🟡 Optional - AI monitoring",
|
| 21 |
-
"LANGFUSE_SECRET_KEY": "🟡 Optional - AI monitoring",
|
| 22 |
-
"LANGFUSE_HOST": "🟡 Optional - AI monitoring",
|
| 23 |
-
"OPENAI_MODEL_NAME": "🟡 Optional - defaults to gpt-4o-mini",
|
| 24 |
-
"DB_URI": "🟡 Optional - defaults to SQLite",
|
| 25 |
-
"PYTHONPATH": "🔧 System variable",
|
| 26 |
-
"HOME": "🔧 System variable",
|
| 27 |
-
"PATH": "🔧 System variable"
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
print("📋 Environment Variables Check:")
|
| 31 |
-
print("-" * 30)
|
| 32 |
-
missing_critical = []
|
| 33 |
-
|
| 34 |
-
for var, description in env_vars.items():
|
| 35 |
-
value = os.getenv(var)
|
| 36 |
-
if value is None:
|
| 37 |
-
status = "❌ NOT SET"
|
| 38 |
-
if "REQUIRED" in description:
|
| 39 |
-
missing_critical.append(var)
|
| 40 |
-
elif value == "":
|
| 41 |
-
status = "⚠️ EMPTY"
|
| 42 |
-
if "REQUIRED" in description:
|
| 43 |
-
missing_critical.append(var)
|
| 44 |
-
else:
|
| 45 |
-
# Mask sensitive values
|
| 46 |
-
if "KEY" in var or "SECRET" in var:
|
| 47 |
-
masked_value = f"{value[:8]}..." if len(value) > 8 else "***"
|
| 48 |
-
status = f"✅ SET ({masked_value})"
|
| 49 |
-
else:
|
| 50 |
-
status = f"✅ SET ({value[:50]}...)" if len(value) > 50 else f"✅ SET ({value})"
|
| 51 |
-
|
| 52 |
-
print(f" {var:20} | {status:25} | {description}")
|
| 53 |
-
|
| 54 |
-
print()
|
| 55 |
-
|
| 56 |
-
# Check critical paths and files
|
| 57 |
-
print("📁 Critical Paths Check:")
|
| 58 |
-
print("-" * 25)
|
| 59 |
-
|
| 60 |
-
paths_to_check = [
|
| 61 |
-
("Current directory", Path.cwd()),
|
| 62 |
-
("utils/config.py", Path("utils/config.py")),
|
| 63 |
-
("backend/app.py", Path("backend/app.py")),
|
| 64 |
-
("main.py", Path("main.py")),
|
| 65 |
-
("pyproject.toml", Path("pyproject.toml"))
|
| 66 |
-
]
|
| 67 |
-
|
| 68 |
-
for name, path in paths_to_check:
|
| 69 |
-
if path.exists():
|
| 70 |
-
status = "✅ EXISTS"
|
| 71 |
-
else:
|
| 72 |
-
status = "❌ MISSING"
|
| 73 |
-
print(f" {name:20} | {status:15} | {path}")
|
| 74 |
-
|
| 75 |
-
print()
|
| 76 |
-
|
| 77 |
-
# Python path check
|
| 78 |
-
print("🐍 Python Environment:")
|
| 79 |
-
print("-" * 20)
|
| 80 |
-
print(f" Python version: {sys.version}")
|
| 81 |
-
print(f" Python path: {sys.executable}")
|
| 82 |
-
print(f" Working directory: {os.getcwd()}")
|
| 83 |
-
print(f" PYTHONPATH: {os.getenv('PYTHONPATH', 'NOT SET')}")
|
| 84 |
-
|
| 85 |
-
print()
|
| 86 |
-
|
| 87 |
-
# Try importing critical modules
|
| 88 |
-
print("📦 Import Test:")
|
| 89 |
-
print("-" * 15)
|
| 90 |
-
|
| 91 |
-
modules_to_test = [
|
| 92 |
-
"utils.config",
|
| 93 |
-
"backend.app",
|
| 94 |
-
"fastapi",
|
| 95 |
-
"uvicorn",
|
| 96 |
-
"pydantic",
|
| 97 |
-
"sqlalchemy"
|
| 98 |
-
]
|
| 99 |
-
|
| 100 |
-
for module in modules_to_test:
|
| 101 |
-
try:
|
| 102 |
-
__import__(module)
|
| 103 |
-
print(f" {module:20} | ✅ OK")
|
| 104 |
-
except ImportError as e:
|
| 105 |
-
print(f" {module:20} | ❌ FAILED: {str(e)}")
|
| 106 |
-
except Exception as e:
|
| 107 |
-
print(f" {module:20} | ⚠️ ERROR: {str(e)}")
|
| 108 |
-
|
| 109 |
-
print()
|
| 110 |
-
|
| 111 |
-
# Summary
|
| 112 |
-
print("📊 Summary:")
|
| 113 |
-
print("-" * 10)
|
| 114 |
-
|
| 115 |
-
if missing_critical:
|
| 116 |
-
print(f"❌ CRITICAL: Missing required environment variables: {', '.join(missing_critical)}")
|
| 117 |
-
print("🔧 Fix: Set these variables in HF Spaces Settings > Environment variables")
|
| 118 |
-
return False
|
| 119 |
-
else:
|
| 120 |
-
print("✅ All critical environment variables are set")
|
| 121 |
-
|
| 122 |
-
# Try to identify the specific error
|
| 123 |
-
print()
|
| 124 |
-
print("🔍 Specific Error Analysis:")
|
| 125 |
-
print("The 'str expected, not NoneType' error suggests:")
|
| 126 |
-
print("1. A string parameter is being passed None instead of a string")
|
| 127 |
-
print("2. Most likely in configuration or initialization code")
|
| 128 |
-
print("3. Check Pydantic model validation or string concatenation")
|
| 129 |
-
|
| 130 |
-
return True
|
| 131 |
-
|
| 132 |
-
def test_config_import():
|
| 133 |
-
"""Test importing and using the config module"""
|
| 134 |
-
print()
|
| 135 |
-
print("🧪 Config Module Test:")
|
| 136 |
-
print("-" * 20)
|
| 137 |
-
|
| 138 |
-
try:
|
| 139 |
-
from utils.config import OPENAI_API_KEY, validate_config
|
| 140 |
-
|
| 141 |
-
print(f"OPENAI_API_KEY loaded: {'✅ YES' if OPENAI_API_KEY else '❌ NO'}")
|
| 142 |
-
|
| 143 |
-
# Test validation
|
| 144 |
-
is_valid = validate_config()
|
| 145 |
-
print(f"Config validation: {'✅ PASSED' if is_valid else '❌ FAILED'}")
|
| 146 |
-
|
| 147 |
-
return is_valid
|
| 148 |
-
|
| 149 |
-
except Exception as e:
|
| 150 |
-
print(f"❌ Config import failed: {str(e)}")
|
| 151 |
-
return False
|
| 152 |
-
|
| 153 |
-
if __name__ == "__main__":
|
| 154 |
-
print("Starting environment debug check...")
|
| 155 |
-
print()
|
| 156 |
-
|
| 157 |
-
# Basic environment check
|
| 158 |
-
env_ok = check_environment()
|
| 159 |
-
|
| 160 |
-
# Config test
|
| 161 |
-
config_ok = test_config_import()
|
| 162 |
-
|
| 163 |
-
print()
|
| 164 |
-
print("🎯 RECOMMENDATIONS:")
|
| 165 |
-
print("=" * 20)
|
| 166 |
-
|
| 167 |
-
if not env_ok:
|
| 168 |
-
print("1. ❌ Set missing OPENAI_API_KEY in HF Spaces environment variables")
|
| 169 |
-
print("2. 🔗 Go to: https://huggingface.co/spaces/holistic-ai/AgentGraph/settings")
|
| 170 |
-
print("3. 📝 Add: OPENAI_API_KEY = your_openai_api_key")
|
| 171 |
-
|
| 172 |
-
if not config_ok:
|
| 173 |
-
print("4. 🔧 Check utils/config.py for import issues")
|
| 174 |
-
print("5. 🐍 Verify Python dependencies are installed correctly")
|
| 175 |
-
|
| 176 |
-
if env_ok and config_ok:
|
| 177 |
-
print("✅ Environment looks good!")
|
| 178 |
-
print("🔍 The 'str expected, not NoneType' error may be in:")
|
| 179 |
-
print(" • Pydantic model validation")
|
| 180 |
-
print(" • String formatting/concatenation")
|
| 181 |
-
print(" • Database connection string")
|
| 182 |
-
print(" • FastAPI configuration")
|
| 183 |
-
|
| 184 |
-
print()
|
| 185 |
-
print("📊 Run this script in HF Spaces to get the exact error location!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deploy.sh
DELETED
|
File without changes
|
extraction_analysis/cot_extraction_20250909_172744_855dfc94.json
DELETED
|
@@ -1,139 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"timestamp": "20250909_172744",
|
| 3 |
-
"extraction_id": "855dfc94",
|
| 4 |
-
"model": "gpt-4o-mini",
|
| 5 |
-
"reasoning_steps": [],
|
| 6 |
-
"knowledge_graph": {
|
| 7 |
-
"system_name": "User Message Response System",
|
| 8 |
-
"system_summary": "This system is designed to process user messages and generate appropriate responses. The process begins when a user sends a message, which is handled by the `Assistant Agent` (agent_001). The agent undertakes the `Message Processing Task` (task_001) to analyze the user input and generate an output. This collaborative process allows the system to efficiently respond to user inquiries.",
|
| 9 |
-
"entities": [
|
| 10 |
-
{
|
| 11 |
-
"id": "agent_001",
|
| 12 |
-
"type": "Agent",
|
| 13 |
-
"name": "Assistant Agent",
|
| 14 |
-
"importance": "HIGH",
|
| 15 |
-
"raw_prompt": "",
|
| 16 |
-
"raw_prompt_ref": [
|
| 17 |
-
{
|
| 18 |
-
"line_start": 2,
|
| 19 |
-
"line_end": 2
|
| 20 |
-
}
|
| 21 |
-
]
|
| 22 |
-
},
|
| 23 |
-
{
|
| 24 |
-
"id": "task_001",
|
| 25 |
-
"type": "Task",
|
| 26 |
-
"name": "Message Processing Task",
|
| 27 |
-
"importance": "HIGH",
|
| 28 |
-
"raw_prompt": "",
|
| 29 |
-
"raw_prompt_ref": [
|
| 30 |
-
{
|
| 31 |
-
"line_start": 3,
|
| 32 |
-
"line_end": 3
|
| 33 |
-
}
|
| 34 |
-
]
|
| 35 |
-
},
|
| 36 |
-
{
|
| 37 |
-
"id": "input_001",
|
| 38 |
-
"type": "Input",
|
| 39 |
-
"name": "User Message",
|
| 40 |
-
"importance": "HIGH",
|
| 41 |
-
"raw_prompt": "",
|
| 42 |
-
"raw_prompt_ref": [
|
| 43 |
-
{
|
| 44 |
-
"line_start": 3,
|
| 45 |
-
"line_end": 3
|
| 46 |
-
}
|
| 47 |
-
]
|
| 48 |
-
},
|
| 49 |
-
{
|
| 50 |
-
"id": "output_001",
|
| 51 |
-
"type": "Output",
|
| 52 |
-
"name": "Agent Response",
|
| 53 |
-
"importance": "HIGH",
|
| 54 |
-
"raw_prompt": "",
|
| 55 |
-
"raw_prompt_ref": [
|
| 56 |
-
{
|
| 57 |
-
"line_start": 4,
|
| 58 |
-
"line_end": 4
|
| 59 |
-
}
|
| 60 |
-
]
|
| 61 |
-
},
|
| 62 |
-
{
|
| 63 |
-
"id": "human_001",
|
| 64 |
-
"type": "Human",
|
| 65 |
-
"name": "End User",
|
| 66 |
-
"importance": "HIGH",
|
| 67 |
-
"raw_prompt": "",
|
| 68 |
-
"raw_prompt_ref": [
|
| 69 |
-
{
|
| 70 |
-
"line_start": 3,
|
| 71 |
-
"line_end": 3
|
| 72 |
-
}
|
| 73 |
-
]
|
| 74 |
-
}
|
| 75 |
-
],
|
| 76 |
-
"relations": [
|
| 77 |
-
{
|
| 78 |
-
"id": "rel_001",
|
| 79 |
-
"source": "input_001",
|
| 80 |
-
"target": "agent_001",
|
| 81 |
-
"type": "CONSUMED_BY",
|
| 82 |
-
"importance": "HIGH",
|
| 83 |
-
"interaction_prompt": "",
|
| 84 |
-
"interaction_prompt_ref": [
|
| 85 |
-
{
|
| 86 |
-
"line_start": 2,
|
| 87 |
-
"line_end": 2
|
| 88 |
-
}
|
| 89 |
-
]
|
| 90 |
-
},
|
| 91 |
-
{
|
| 92 |
-
"id": "rel_002",
|
| 93 |
-
"source": "agent_001",
|
| 94 |
-
"target": "task_001",
|
| 95 |
-
"type": "PERFORMS",
|
| 96 |
-
"importance": "HIGH",
|
| 97 |
-
"interaction_prompt": "",
|
| 98 |
-
"interaction_prompt_ref": [
|
| 99 |
-
{
|
| 100 |
-
"line_start": 2,
|
| 101 |
-
"line_end": 2
|
| 102 |
-
}
|
| 103 |
-
]
|
| 104 |
-
},
|
| 105 |
-
{
|
| 106 |
-
"id": "rel_003",
|
| 107 |
-
"source": "task_001",
|
| 108 |
-
"target": "output_001",
|
| 109 |
-
"type": "PRODUCES",
|
| 110 |
-
"importance": "HIGH",
|
| 111 |
-
"interaction_prompt": "",
|
| 112 |
-
"interaction_prompt_ref": [
|
| 113 |
-
{
|
| 114 |
-
"line_start": 4,
|
| 115 |
-
"line_end": 4
|
| 116 |
-
}
|
| 117 |
-
]
|
| 118 |
-
},
|
| 119 |
-
{
|
| 120 |
-
"id": "rel_004",
|
| 121 |
-
"source": "output_001",
|
| 122 |
-
"target": "human_001",
|
| 123 |
-
"type": "DELIVERS_TO",
|
| 124 |
-
"importance": "HIGH",
|
| 125 |
-
"interaction_prompt": "",
|
| 126 |
-
"interaction_prompt_ref": [
|
| 127 |
-
{
|
| 128 |
-
"line_start": 4,
|
| 129 |
-
"line_end": 4
|
| 130 |
-
}
|
| 131 |
-
]
|
| 132 |
-
}
|
| 133 |
-
],
|
| 134 |
-
"failures": [],
|
| 135 |
-
"optimizations": []
|
| 136 |
-
},
|
| 137 |
-
"input_trace_length": 184,
|
| 138 |
-
"input_trace_preview": "<L1> {\n<L2> \"agent_name\": \"assistant\",\n<L3> \"input\": \"user message\",\n<L4> \"output\": \"agent response\",\n<L5> \"timestamp\": \"2024-08-31\",\n<L6> \"trace_id\": \"test-trace-123\"\n<L7> }"
|
| 139 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
frontend/Dockerfile.dev
DELETED
|
@@ -1,18 +0,0 @@
|
|
| 1 |
-
FROM node:18-slim
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
# Copy package files
|
| 6 |
-
COPY package*.json ./
|
| 7 |
-
|
| 8 |
-
# Install dependencies
|
| 9 |
-
RUN npm ci
|
| 10 |
-
|
| 11 |
-
# Copy source code
|
| 12 |
-
COPY . .
|
| 13 |
-
|
| 14 |
-
# Expose port for development server
|
| 15 |
-
EXPOSE 3001
|
| 16 |
-
|
| 17 |
-
# Start development server with hot reload
|
| 18 |
-
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0", "--port", "3001"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main.py
CHANGED
|
@@ -8,6 +8,9 @@ Updated: Graph visualization sizes optimized for better UI layout.
|
|
| 8 |
# Import the complete LiteLLM fix FIRST, before any other imports that might use LiteLLM
|
| 9 |
from utils.fix_litellm_stop_param import * # This applies all the patches
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
# Continue with regular imports
|
| 12 |
import argparse
|
| 13 |
import sys
|
|
@@ -218,6 +221,14 @@ def main():
|
|
| 218 |
logging.getLogger().setLevel(getattr(logging, args.log_level))
|
| 219 |
logger.setLevel(getattr(logging, args.log_level))
|
| 220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
# --------------------------------------------------
|
| 222 |
# First-run combo flag: environment setup + init DB + dev server
|
| 223 |
# --------------------------------------------------
|
|
@@ -248,26 +259,16 @@ def main():
|
|
| 248 |
return
|
| 249 |
deps_marker.touch()
|
| 250 |
|
| 251 |
-
# 1. Environment setup
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
setup_environment()
|
| 256 |
-
logger.info("✅ Environment setup complete")
|
| 257 |
-
except Exception as e:
|
| 258 |
-
logger.error(f"Environment setup failed: {e}")
|
| 259 |
-
return
|
| 260 |
|
| 261 |
# 2. Database initialization
|
| 262 |
try:
|
| 263 |
-
from backend.database.init_db import
|
| 264 |
logger.info("🗄️ Initializing the database...")
|
| 265 |
-
|
| 266 |
-
sys.argv = [sys.argv[0]] # clear extra flags for init_db parser
|
| 267 |
-
try:
|
| 268 |
-
init_db_main()
|
| 269 |
-
finally:
|
| 270 |
-
sys.argv = _orig_argv
|
| 271 |
logger.info("✅ Database initialization complete")
|
| 272 |
except Exception as e:
|
| 273 |
logger.error(f"Database initialization failed: {e}")
|
|
@@ -290,14 +291,21 @@ def main():
|
|
| 290 |
|
| 291 |
# Environment setup
|
| 292 |
if args.setup:
|
| 293 |
-
|
| 294 |
-
|
|
|
|
|
|
|
| 295 |
return
|
| 296 |
|
| 297 |
# Initialize database
|
| 298 |
if args.init_db:
|
| 299 |
-
from backend.database.init_db import
|
| 300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
return
|
| 302 |
|
| 303 |
# Start full-stack development environment
|
|
|
|
| 8 |
# Import the complete LiteLLM fix FIRST, before any other imports that might use LiteLLM
|
| 9 |
from utils.fix_litellm_stop_param import * # This applies all the patches
|
| 10 |
|
| 11 |
+
# Import configuration and debug utilities
|
| 12 |
+
from utils.config import validate_config, debug_config
|
| 13 |
+
|
| 14 |
# Continue with regular imports
|
| 15 |
import argparse
|
| 16 |
import sys
|
|
|
|
| 221 |
logging.getLogger().setLevel(getattr(logging, args.log_level))
|
| 222 |
logger.setLevel(getattr(logging, args.log_level))
|
| 223 |
|
| 224 |
+
# Debug configuration on startup (but only if not just showing help)
|
| 225 |
+
if len(sys.argv) > 1:
|
| 226 |
+
debug_config()
|
| 227 |
+
if not validate_config():
|
| 228 |
+
logger.error("❌ Configuration validation failed. Please check your environment variables.")
|
| 229 |
+
logger.error("💡 Tip: Copy .env.example to .env and fill in your API keys")
|
| 230 |
+
return
|
| 231 |
+
|
| 232 |
# --------------------------------------------------
|
| 233 |
# First-run combo flag: environment setup + init DB + dev server
|
| 234 |
# --------------------------------------------------
|
|
|
|
| 259 |
return
|
| 260 |
deps_marker.touch()
|
| 261 |
|
| 262 |
+
# 1. Environment setup (now handled by unified config system)
|
| 263 |
+
logger.info("🔧 Environment setup...")
|
| 264 |
+
logger.info("✅ Environment configuration loaded successfully")
|
| 265 |
+
# Note: Environment setup is now handled by the unified config system in utils/config.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
|
| 267 |
# 2. Database initialization
|
| 268 |
try:
|
| 269 |
+
from backend.database.init_db import init_database
|
| 270 |
logger.info("🗄️ Initializing the database...")
|
| 271 |
+
init_database(reset=False, force=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
logger.info("✅ Database initialization complete")
|
| 273 |
except Exception as e:
|
| 274 |
logger.error(f"Database initialization failed: {e}")
|
|
|
|
| 291 |
|
| 292 |
# Environment setup
|
| 293 |
if args.setup:
|
| 294 |
+
logger.info("🔧 Environment setup...")
|
| 295 |
+
logger.info("✅ Environment configuration is handled by the unified config system")
|
| 296 |
+
logger.info("💡 Configuration is automatically loaded from .env file or environment variables")
|
| 297 |
+
logger.info("📝 See .env.example for available configuration options")
|
| 298 |
return
|
| 299 |
|
| 300 |
# Initialize database
|
| 301 |
if args.init_db:
|
| 302 |
+
from backend.database.init_db import init_database
|
| 303 |
+
try:
|
| 304 |
+
logger.info("🗄️ Initializing database...")
|
| 305 |
+
init_database(reset=False, force=False)
|
| 306 |
+
logger.info("✅ Database initialization complete")
|
| 307 |
+
except Exception as e:
|
| 308 |
+
logger.error(f"❌ Database initialization failed: {e}")
|
| 309 |
return
|
| 310 |
|
| 311 |
# Start full-stack development environment
|
pyproject.toml
CHANGED
|
@@ -66,10 +66,6 @@ dependencies = [
|
|
| 66 |
"datasets>=3.6.0", # 🟡 HF数据集 (1 使用)
|
| 67 |
]
|
| 68 |
|
| 69 |
-
# ❌ 已移除的依赖项 (节省约500MB+):
|
| 70 |
-
# "bottleneck>=1.3,<2.0.0", # ❌ 未使用 (0次导入)
|
| 71 |
-
# "pydot>=3.0.4", # ❌ 未使用 (0次导入)
|
| 72 |
-
# "openai-agents==0.2.4", # ❌ 未使用 (0次导入)
|
| 73 |
|
| 74 |
[project.urls]
|
| 75 |
"Homepage" = "https://github.com/981526092/agent-graph"
|
|
|
|
| 66 |
"datasets>=3.6.0", # 🟡 HF数据集 (1 使用)
|
| 67 |
]
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
[project.urls]
|
| 71 |
"Homepage" = "https://github.com/981526092/agent-graph"
|
setup.sh
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# AgentGraph Quick Setup Script
|
| 4 |
+
# This script automates the setup process for AgentGraph
|
| 5 |
+
|
| 6 |
+
set -e # Exit on any error
|
| 7 |
+
|
| 8 |
+
echo "🕸️ AgentGraph Quick Setup"
|
| 9 |
+
echo "=========================="
|
| 10 |
+
echo
|
| 11 |
+
|
| 12 |
+
# Colors for output
|
| 13 |
+
RED='\033[0;31m'
|
| 14 |
+
GREEN='\033[0;32m'
|
| 15 |
+
YELLOW='\033[1;33m'
|
| 16 |
+
BLUE='\033[0;34m'
|
| 17 |
+
NC='\033[0m' # No Color
|
| 18 |
+
|
| 19 |
+
# Helper functions
|
| 20 |
+
print_success() {
|
| 21 |
+
echo -e "${GREEN}✅ $1${NC}"
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
print_info() {
|
| 25 |
+
echo -e "${BLUE}ℹ️ $1${NC}"
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
print_warning() {
|
| 29 |
+
echo -e "${YELLOW}⚠️ $1${NC}"
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
print_error() {
|
| 33 |
+
echo -e "${RED}❌ $1${NC}"
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
# Check if running in correct directory
|
| 37 |
+
if [ ! -f "main.py" ] || [ ! -f "pyproject.toml" ]; then
|
| 38 |
+
print_error "Please run this script from the AgentGraph root directory"
|
| 39 |
+
exit 1
|
| 40 |
+
fi
|
| 41 |
+
|
| 42 |
+
# Function to check if command exists
|
| 43 |
+
command_exists() {
|
| 44 |
+
command -v "$1" >/dev/null 2>&1
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
# Function to prompt for OpenAI API key
|
| 48 |
+
setup_env_file() {
|
| 49 |
+
print_info "Setting up environment configuration..."
|
| 50 |
+
|
| 51 |
+
if [ ! -f ".env" ]; then
|
| 52 |
+
if [ -f ".env.example" ]; then
|
| 53 |
+
cp .env.example .env
|
| 54 |
+
print_success "Created .env file from .env.example"
|
| 55 |
+
else
|
| 56 |
+
print_error ".env.example file not found"
|
| 57 |
+
exit 1
|
| 58 |
+
fi
|
| 59 |
+
else
|
| 60 |
+
print_info ".env file already exists, checking configuration..."
|
| 61 |
+
fi
|
| 62 |
+
|
| 63 |
+
# Check if OPENAI_API_KEY is set
|
| 64 |
+
if grep -q "^OPENAI_API_KEY=your_openai_api_key_here" .env || grep -q "^OPENAI_API_KEY=$" .env; then
|
| 65 |
+
print_warning "OpenAI API key is not configured"
|
| 66 |
+
echo
|
| 67 |
+
echo "Please enter your OpenAI API key (starts with 'sk-'):"
|
| 68 |
+
echo "You can get one at: https://platform.openai.com/account/api-keys"
|
| 69 |
+
read -p "OpenAI API Key: " openai_key
|
| 70 |
+
|
| 71 |
+
if [ -n "$openai_key" ]; then
|
| 72 |
+
# Update the API key in .env file
|
| 73 |
+
if [[ "$OSTYPE" == "darwin"* ]]; then
|
| 74 |
+
# macOS
|
| 75 |
+
sed -i '' "s/^OPENAI_API_KEY=.*/OPENAI_API_KEY=$openai_key/" .env
|
| 76 |
+
else
|
| 77 |
+
# Linux
|
| 78 |
+
sed -i "s/^OPENAI_API_KEY=.*/OPENAI_API_KEY=$openai_key/" .env
|
| 79 |
+
fi
|
| 80 |
+
print_success "OpenAI API key configured"
|
| 81 |
+
else
|
| 82 |
+
print_warning "No API key provided. You can set it later in the .env file"
|
| 83 |
+
fi
|
| 84 |
+
else
|
| 85 |
+
print_success "OpenAI API key is already configured"
|
| 86 |
+
fi
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
# Function to setup and run with Docker
|
| 90 |
+
setup_docker() {
|
| 91 |
+
print_info "Setting up AgentGraph with Docker..."
|
| 92 |
+
|
| 93 |
+
# Check if Docker is installed
|
| 94 |
+
if ! command_exists docker; then
|
| 95 |
+
print_error "Docker is not installed. Please install Docker first:"
|
| 96 |
+
echo " - macOS: https://docs.docker.com/desktop/mac/"
|
| 97 |
+
echo " - Linux: https://docs.docker.com/engine/install/"
|
| 98 |
+
echo " - Windows: https://docs.docker.com/desktop/windows/"
|
| 99 |
+
exit 1
|
| 100 |
+
fi
|
| 101 |
+
|
| 102 |
+
# Check if Docker is running
|
| 103 |
+
if ! docker info > /dev/null 2>&1; then
|
| 104 |
+
print_error "Docker is not running. Please start Docker and try again."
|
| 105 |
+
exit 1
|
| 106 |
+
fi
|
| 107 |
+
|
| 108 |
+
print_success "Docker is available"
|
| 109 |
+
|
| 110 |
+
# Setup environment file
|
| 111 |
+
setup_env_file
|
| 112 |
+
|
| 113 |
+
print_info "Building Docker image (this may take a few minutes)..."
|
| 114 |
+
if docker build -t agentgraph . > /dev/null 2>&1; then
|
| 115 |
+
print_success "Docker image built successfully"
|
| 116 |
+
else
|
| 117 |
+
print_error "Failed to build Docker image"
|
| 118 |
+
exit 1
|
| 119 |
+
fi
|
| 120 |
+
|
| 121 |
+
# Stop existing container if running
|
| 122 |
+
if docker ps -q -f name=agentgraph-app > /dev/null 2>&1; then
|
| 123 |
+
print_info "Stopping existing AgentGraph container..."
|
| 124 |
+
docker stop agentgraph-app > /dev/null 2>&1
|
| 125 |
+
docker rm agentgraph-app > /dev/null 2>&1
|
| 126 |
+
print_success "Existing container stopped"
|
| 127 |
+
fi
|
| 128 |
+
|
| 129 |
+
print_info "Starting AgentGraph container..."
|
| 130 |
+
if docker run -d --name agentgraph-app -p 7860:7860 --env-file .env agentgraph > /dev/null 2>&1; then
|
| 131 |
+
print_success "AgentGraph container started successfully"
|
| 132 |
+
else
|
| 133 |
+
print_error "Failed to start container"
|
| 134 |
+
exit 1
|
| 135 |
+
fi
|
| 136 |
+
|
| 137 |
+
# Wait a moment for startup
|
| 138 |
+
sleep 5
|
| 139 |
+
|
| 140 |
+
# Check if the service is healthy
|
| 141 |
+
print_info "Checking service health..."
|
| 142 |
+
for i in {1..30}; do
|
| 143 |
+
if curl -s http://localhost:7860/api/observability/health-check > /dev/null 2>&1; then
|
| 144 |
+
print_success "AgentGraph is running and healthy!"
|
| 145 |
+
break
|
| 146 |
+
fi
|
| 147 |
+
if [ $i -eq 30 ]; then
|
| 148 |
+
print_warning "Service health check timed out, but container is running"
|
| 149 |
+
break
|
| 150 |
+
fi
|
| 151 |
+
sleep 2
|
| 152 |
+
done
|
| 153 |
+
|
| 154 |
+
echo
|
| 155 |
+
print_success "🎉 AgentGraph Setup Complete!"
|
| 156 |
+
echo
|
| 157 |
+
echo "🌐 Access AgentGraph at: http://localhost:7860"
|
| 158 |
+
echo "📚 API Documentation: http://localhost:7860/docs"
|
| 159 |
+
echo
|
| 160 |
+
echo "💡 Useful commands:"
|
| 161 |
+
echo " - View logs: docker logs agentgraph-app"
|
| 162 |
+
echo " - Stop: docker stop agentgraph-app"
|
| 163 |
+
echo " - Restart: docker restart agentgraph-app"
|
| 164 |
+
echo
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
# Function to setup for local development
|
| 168 |
+
setup_local() {
|
| 169 |
+
print_info "Setting up AgentGraph for local development..."
|
| 170 |
+
|
| 171 |
+
# Setup environment file
|
| 172 |
+
setup_env_file
|
| 173 |
+
|
| 174 |
+
# Check Python version
|
| 175 |
+
if command_exists python3; then
|
| 176 |
+
python_cmd="python3"
|
| 177 |
+
elif command_exists python; then
|
| 178 |
+
python_cmd="python"
|
| 179 |
+
else
|
| 180 |
+
print_error "Python is not installed. Please install Python 3.11+ first."
|
| 181 |
+
exit 1
|
| 182 |
+
fi
|
| 183 |
+
|
| 184 |
+
print_success "Python is available"
|
| 185 |
+
|
| 186 |
+
print_info "Running AgentGraph setup..."
|
| 187 |
+
if $python_cmd main.py --first-run; then
|
| 188 |
+
print_success "Local development setup completed!"
|
| 189 |
+
else
|
| 190 |
+
print_error "Setup failed. Please check the error messages above."
|
| 191 |
+
exit 1
|
| 192 |
+
fi
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
# Main setup logic
|
| 196 |
+
echo "Choose your setup method:"
|
| 197 |
+
echo "1) Docker (Recommended - Easy and isolated)"
|
| 198 |
+
echo "2) Local Development (For development work)"
|
| 199 |
+
echo
|
| 200 |
+
read -p "Enter your choice (1 or 2): " choice
|
| 201 |
+
|
| 202 |
+
case $choice in
|
| 203 |
+
1)
|
| 204 |
+
setup_docker
|
| 205 |
+
;;
|
| 206 |
+
2)
|
| 207 |
+
setup_local
|
| 208 |
+
;;
|
| 209 |
+
*)
|
| 210 |
+
print_error "Invalid choice. Please run the script again and choose 1 or 2."
|
| 211 |
+
exit 1
|
| 212 |
+
;;
|
| 213 |
+
esac
|
utils/config.py
CHANGED
|
@@ -2,9 +2,35 @@ import os
|
|
| 2 |
from pathlib import Path
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# OpenAI Configuration
|
| 10 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
|
@@ -40,8 +66,51 @@ def validate_config():
|
|
| 40 |
|
| 41 |
if missing_vars:
|
| 42 |
missing_vars_str = ", ".join(missing_vars)
|
| 43 |
-
print(f"Missing required environment variables: {missing_vars_str}")
|
| 44 |
-
print(f"Please set them in the .env file or as environment variables")
|
| 45 |
return False
|
| 46 |
|
| 47 |
-
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from pathlib import Path
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
|
| 5 |
+
def load_environment_variables():
|
| 6 |
+
"""
|
| 7 |
+
Load environment variables with proper priority:
|
| 8 |
+
1. System environment variables (highest priority - for production/HF Spaces)
|
| 9 |
+
2. .env file (fallback for local development)
|
| 10 |
+
"""
|
| 11 |
+
# First check if we're in a production environment (HF Spaces, Docker, etc.)
|
| 12 |
+
# by looking for common production indicators
|
| 13 |
+
is_production = any([
|
| 14 |
+
os.getenv("SPACE_ID"), # Hugging Face Spaces
|
| 15 |
+
os.getenv("RENDER"), # Render.com
|
| 16 |
+
os.getenv("RAILWAY_ENVIRONMENT"), # Railway
|
| 17 |
+
os.getenv("VERCEL"), # Vercel
|
| 18 |
+
os.getenv("KUBERNETES_SERVICE_HOST"), # Kubernetes
|
| 19 |
+
os.getenv("AWS_LAMBDA_FUNCTION_NAME"), # AWS Lambda
|
| 20 |
+
])
|
| 21 |
+
|
| 22 |
+
# Load .env file only if not in production AND file exists
|
| 23 |
+
env_path = Path('.') / '.env'
|
| 24 |
+
if not is_production and env_path.exists():
|
| 25 |
+
print(f"🔧 Loading environment variables from {env_path}")
|
| 26 |
+
load_dotenv(dotenv_path=env_path, override=False) # Don't override existing env vars
|
| 27 |
+
elif is_production:
|
| 28 |
+
print("🚀 Production environment detected, using system environment variables")
|
| 29 |
+
else:
|
| 30 |
+
print("⚠️ No .env file found and not in production environment")
|
| 31 |
+
|
| 32 |
+
# Load environment variables using the unified method
|
| 33 |
+
load_environment_variables()
|
| 34 |
|
| 35 |
# OpenAI Configuration
|
| 36 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
|
|
|
| 66 |
|
| 67 |
if missing_vars:
|
| 68 |
missing_vars_str = ", ".join(missing_vars)
|
| 69 |
+
print(f"❌ Missing required environment variables: {missing_vars_str}")
|
| 70 |
+
print(f"📝 Please set them in the .env file or as environment variables")
|
| 71 |
return False
|
| 72 |
|
| 73 |
+
return True
|
| 74 |
+
|
| 75 |
+
def debug_config():
|
| 76 |
+
"""Debug function to show current configuration state"""
|
| 77 |
+
print("🔍 AgentGraph Configuration Debug:")
|
| 78 |
+
print("=" * 50)
|
| 79 |
+
|
| 80 |
+
# Show environment loading method
|
| 81 |
+
env_path = Path('.') / '.env'
|
| 82 |
+
is_production = any([
|
| 83 |
+
os.getenv("SPACE_ID"),
|
| 84 |
+
os.getenv("RENDER"),
|
| 85 |
+
os.getenv("RAILWAY_ENVIRONMENT"),
|
| 86 |
+
os.getenv("VERCEL"),
|
| 87 |
+
os.getenv("KUBERNETES_SERVICE_HOST"),
|
| 88 |
+
os.getenv("AWS_LAMBDA_FUNCTION_NAME"),
|
| 89 |
+
])
|
| 90 |
+
|
| 91 |
+
print(f"🏗️ Environment: {'Production' if is_production else 'Development'}")
|
| 92 |
+
print(f"📁 .env file exists: {env_path.exists()}")
|
| 93 |
+
print(f"📍 Working directory: {Path.cwd()}")
|
| 94 |
+
print()
|
| 95 |
+
|
| 96 |
+
# Show key configuration values (masked)
|
| 97 |
+
configs = [
|
| 98 |
+
("OPENAI_API_KEY", OPENAI_API_KEY),
|
| 99 |
+
("OPENAI_MODEL_NAME", OPENAI_MODEL_NAME),
|
| 100 |
+
("LANGFUSE_PUBLIC_KEY", LANGFUSE_PUBLIC_KEY),
|
| 101 |
+
("LANGFUSE_SECRET_KEY", LANGFUSE_SECRET_KEY),
|
| 102 |
+
("LANGFUSE_HOST", LANGFUSE_HOST),
|
| 103 |
+
("DB_URI", DB_URI),
|
| 104 |
+
]
|
| 105 |
+
|
| 106 |
+
for name, value in configs:
|
| 107 |
+
if value:
|
| 108 |
+
if "KEY" in name or "SECRET" in name:
|
| 109 |
+
masked = f"{value[:8]}..." if len(value) > 8 else "***"
|
| 110 |
+
print(f"✅ {name}: {masked}")
|
| 111 |
+
else:
|
| 112 |
+
print(f"✅ {name}: {value}")
|
| 113 |
+
else:
|
| 114 |
+
print(f"❌ {name}: Not set")
|
| 115 |
+
|
| 116 |
+
print("=" * 50)
|