AI-Powered Development Environment
An AI-assisted mini program development IDE that demonstrates AEnvironment's capabilities for tool integration, deployment, and scaling. This IDE enables developers to create web applications through natural language conversations with an AI agent.
- AI Agent: Multi-turn conversation powered by OpenAI API with automatic retry logic for rate limits
- Virtual File System (VFS): Persistent file system for managing mini program files
- MCP Tools: Model Context Protocol tools for file operations and code execution
- Live Preview: Real-time preview of generated applications in an iframe
- Responsive Design: Automatically ensures generated content fits the preview window
- Version Tracking: Displays version numbers on generated pages for update verification
The project is organized into three main directories:
mini-program/
├── agent/ # Agent server (FastAPI + OpenAI integration)
│ └── agent_server.py
├── environment/ # AEnvironment tools and configuration
│ ├── src/ # MCP tools (read_file, write_file, etc.)
│ ├── config.json # Environment configuration
│ ├── Dockerfile # Container build configuration
│ └── requirements.txt
└── frontend/ # Web UI (HTML/CSS/JavaScript)
├── index.html
├── app.js
└── style.css
- Frontend: HTML/CSS/JS interface with split view (chat | live preview)
- Agent Server: FastAPI backend that integrates OpenAI API with MCP tools
- MCP Server: AEnvironment MCP server providing tools via Model Context Protocol
- Tools:
read_file: Read files from virtual file systemwrite_file: Write files to virtual file systemlist_files: List all files in the VFSexecute_python_code: Execute Python code snippets for validationvalidate_html: Validate HTML structure and syntaxcheck_responsive_design: Analyze CSS for responsive design compliance
- Python 3.8+ installed
- AEnvironment SDK installed (
pip install aenvironment) - OpenAI API Key (required for AI chat functionality)
- Node.js and npm (for MCP Inspector, installed automatically by
aenv run)
- Install Python dependencies:
pip install -r environment/requirements.txt- Set environment variables:
export OPENAI_API_KEY='your-api-key-here'
export OPENAI_MODEL='gpt-4' # Optional, defaults to gpt-4
export OPENAI_BASE_URL='https://api.openai.com/v1' # Optional, for custom endpoints
export AENV_ENV_NAME='mini-program@1.0.0' # Optional, environment nameOpen a terminal and navigate to the environment directory:
cd environment
aenv runThis will:
- Start the AEnvironment MCP server
- Load tools from
environment/src/ - Start the MCP Inspector (available at
http://localhost:6274)
Keep this terminal running.
Open a new terminal and navigate to the agent directory:
cd agent
python agent_server.pyThis will:
- Start the FastAPI server on port 8080
- Connect to the MCP server for tool access
- Enable the web interface
Keep this terminal running.
Open your browser and navigate to:
http://localhost:8080
- Type your request in the chat input (e.g., "Create a simple counter mini program")
- The AI agent will:
- Analyze your request
- Use tools to read existing files (if any)
- Create or modify files as needed
- Generate complete HTML/CSS/JavaScript applications
- The Live Preview will automatically update to show your generated application
- Click the "🔄 Refresh" button to manually refresh the preview
User: "Create a simple counter mini program"
Agent Actions:
- Uses
list_filesto check existing files - Creates
index.htmlwith HTML structure, CSS styling, and JavaScript logic - Uses
validate_htmlto check for errors - Uses
check_responsive_designto ensure responsive layout - Preview automatically updates
Result: A fully functional counter application appears in the Live Preview.
User: "Add a reset button to the counter"
Agent Actions:
- Uses
read_fileto read the existingindex.html - Modifies the file to add a reset button
- Increments the version number displayed on the page
- Preview updates automatically
Result: The counter now includes a reset button.
User: "Create a Snake game"
Agent Actions:
- Plans the game structure (HTML canvas, game logic, controls)
- Creates
index.htmlwith complete game implementation - Ensures responsive design (scales to fit preview window)
- Adds version number tracking
- Preview shows the playable game
Result: A fully playable Snake game in the Live Preview.
- User Input: Type a natural language request in the chat
- Agent Planning: AI agent analyzes the request and plans the implementation
- Tool Execution: Agent uses MCP tools to:
- Check existing files (
list_files) - Read files if needed (
read_file) - Create/modify files (
write_file) - Validate code (
validate_html,check_responsive_design) - Execute Python code for calculations (
execute_python_code)
- Check existing files (
- Automatic Preview: System automatically renders the generated HTML in Live Preview
- Iteration: User can provide feedback and continue refining the application
The agent server includes automatic retry logic with exponential backoff for OpenAI API rate limit errors (429):
- Max Retries: 3 attempts
- Initial Delay: 1 second
- Backoff Factor: 2x (delays: 1s, 2s, 4s)
- Max Delay: 60 seconds
- Persistent Storage: Files are stored in
/tmp/code/on disk - In-Memory Cache: Fast access to frequently used files
- Automatic Loading: Existing files are loaded on server startup
- Clear Function: Use
/api/clearendpoint to reset the VFS
The agent is instructed to:
- Use viewport-relative units (vw, vh, %, clamp)
- Ensure content fits without scrolling
- Scale canvas elements dynamically
- Use flexible layouts (flexbox, grid)
Every generated index.html includes a visible version number that increments with each modification, helping users verify that updates are working correctly.
GET /: Serve the main HTML interfacePOST /api/chat: Send chat messages and receive AI responsesGET /api/files: List all files in VFSGET /api/files/{file_path}: Get file contentPOST /api/files/{file_path}: Save file contentPOST /api/clear: Clear all files from VFSGET /health: Health check endpointWebSocket /ws: Real-time communication (for future use)
OPENAI_API_KEY(required): Your OpenAI API keyOPENAI_MODEL(optional): Model to use (default: "gpt-4")OPENAI_BASE_URL(optional): Custom API endpoint URLAENV_ENV_NAME(optional): Environment name (default: "mini-program@1.0.0")
environment/config.json: AEnvironment project metadataenvironment/Dockerfile: Container build configurationenvironment/requirements.txt: Python dependencies
- Ensure you're in the
environmentdirectory when runningaenv run - Check that
environment/src/contains the tool files - Verify AEnvironment SDK is installed:
pip list | grep aenv
- Ensure the MCP server is running first
- Check that
AENV_ENV_NAMEmatches the environment name - Verify OpenAI API key is set correctly
- Ensure you're running
agent_server.pyfrom theagent/directory - Check that
frontend/directory exists at the project root - Verify FastAPI is serving static files (check server logs)
- The system automatically retries with exponential backoff
- If errors persist, check your OpenAI API quota
- Consider using a different model or reducing request frequency
The project includes basic functionality tests. Run tests using pytest or your preferred testing framework.
┌─────────────────────────────────────────────────────────┐
│ Browser (User) │
│ http://localhost:8080 │
└────────────────────┬────────────────────────────────────┘
│ HTTP/WebSocket
┌────────────────────▼────────────────────────────────────┐
│ Agent Server (FastAPI) │
│ Port: 8080 │
│ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ OpenAI API Client │ │
│ │ - Chat Completions │ │
│ │ - Tool Calling │ │
│ │ - Retry Logic (429 handling) │ │
│ └──────────────┬───────────────────────────────────┘ │
│ │ HTTP API │
│ ┌──────────────▼───────────────────────────────────┐ │
│ │ MCP Client │ │
│ │ - Tool Discovery │ │
│ │ - Tool Execution │ │
│ └──────────────┬───────────────────────────────────┘ │
└─────────────────┼───────────────────────────────────────┘
│ MCP Protocol (HTTP)
┌─────────────────▼───────────────────────────────────────┐
│ AEnvironment MCP Server │
│ Port: 8081 │
│ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ MCP Tools (from environment/src/) │ │
│ │ - read_file │ │
│ │ - write_file │ │
│ │ - list_files │ │
│ │ - execute_python_code │ │
│ │ - validate_html │ │
│ │ - check_responsive_design │ │
│ └──────────────┬───────────────────────────────────┘ │
│ │ │
│ ┌──────────────▼───────────────────────────────────┐ │
│ │ Virtual File System (VFS) │ │
│ │ Storage: /tmp/code/ │ │
│ │ - Persistent on disk │ │
│ │ - In-memory cache │ │
│ └──────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────┘
agent/: Agent server code (FastAPI application)environment/src/: MCP tools implementationfrontend/: Web UI filestest_*.py: Test scripts for verification
- Create a new tool function in
environment/src/mini_program_tools.py - Use the
@register_tooldecorator - Restart the MCP server (
aenv run) - The tool will be automatically available to the agent
- Edit files in
frontend/directory - Changes take effect immediately (no rebuild needed)
- Refresh the browser to see updates
Copyright 2025. Licensed under the Apache License, Version 2.0.
For issues or questions:
- Check the troubleshooting section above
- Review server logs for error messages
- Verify all prerequisites are installed
- Ensure environment variables are set correctly