Skip to main content

API-agnostic agentic Python package with configurable providers

Project description

Flexai

An API-agnostic agentic Python package that provides Cursor/Replit-like functionality with configurable API providers. Build your own AI coding assistant that works with any OpenAI-compatible API!

Features

  • ๐Ÿ”— API Agnostic: Works with OpenAI, local models, or any API following OpenAI format
  • ๐Ÿค– Intelligent Agent: Code generation, chat, analysis, debugging, and explanation capabilities
  • ๐Ÿ“ Project-Aware Workflows: Analyzes entire codebases and maintains context with agent.md files
  • โš™๏ธ Multi-Provider: Easy switching between different API providers (OpenAI, local LLMs, etc.)
  • ๐Ÿ–ฅ๏ธ Rich CLI: Beautiful terminal interface with syntax highlighting and markdown rendering
  • ๐Ÿ”’ Safe Execution: Sandboxed code execution with timeout protection for Python, JavaScript, and Bash
  • ๐Ÿ“ Persistent Context: Maintains chat history and project context across sessions
  • ๐ŸŽจ Professional Output: Rich terminal formatting with code syntax highlighting

Quick Start

1. Installation

Option A: Using uv (Recommended)

# Clone the repository
git clone https://github.com/kelleyblackmore/Flexai.git
cd Flexai

# Install uv if you don't have it
curl -LsSf https://astral.sh/uv/install.sh | sh

# Set up the project with uv
uv sync

# Set up OpenAI API key (get one from https://platform.openai.com)
export OPENAI_API_KEY="your-api-key-here"

# Quick setup with OpenAI
uv run python scripts/test_flexai.py

Option B: Using pip

# Clone the repository
git clone https://github.com/kelleyblackmore/Flexai.git
cd Flexai

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

# Install dependencies
pip install -e .

# Set up OpenAI API key (get one from https://platform.openai.com)
export OPENAI_API_KEY="your-api-key-here"

# Quick setup with OpenAI
python scripts/test_flexai.py

2. Try the Examples

# Run the complete workflow demo
uv run python examples/demo.py

# Try the Ollama integration demo
uv run python examples/example_workflow.py

# Test with the sample project
cd examples/example_project
uv run python main.py

2. Basic Usage

# List available commands
python main.py --help

# Start interactive chat
python main.py chat

# Generate code
python main.py generate "Create a web scraper in Python"

# List configured providers
python main.py list

# Execute a code file
python main.py execute my_script.py

๐Ÿš€ Enhanced Project Workflow (NEW!)

The most powerful feature - project-aware AI that understands your entire codebase:

# Analyze and work on any project with full context
python flexai.py project --dir ./my-app --task "update README with installation instructions"
python flexai.py project --dir ./backend --task "refactor user authentication module"  
python flexai.py project --dir ./frontend --task "add dark mode toggle component"

๐Ÿ“ Project Structure

flexai/
โ”œโ”€โ”€ docs/                    # ๐Ÿ“š Documentation
โ”‚   โ”œโ”€โ”€ README.md           # Documentation index
โ”‚   โ”œโ”€โ”€ WORKFLOW_GUIDE.md   # Complete user guide
โ”‚   โ”œโ”€โ”€ IMPLEMENTATION_SUMMARY.md # Technical overview
โ”‚   โ””โ”€โ”€ GIT_SETUP.md        # Development setup
โ”œโ”€โ”€ examples/               # ๐ŸŽฏ Examples and demos
โ”‚   โ”œโ”€โ”€ demo.py            # Complete workflow demo
โ”‚   โ”œโ”€โ”€ example_workflow.py # Ollama integration demo
โ”‚   โ”œโ”€โ”€ example_project/   # Sample project for testing
โ”‚   โ””โ”€โ”€ README.md          # Examples guide
โ”œโ”€โ”€ scripts/               # ๐Ÿ› ๏ธ Utility scripts
โ”‚   โ”œโ”€โ”€ test_workflow.py   # Comprehensive test suite
โ”‚   โ””โ”€โ”€ README.md          # Scripts guide
โ”œโ”€โ”€ flexai/                # ๐Ÿ“ฆ Main package
โ”œโ”€โ”€ tests/                 # ๐Ÿงช Core tests
โ”œโ”€โ”€ flexai.py             # ๐Ÿš€ CLI entry point
โ””โ”€โ”€ README.md             # ๐Ÿ“– This file

What makes this special:

๐Ÿ” Automatic Project Analysis

  • Crawls entire project structure and key files
  • Detects dependencies and tech stack (Python, Node.js, etc.)
  • Analyzes README, package.json, requirements.txt, and config files

๐Ÿ“Š Git Integration

  • Checks current branch and recent commits
  • Identifies uncommitted changes
  • Provides git context to AI for better understanding

๐Ÿ“ Agent Context Management

  • Creates and maintains agent.md files for project-specific context
  • Tracks previous tasks and decisions
  • Provides persistent project memory across sessions

๐Ÿค– Enhanced AI Understanding

  • AI receives complete project context before executing tasks
  • Understands existing patterns, dependencies, and architecture
  • Makes informed decisions that fit with your codebase

Example Project Workflow:

# The AI will automatically:
# 1. Analyze your project structure and dependencies
# 2. Check git status and recent changes  
# 3. Read existing documentation and patterns
# 4. Create/update agent.md with project context
# 5. Execute your task with full understanding
# 6. Update agent.md with completion notes

python flexai.py project --dir ./my-web-app --task "add user authentication system"

Advanced Configuration

Multiple API Providers

You can configure multiple providers and switch between them:

# Configure OpenAI
python main.py configure
# Provider name: openai
# API Key: your-openai-key
# Base URL: https://api.openai.com/v1
# Model: gpt-4o-mini

# Configure a local model (e.g., Ollama)
python main.py configure
# Provider name: local
# API Key: not-needed
# Base URL: http://localhost:11434/v1
# Model: llama2

# Switch between providers
python main.py switch local
python main.py switch openai

Programmatic Usage

from flexai.config import Config
from flexai.agent import Agent

# Initialize
config = Config()
agent = Agent(config)

# Chat
response = agent.chat("Explain recursion in Python")

# Generate code
code = agent.generate_code("Sort a list using quicksort", "python")

# Analyze code
analysis = agent.analyze_code(code, "python")

# Execute code safely
result = agent.execute_code(code, "python")

Supported Providers

  • OpenAI: GPT-4, GPT-4o, GPT-3.5-turbo
  • Local Models: Ollama, LM Studio, or any OpenAI-compatible endpoint
  • Other Services: Any API that follows OpenAI's chat completions format

Core Capabilities

1. Code Generation

Generate complete, production-ready code in multiple languages:

  • Python, JavaScript, Go, Rust, and more
  • Includes proper documentation and error handling
  • Follows language-specific best practices

2. Code Analysis & Review

  • Quality assessment and bug detection
  • Performance optimization suggestions
  • Security vulnerability scanning
  • Best practice recommendations

3. Interactive Debugging

  • Error explanation and fix suggestions
  • Step-by-step debugging guidance
  • Code improvement recommendations

4. Safe Code Execution

  • Sandboxed execution environment
  • Timeout protection (30s default)
  • Support for Python, JavaScript, and Bash
  • Automatic cleanup of temporary files

5. Multi-Provider Support

  • Easy switching between API providers
  • Fallback options for reliability
  • Cost optimization through provider selection

Examples

Chat Mode

$ python main.py chat
๐Ÿ’ฌ Chat Mode - Type 'exit' to quit

You: How do I implement a binary search tree in Python?

Agent: I'll help you implement a binary search tree in Python. Here's a complete implementation...

Code Generation

$ python main.py generate "Create a REST API using Flask"

Code Execution

$ python main.py execute fibonacci.py

Configuration File

Agentix stores configuration in ~/.agentix/config.yaml:

active_provider: openai
providers:
  openai:
    api_key: your-key-here
    base_url: https://api.openai.com/v1
    model: gpt-4o-mini
  local:
    api_key: not-needed
    base_url: http://localhost:11434/v1
    model: llama2

๐Ÿ“š Documentation

๐Ÿงช Testing

# Run the comprehensive test suite
uv run python scripts/test_workflow.py

# Run core tests
uv run pytest tests/

# Run specific test categories
uv run pytest scripts/test_workflow.py::TestConfiguration -v

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Quick Start for Contributors

# Fork and clone the repository
git clone https://github.com/your-username/Flexai.git
cd Flexai

# Set up development environment
uv sync

# Run tests
uv run pytest tests/

# Make your changes and submit a PR

Development Tools

# Code formatting
uv run black .

# Linting
uv run ruff check .

# Type checking
uv run mypy flexai/

# Security scan
uv run bandit -r flexai/

๐Ÿš€ CI/CD Status

Test Release

Our CI/CD pipeline includes:

  • โœ… Automated Testing - Runs on Python 3.11, 3.12, 3.13
  • โœ… Code Quality - Linting, formatting, and type checking
  • โœ… Security Scanning - Vulnerability and security checks
  • โœ… Automated Publishing - PyPI releases on GitHub releases

License

MIT License - see LICENSE file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flexai_agent-0.1.0-py3-none-any.whl (31.0 kB view details)

Uploaded Python 3

File details

Details for the file flexai_agent-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flexai_agent-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 31.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for flexai_agent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae35564fadcc33b08314ed543638058e4249128d848879f355985ee814f33a65
MD5 b4be40f7e398a7820bb15189d1da7625
BLAKE2b-256 a363797356f71c10ee6cf29aa59ad01cd2e84a520736ae631086d8bf9a63b6f4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page