A comprehensive AI-powered programming assistant for the Flex programming language, featuring 400+ AI models from OpenRouter, intelligent code generation, and advanced CLI interface.
- 400+ AI Models via OpenRouter.ai (Claude, GPT-4, Llama, Qwen, and more)
- Dynamic Model Switching - Choose the best model for your task
- Intelligent Model Selection - Get recommendations based on task complexity
- Cost Optimization - Filter models by price and features
- Dual Syntax Support - Franco Arabic (
karr,etb3,l7d) and English (for,print,while) - Franco Loop Safety - Automatic detection and correction of inclusive loop bounds
- Syntax Detection - Automatically identifies and adapts to your preferred style
- Code Validation - Real-time validation against Flex language specification
- Rich Terminal UI - Beautiful, responsive interface with syntax highlighting
- Interactive Model Browser - Browse, search, and filter 400+ models
- Real-time Code Execution - Execute Flex programs directly from the CLI
- Conversation History - Persistent context across your programming session
- Smart Command System - Intuitive commands for all operations
- Comprehensive Error Handling - Graceful failure recovery and detailed error messages
- Security Validation - File operation security and input sanitization
- Performance Monitoring - Model usage metrics and cost tracking
- Async Architecture - Non-blocking operations for responsive experience
- Extensive Testing - 85%+ test coverage with comprehensive test suite
- Python 3.8 or higher
- OpenRouter API Key (get one free at openrouter.ai)
- Flex CLI (optional, for code execution)
# Clone the repository
git clone https://github.com/your-username/flex-ai-agent.git
cd flex-ai-agent
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt# Copy environment template
cp .env.example .env
# Edit .env and add your OpenRouter API key
nano .env # or your preferred editorRequired in .env:
OPENROUTER_API_KEY=your_openrouter_api_key_herepython main.py๐ You're ready to code with AI assistance!
| Command | Description | Example |
|---|---|---|
help |
Show help information | help |
models |
Interactive model selection | models |
switch <model> |
Switch to specific model | switch anthropic/claude-3-5-sonnet |
examples |
Show Flex code examples | examples |
validate <code> |
Validate Flex code | validate "etb3('hello')" |
execute <code> |
Execute Flex code | execute "karr i=0 l7d 9 { etb3(i) }" |
clear |
Clear conversation history | clear |
history |
Show conversation history | history |
settings |
Show current settings | settings |
exit / quit |
Exit application | exit |
Franco Arabic syntax uses culturally familiar keywords:
// Variables
rakm number = 42 // Integer
kasr decimal = 3.14 // Float
klma text = "Marhaba" // String
so2al flag = sa7 // Boolean (sa7=true, ghalt=false)
dorg list = [1, 2, 3] // Array
// Safe Franco loops (CRITICAL: notice the -1 for safety)
karr i=0 l7d length(list) - 1 {
etb3("Item " + i + ": " + list[i])
}
// Conditionals
lw number > 10 yalla
etb3("Number is greater than 10")
gher yalla
etb3("Number is 10 or less")
safi
// Functions
sndo2 greet(klma name) {
etb3("Ahlan wa sahlan, " + name + "!")
}
greet("Ahmed")English syntax follows familiar programming conventions:
// Variables
int number = 42
float decimal = 3.14
string text = "Hello"
bool flag = true
list array = [1, 2, 3]
// Standard loops
for(i=0; i<length(array); i++) {
print("Item " + i + ": " + array[i])
}
// Conditionals
if(number > 10) {
print("Number is greater than 10")
} else {
print("Number is 10 or less")
}
// Functions
fun greet(string name) {
print("Hello, " + name + "!")
}
greet("Alice")Choose from 400+ models based on your needs:
# Interactive model browser
> models
๐ Loading available models...
[Interactive selection menu appears]
# Direct model switching
> switch anthropic/claude-3-5-sonnet
โ
Switched to model: anthropic/claude-3-5-sonnet
# Get model recommendations
> models
โญ Recommended Models for Flex ProgrammingModel Categories:
- Free Models:
qwen/qwen-14b:free,meta-llama/llama-3.1-8b-instruct:free - Balanced:
anthropic/claude-3-5-haiku,openai/gpt-4o-mini - Premium:
anthropic/claude-3-5-sonnet,openai/gpt-4o - Specialized:
deepseek/deepseek-coder,meta-llama/codellama-70b-instruct
Create a .env file with these options:
# === OpenRouter Configuration ===
OPENROUTER_API_KEY=your_openrouter_api_key_here
OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
OPENROUTER_HTTP_REFERER=https://github.com/your-repo
OPENROUTER_APP_TITLE=Flex AI Agent
# === Flex Language Settings ===
FLEX_CLI_PATH=flex
FLEX_EXAMPLES_DIR=./flex_examples
FLEX_TEMP_DIR=./temp
FLEX_FILE_EXTENSIONS=.flex,.flx
# === Application Settings ===
MAX_CODE_LENGTH=500
EXECUTION_TIMEOUT=30
ENABLE_FILE_OPERATIONS=true
MODEL_CACHE_DURATION=3600
DEFAULT_MODEL=anthropic/claude-3-5-sonnet
# === Cost Optimization ===
ENABLE_COST_OPTIMIZATION=true
DAILY_BUDGET_LIMIT=10.0
PREFER_FREE_MODELS=false
# === Development ===
DEBUG=false
LOG_LEVEL=INFO
ENABLE_METRICS=false# Start interactive mode (default)
python main.py
# Show available models
python main.py --models
# Validate a Flex file
python main.py --validate examples/hello_world.flex
# Execute a Flex file
python main.py --execute examples/hello_world.flex
# Generate code from command line
python main.py --generate "create a Franco loop that prints numbers 1 to 10"
# Show help
python main.py --help> generate a safe Franco loop that prints array elements
๐ค Assistant: I'll create a safe Franco loop for you. Notice the crucial `- 1`
to prevent out-of-bounds errors since Franco loops are INCLUSIVE.
```flex
// Safe Franco array iteration
dorg myArray = ["apple", "banana", "cherry", "date"]
karr i=0 l7d length(myArray) - 1 {
etb3("Element " + i + ": " + myArray[i])
}โ
This is safe because Franco l7d loops are inclusive, so using
length(myArray) - 1 ensures we don't exceed array bounds.
### Error Detection and Fixing
```bash
> validate this code: karr i=0 l7d length(arr) { etb3(arr[i]) }
๐ค Assistant: โ Code validation failed
**Critical Franco Loop Safety Error:**
- Line 1: Franco l7d loop will cause out-of-bounds access
- Fix: Change `l7d length(arr)` to `l7d length(arr) - 1`
- Reason: Franco loops are INCLUSIVE - they run from start TO end (including end)
**Corrected code:**
```flex
karr i=0 l7d length(arr) - 1 {
etb3(arr[i])
}
### Model Switching
```bash
> switch to a cost-effective model for simple tasks
๐ค Assistant: I'll help you switch to a cost-effective model perfect for simple tasks.
๐ Cost-Effective Models:
โข qwen/qwen-14b:free - FREE, great for basic code generation
โข meta-llama/llama-3.1-8b-instruct:free - FREE, good for explanations
โข anthropic/claude-3-5-haiku - $0.00025/1K tokens, fast and efficient
> switch qwen/qwen-14b:free
โ
Switched to model: qwen/qwen-14b:free
This model is perfect for:
- Simple code generation
- Basic debugging help
- Learning Flex syntax
- Cost-conscious development
flex_code/
โโโ agents/ # AI agent components
โ โโโ __init__.py # Package initialization
โ โโโ flex_agent.py # Main Flex AI agent
โ โโโ models.py # Pydantic data models
โ โโโ providers.py # OpenRouter provider config
โโโ tools/ # Agent tools
โ โโโ __init__.py # Package initialization
โ โโโ model_manager.py # OpenRouter model management
โ โโโ flex_executor.py # Flex code execution
โ โโโ file_manager.py # File operations
โ โโโ code_validator.py # Flex code validation
โโโ ui/ # User interface
โ โโโ __init__.py # Package initialization
โ โโโ cli.py # Main CLI interface
โ โโโ model_selector.py # Interactive model selection
โ โโโ formatters.py # Output formatting
โโโ config/ # Configuration
โ โโโ __init__.py # Package initialization
โ โโโ settings.py # Settings management
โโโ tests/ # Test suite (85%+ coverage)
โ โโโ test_flex_agent.py # Agent tests
โ โโโ test_model_manager.py # Model management tests
โ โโโ test_file_manager.py # File operation tests
โ โโโ test_code_validator.py# Validation tests
โ โโโ test_flex_executor.py # Execution tests
โ โโโ test_model_selector.py# UI tests
โ โโโ test_cli.py # CLI tests
โโโ flex_examples/ # Example Flex programs
โ โโโ franco_examples/ # Franco syntax examples
โ โ โโโ hello_world.flex # Basic Franco example
โ โ โโโ safe_loops.flex # Franco loop safety demo
โ โ โโโ advanced_patterns.flex # Complex patterns
โ โโโ english_examples/ # English syntax examples
โ โโโ hello_world.flex # Basic English example
โ โโโ advanced_algorithms.flex # Advanced algorithms
โโโ cache/ # Model cache
โ โโโ models_cache.json # Cached model information
โโโ data/ # Language specifications
โ โโโ flex_language_spec.json # Complete Flex spec
โโโ main.py # Entry point
โโโ requirements.txt # Python dependencies
โโโ .env.example # Environment template
โโโ README.md # This file
# Run all tests with coverage
pytest tests/ -v --cov=agents --cov=tools --cov=ui --cov-report=term-missing
# Run specific test categories
pytest tests/test_flex_agent.py -v
pytest tests/test_model_manager.py -v
pytest tests/test_code_validator.py -v
# Run tests with detailed output
pytest tests/ -v -s# Format code
black .
# Lint code
ruff check . --fix
# Type checking
mypy .
# Security scanning
bandit -r .# Install development dependencies
pip install -r requirements.txt
# Install pre-commit hooks
pre-commit install
# Run pre-commit checks
pre-commit run --all-filesSolution:
- Check your
.envfile contains:OPENROUTER_API_KEY=your_actual_key - Verify your API key at openrouter.ai/keys
- Ensure you have sufficient credits
Solution:
- Install Flex CLI:
npm install -g flex-cli(or your system's method) - Set custom path:
FLEX_CLI_PATH=/path/to/flexin.env - Disable execution:
ENABLE_FILE_OPERATIONS=falsein.env
Solution:
- Check internet connection
- Verify API key permissions
- Try refreshing: Type
modelsin CLI and select "Refresh model cache"
This is intentional! Franco loops are inclusive. Always use:
// โ
SAFE: Use length - 1
karr i=0 l7d length(array) - 1 { ... }
// โ UNSAFE: Will cause out-of-bounds
karr i=0 l7d length(array) { ... }Solution:
- Use free models:
qwen/qwen-14b:freeormeta-llama/llama-3.1-8b-instruct:free - Enable cost optimization:
ENABLE_COST_OPTIMIZATION=true - Set budget limit:
DAILY_BUDGET_LIMIT=5.0
Enable debug mode for detailed logging:
# In .env file
DEBUG=true
LOG_LEVEL=DEBUG
ENABLE_METRICS=true# Reduce model cache duration
MODEL_CACHE_DURATION=1800 # 30 minutes
# Disable file operations
ENABLE_FILE_OPERATIONS=false
# Use faster models
DEFAULT_MODEL=anthropic/claude-3-5-haikuWe welcome contributions! Please see our Contributing Guidelines.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- ๐ง New Model Integrations - Add support for more AI providers
- ๐ Flex Language Features - Enhanced syntax support and validation
- ๐ป UI Improvements - Better CLI experience and formatting
- ๐งช Testing - Increase test coverage and add integration tests
- ๐ Documentation - More examples and tutorials
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenRouter - For providing access to 400+ AI models
- PydanticAI - For the excellent AI agent framework
- Rich - For beautiful terminal interfaces
- Flex Language - For the innovative dual-syntax programming language
- ๐ Documentation: Full Documentation
- ๐ฌ Discussions: GitHub Discussions
- ๐ Issues: GitHub Issues
- ๐ง Email: support@your-domain.com
- ๐ฎ Multi-Agent Systems - Collaborative AI agents for complex projects
- ๐ Web Interface - Browser-based IDE with real-time collaboration
- ๐ฑ Mobile Support - Native mobile apps for on-the-go coding
- ๐ Learning Mode - Interactive tutorials and guided programming lessons
- ๐ IDE Integration - VS Code, IntelliJ, and other IDE plugins
Made with โค๏ธ by the Flex AI Agent Team
โญ Star this project | ๐ด Fork it | ๐ Read the docs
Empowering developers with AI-assisted Flex programming