Skip to content

allthingssecurity/evoldsl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MCTS (Monte Carlo Tree Search) + GPT-4o + Self Evolution for API discovering novel API Composition scenarios

An intelligent API composition system that uses MCTS (Monte Carlo Tree Search) + GPT-4o + Self Evolution to automatically discover and build novel API composition scenarios for business intelligence and data analysis tasks.

Architecture

Clean 3-phase architecture showing MCTS exploration, Evolution optimization, and Self-Evolution for continuous improvement

🎬 Live Demo

πŸš€ View Interactive Animation Demo

Watch the complete MCTS + Evolution process in action with a real financial dashboard example!

πŸš€ Features

  • GPT-4o Neural Guidance: Uses GPT-4o as both policy and value network for intelligent API selection
  • MCTS Tree Search: Systematically explores API composition space with UCB1 selection
  • Evolution Engine: Optimizes API chains through mutation and selection
  • Real-time Visualization: Professional React frontend with live MCTS tree and evolution progress
  • 25+ API Bank: Comprehensive set of APIs for data analysis, visualization, and reporting
  • Type Safety: Automatic type compatibility checking and data flow validation
  • WebSocket Communication: Real-time updates of composition progress

πŸ—οΈ Architecture

The system combines three powerful techniques:

  1. GPT-4o Neural Network: Provides semantic understanding and intelligent guidance
  2. MCTS Tree Search: Explores API composition space systematically
  3. Evolution Engine: Optimizes the best candidates through genetic algorithms

Key Components:

  • Backend: FastAPI with WebSocket support
  • Frontend: React with TypeScript, Tailwind CSS, and Framer Motion
  • AI Integration: GPT-4o for policy and value networks
  • Visualization: Real-time D3.js tree visualization and evolution progress

πŸ“‹ Prerequisites

  • Python 3.8+
  • Node.js 16+
  • OpenAI API key
  • Git

πŸ› οΈ Installation

1. Clone the Repository

git clone <repository-url>
cd mcts-evolution-coding-agent

2. Backend Setup

# Create virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements_api.txt

# Set up environment variables
cp .env.template .env
# Edit .env and add your OPENAI_API_KEY

3. Frontend Setup

cd frontend
npm install
cd ..

πŸš€ Quick Start

1. Start the Backend

source venv/bin/activate
python api_composition_backend.py

The backend will start on http://localhost:8000

2. Start the Frontend

cd frontend
npm run dev

The frontend will start on http://localhost:3000

3. Open the Application

Navigate to http://localhost:3000 in your browser.

🎯 Usage

  1. Configure Parameters: Set MCTS iterations, evolution generations, and business objectives
  2. Start Composition: Click "Start Composition" to begin the intelligent API chain building
  3. Watch Progress: Observe real-time MCTS tree construction and evolution progress
  4. View Results: See the optimized API chain with type compatibility and data flow

Example Business Goals:

  • Business Intelligence Dashboard
  • Financial Risk Analysis
  • Market Research Report
  • Competitive Analysis
  • Investment Insights

πŸ”§ Configuration

MCTS Parameters:

  • Iterations: Number of MCTS search iterations (5-30)
  • Exploration Constant: UCB1 exploration parameter (0.5-2.0)
  • Target Task: Business objective for API composition

Evolution Parameters:

  • Generations: Number of evolution generations (5-20)
  • Population Size: Size of candidate population (10-50)
  • Mutation Rate: Probability of mutations (0.1-1.0)

GPT-4o Parameters:

  • Model: gpt-4o or gpt-4o-mini
  • Temperature: Creativity level (0.1-1.0)
  • Max Tokens: Response length limit (100-2000)

πŸ“Š API Bank

The system includes 25+ APIs across 5 categories:

  • Data Sources: News search, stock data, weather, company info
  • Analysis: Sentiment analysis, trend analysis, entity extraction
  • Processing: Text summarization, data filtering, normalization
  • Visualization: Charts, heatmaps, timelines, plots
  • Output: Reports, dashboards, alerts, presentations

πŸ”¬ How It Works

1. MCTS Phase

  • Selection: Choose nodes using UCB1 + GPT-4o guidance
  • Expansion: Add new APIs based on GPT-4o suggestions
  • Evaluation: Score API chains using GPT-4o value network
  • Backpropagation: Update node statistics

2. Evolution Phase

  • Population: Initialize with best MCTS candidates
  • Mutation: Modify API chains (add/remove/replace APIs)
  • Selection: Choose fittest candidates for next generation
  • Optimization: Converge to optimal API compositions

3. Real-time Visualization

  • Live MCTS tree construction
  • Evolution progress tracking
  • API chain flow visualization
  • Performance metrics dashboard

πŸ• Simple Explanation: The Pizza Analogy

Think of building API compositions like making the perfect pizza:

MCTS = Smart Chef πŸ§‘β€πŸ³

  • Tries different ingredient combinations systematically
  • "Let me try pepperoni... now add mushrooms... now cheese..."
  • GPT-4o guides: "Based on customer preferences, try adding basil next"
  • Finds 5 good pizza recipes (API chains)

Evolution = Recipe Improver 🧬

  • Takes those 5 good pizzas and creates variations
  • Makes small changes: "What if I add more cheese? Less sauce? Different crust?"
  • Creates a population of 10 pizza variations
  • Keeps the tastiest ones, discards the bad ones
  • Repeats to make them even better over generations

Real Example: Financial Dashboard

MCTS Exploration:

Iteration 1: START β†’ get_stock_data("AAPL")
Iteration 5: START β†’ get_stock_data β†’ calculate_risk  
Iteration 10: START β†’ get_stock_data β†’ search_news β†’ analyze_sentiment
Iteration 15: START β†’ get_stock_data β†’ calculate_risk β†’ create_chart β†’ generate_report

Evolution Optimization:

Generation 1: 5 different financial API chains
Best: Stock β†’ Risk β†’ Chart β†’ Report (Score: 0.75)

Generation 3: Evolved variations  
Better: Stock β†’ News β†’ Sentiment β†’ Risk β†’ Prediction β†’ Dashboard (Score: 0.85)

Generation 5: Further optimized
Best: Stock β†’ News β†’ Social β†’ Sentiment β†’ Risk β†’ Timeline β†’ Alert β†’ Dashboard (Score: 0.92)

♾️ Self-Evolution: Never-Ending Improvement

The system keeps evolving forever by:

1. New Ingredients (APIs): Automatically discovers and adds new APIs

  • Month 1: 25 APIs (basic financial)
  • Month 6: 40 APIs (added social media)
  • Month 12: 60 APIs (added crypto, ESG, supply chain)

2. Changing Tastes (Goals): Adapts to new business needs

  • January: "Create fastest dashboard"
  • June: "Optimize for accuracy"
  • December: "Minimize costs"

3. New Customers (Domains): Expands to new business areas

  • Start: Financial analysis
  • Later: Healthcare, retail, manufacturing
  • Future: Space exploration, quantum computing

The Never-Ending Cycle:

  1. Evolve current chains (make them better) βœ…
  2. Add new APIs when available (more ingredients) βœ…
  3. Change goals when needs shift (new preferences) βœ…
  4. Expand to new domains (new customers) βœ…
  5. Repeat forever πŸ”„

Population Evolution Example:

Generation 1: 5 API chains from MCTS

Chain A: News β†’ Sentiment β†’ Report
Chain B: Stock β†’ Risk β†’ Chart  
Chain C: Weather β†’ Analysis β†’ Dashboard
Chain D: Company β†’ Patents β†’ Summary
Chain E: Social β†’ Trends β†’ Visualization

Evolution creates variations:

Chain A1: News β†’ Sentiment β†’ Summary β†’ Report (added step)
Chain A2: News β†’ Sentiment (removed report)
Chain B1: Stock β†’ Risk β†’ Chart β†’ Dashboard (added dashboard)
Chain B2: Stock β†’ News β†’ Risk β†’ Chart (added news)

Generation 2: Keep best 5, create 5 more variations
Generation 3: Keep best 5, create 5 more variations
...and the cycle continues infinitely!

Real-World Adaptation Example:

Week 1: System creates financial dashboards

  • Population: 10 different financial API chains
  • Best: Stock β†’ Risk β†’ Chart β†’ Report

Week 10: Market crashes, need faster alerts

  • Goal changes to "speed over accuracy"
  • Population evolves: Stock β†’ Quick-Risk β†’ Alert

Week 20: New crypto APIs become available

  • System adds Bitcoin, Ethereum APIs
  • Population evolves: Stock β†’ Crypto β†’ Combined-Risk β†’ Alert

Week 30: Users want social sentiment

  • System adds Twitter, Reddit APIs
  • Population evolves: Stock β†’ Crypto β†’ Social β†’ Sentiment β†’ Risk β†’ Alert

This creates a system that never stops discovering novel API composition scenarios!

πŸ›‘οΈ Type Safety

The system ensures type compatibility through:

  • Type Compatibility Graph: Maps valid type conversions
  • Automatic Validation: Checks input/output type matching
  • Data Flow Analysis: Ensures valid API chaining

🌐 WebSocket API

Real-time communication endpoints:

  • ws://localhost:8000/ws/{session_id} - WebSocket connection
  • Message types: mcts_update, evolution_generation, system_status

πŸ“ Project Structure

β”œβ”€β”€ api_composition_backend.py    # Main FastAPI backend
β”œβ”€β”€ frontend/                     # React frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/          # React components
β”‚   β”‚   β”œβ”€β”€ hooks/               # Custom hooks
β”‚   β”‚   β”œβ”€β”€ store/               # Zustand state management
β”‚   β”‚   └── types/               # TypeScript definitions
β”œβ”€β”€ architecture_diagram.svg     # System architecture
β”œβ”€β”€ requirements_api.txt         # Python dependencies
└── README.md                    # This file

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • OpenAI for GPT-4o API
  • FastAPI for the excellent web framework
  • React and the amazing frontend ecosystem
  • D3.js for powerful visualizations

πŸ“ž Support

For questions and support, please open an issue on GitHub.


Built with ❀️ using GPT-4o, MCTS, and Evolution

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •