Skip to content

SmolD is a sophisticated yet lightweight command-line code assistant that combines the power of Gemini 2.5 Large Language Models with a comprehensive suite of development tools.

License

Notifications You must be signed in to change notification settings

fabiopauli/smold-gemini

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SmolD

A Lightweight Code Assistant with Powerful Tool Integration

Python 3.11+ License: MIT Tests GitHub Issues

Built on HuggingFace's smolagents framework with Google Gemini 2.5 Flash integration


πŸ“‘ Table of Contents


πŸš€ Quick Start

Get SmolD running in under 5 minutes:

# 1. Clone and enter directory
git clone https://github.com/fabiopauli/smold-gemini.git && cd smold-gemini

# 2. Create virtual environment and activate
python -m venv venv && source venv/bin/activate  # Unix/Linux/macOS
# python -m venv venv && venv\Scripts\activate   # Windows

# 3. Install dependencies (using uv for speed)
pip install uv && uv pip install -e .

# 4. Set your API key
echo "GEMINI_API_KEY=your_key_here" > .env

# 5. Start coding assistance!
python main.py -i

Need help? See our detailed installation guide or report issues.


πŸš€ Overview

SmolD is a sophisticated yet lightweight command-line code assistant that combines the power of Large Language Models with a comprehensive suite of development tools. Whether you're exploring codebases, refactoring code, running tests, or managing files, SmolD provides an intelligent interface that understands context and executes tasks efficiently.

✨ Key Features

  • 🧠 Intelligent Code Understanding - Deep codebase analysis and context-aware responses
  • πŸ’­ Advanced Context Management - Remembers last 8 interactions with automatic token management under 100k
  • πŸ›οΈ Council of AI Specialists - Multi-model consultation system (OpenAI o4-mini, Gemini 2.5 Pro, DeepSeek Reasoner)
  • πŸ› οΈ Comprehensive Tool Suite - File operations, search, shell commands, and more
  • πŸ–₯️ Cross-Platform Support - Works seamlessly on Windows (PowerShell) and Unix (Bash)
  • ⚑ Interactive & Batch Modes - Flexible usage patterns for different workflows
  • πŸ” Advanced Search Capabilities - Regex-powered content search and glob pattern matching
  • πŸ“ Smart Directory Management - Context-aware file and directory operations
  • πŸ”’ Security-First Design - Built-in command filtering and safety measures
  • πŸ§ͺ Comprehensive Testing - 43+ unit tests ensuring reliability across platforms

πŸ—οΈ Architecture

SmolD leverages a modular architecture built around three core components:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   CLI Interface β”‚    β”‚   Agent Core     β”‚    β”‚   Tool System   β”‚
β”‚                 │─ ─▢│                  │───▢│                 β”‚
β”‚ β€’ Interactive   β”‚    β”‚ β€’ Gemini 2.5Flashβ”‚    β”‚ β€’ Platform-     β”‚
β”‚ β€’ Single Query  β”‚    β”‚ β€’ LiteLLM        β”‚    β”‚   specific      β”‚
β”‚ β€’ Directory     β”‚    β”‚ β€’ Context Mgmt   β”‚    β”‚ β€’ Extensible    β”‚
β”‚   Context       β”‚    β”‚ β€’ System Prompt  β”‚    β”‚ β€’ Type-safe     β”‚
β”‚ β€’ AI Council    β”‚    β”‚ β€’ Memory (4 int) β”‚    β”‚ β€’ 10 Tools      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”§ Available Tools

Tool Platform Description Use Cases
BashTool Unix/Linux Execute bash commands with persistent sessions Running scripts, git operations, system commands
PowerShellTool Windows Execute PowerShell commands with safety checks Windows-specific tasks, administration, file operations
EditTool All Precise file editing with string replacement Code refactoring, bug fixes, content updates
ViewTool All Read files with line numbers and pagination Code review, file inspection, content analysis
GrepTool All Advanced regex-based content search Finding functions, classes, patterns in code
GlobTool All File pattern matching with recursive search Locating files by name, extension, or path patterns
LSTool All Tree-structured directory listings Project exploration, file structure analysis
ReplaceTool All Create or completely replace file contents Template generation, file creation
CDTool All Smart directory navigation with error handling Workspace navigation, path management
UserInputTool All Interactive user prompts during execution Confirmation dialogs, parameter collection

πŸ›οΈ Council of AI Specialists

SmolD includes a powerful consultation system that leverages multiple AI models for superior advice:

# Consult the Council of AI Specialists
python smold/council.py --prompt "How can I optimize this React component for performance?"

# Include context from files
python smold/council.py --context-file "component.jsx" --prompt "Review this code"

# Add additional context
python smold/council.py --context "Using React 18" --prompt "Best practices for state management"

Council Members:

  • OpenAI o4-mini - General software engineering expertise and reasoning
  • Gemini 2.5 Pro - Advanced reasoning with Google Search capabilities
  • DeepSeek Reasoner - Deep analytical reasoning and complex problem solving

The council runs parallel consultations and provides a comprehensive report with insights from all three specialists, helping you make more informed technical decisions.

πŸ“¦ Installation

Prerequisites

  • Python 3.11 or higher - Required for modern async support and type hints
    • Tested on Python 3.11, 3.12, and 3.13
    • Older versions (3.10 and below) are not supported
  • Google Gemini API Key - Get yours at Google AI Studio
    • πŸ”’ Security Note: Never commit API keys to version control
    • Use .env files or environment variables for key management
  • Git (optional) - For enhanced git repository features and project cloning

Quick Setup

  1. Clone and Navigate

    git clone https://github.com/fabiopauli/smold-gemini.git
    cd smold-gemini
  2. Environment Setup

    # Create virtual environment
    python -m venv venv
    
    # Activate (Unix/Linux/macOS)
    source venv/bin/activate
    
    # Activate (Windows)
    venv\Scripts\activate
  3. Install Dependencies

    Option A: Using uv (recommended - faster)

    # Install uv if you haven't already
    pip install uv
    
    # Install dependencies and SmolD
    uv pip install -e .

    Option B: Using pip (traditional)

    # Install from requirements.txt
    pip install -r requirements.txt
    
    # Install SmolD in development mode
    pip install -e .
  4. Configure API Access πŸ”’

    # Create .env file with required API keys (SECURE METHOD)
    echo "GEMINI_API_KEY=your_gemini_key_here" > .env
    echo "OPENAI_API_KEY=your_openai_key_here" >> .env  # For council.py
    echo "GEMINI_API_KEY=your_gemini_key_here" >> .env  # For council.py
    
    # Set proper permissions (Unix/Linux/macOS)
    chmod 600 .env
    
    # Verify .env is in .gitignore (important!)
    echo ".env" >> .gitignore

    πŸ” Security Best Practices:

    • βœ… Use .env files for local development
    • βœ… Set environment variables in production
    • βœ… Never commit API keys to version control
    • βœ… Rotate keys regularly
    • ❌ Don't hardcode keys in source code

🎯 Usage Guide

Command-Line Interface

Single Query Mode

# Analyze current directory
python main.py "What files are in this project?"

# Code analysis
python main.py "Find all TODO comments in Python files"

# Refactoring assistance
python main.py "Rename the function 'old_name' to 'new_name' in utils.py"

Interactive Mode (now with conversation memory!)

# Start interactive session with context retention
python main.py -i

# Session in specific directory
python main.py --cwd /path/to/project -i

# Use new context management commands:
# - "context" to view conversation state and token usage
# - "clear" to reset conversation history

Directory-Specific Operations

# Run query in specific directory
python main.py --cwd ./src "List all TypeScript files"

# Automatic context switching
python main.py --cwd ~/projects/myapp "Run the test suite"

πŸ’‘ Example Use Cases

πŸ” Codebase Exploration
# Understand project structure
> "Analyze this codebase and explain its architecture"

# Find specific implementations
> "Where is the user authentication logic implemented?"

# Locate configuration files
> "Find all configuration files in this project"
πŸ› οΈ Development Tasks
# Refactoring
> "Rename all instances of 'getUserData' to 'fetchUserProfile'"

# Bug fixing
> "Find and fix the syntax error in main.py"

# Code quality
> "Add type hints to all functions in the utils module"
πŸ§ͺ Testing & CI/CD
# Run tests
> "Execute the test suite and show results"

# Check code quality
> "Run linting and type checking"

# Build processes
> "Build the project and handle any errors"
πŸ“ File Management
# Bulk operations
> "Create a .gitignore file for a Python project"

# Content generation
> "Generate a basic setup.py file for this package"

# Documentation
> "Create API documentation for all public functions"

πŸŽ›οΈ Advanced Features

Enhanced Context Management

  • Conversation Memory: Remembers last 4 interactions for better continuity
  • Smart Token Management: Automatically manages context under 100k tokens using tiktoken
  • Project Context: Automatically includes directory structure and git status in system prompt
  • Dynamic Context: Updates context when changing directories with cd command

Interactive Commands

# Context management in interactive mode
> context     # View current conversation state and token usage
> clear       # Clear conversation history to start fresh
> cd <path>   # Change directory and update agent context
> help        # Show all available commands and capabilities

Smart Command Recognition

# These all work naturally:
> "ls"                    # Lists current directory
> "dir"                   # Windows directory listing  
> "git status"            # Git repository status
> "npm test"              # Run Node.js tests
> "pytest"               # Run Python tests

Safety Features

  • Automatic command validation and safety checks
  • Banned command filtering (prevents dangerous operations)
  • Confirmation prompts for destructive actions
  • Sandbox-aware execution environment

πŸ§ͺ Testing

SmolD includes a comprehensive test suite covering all tools and platforms:

# Run all tests
python smold/run_tool_tests.py

# Run specific tool tests
python smold/run_tool_tests.py --tool bash

# Verbose output
python smold/run_tool_tests.py --verbose

# Alternative test runner
python -m unittest discover smold/tools/tests/

Test Coverage

  • βœ… 43 total tests across all tools
  • βœ… Cross-platform compatibility testing
  • βœ… Error handling and edge cases
  • βœ… Security and safety feature validation
  • βœ… Performance and timeout testing

πŸ›οΈ Project Structure

smold/
β”œβ”€β”€ πŸ“ smold/                    # Core package
β”‚   β”œβ”€β”€ πŸ”§ agent.py              # Enhanced agent with conversation history
β”‚   β”œβ”€β”€ πŸ’­ context_manager.py    # Conversation memory & token management
β”‚   β”œβ”€β”€ πŸ›οΈ council.py            # Multi-model AI consultation system
β”‚   β”œβ”€β”€ πŸ“ system_prompt.py      # Dynamic prompt generation
β”‚   β”œβ”€β”€ πŸ“„ system_message.txt    # Base system message template
β”‚   └── πŸ› οΈ tools/               # Tool implementations
β”‚       β”œβ”€β”€ 🐚 bash_tool.py      # Unix shell commands
β”‚       β”œβ”€β”€ πŸ’» powershell_tool.py # Windows shell commands
β”‚       β”œβ”€β”€ ✏️ edit_tool.py       # File editing
β”‚       β”œβ”€β”€ πŸ‘€ view_tool.py       # File reading
β”‚       β”œβ”€β”€ πŸ” grep_tool.py       # Content search
β”‚       β”œβ”€β”€ πŸ“‚ glob_tool.py       # File pattern matching
β”‚       β”œβ”€β”€ πŸ“‹ ls_tool.py         # Directory listing
β”‚       β”œβ”€β”€ πŸ“ replace_tool.py    # File creation/replacement
β”‚       β”œβ”€β”€ πŸ“ cd_tool.py         # Directory navigation
β”‚       β”œβ”€β”€ πŸ’¬ user_input_tool.py # User interaction
β”‚       └── πŸ§ͺ tests/            # Comprehensive test suite
β”œβ”€β”€ πŸš€ main.py                   # CLI entry point with context commands
β”œβ”€β”€ πŸ§ͺ test_context.py           # Context system test suite
β”œβ”€β”€ βš™οΈ pyproject.toml            # Project configuration
β”œβ”€β”€ πŸ“‹ requirements.txt          # Dependencies
β”œβ”€β”€ πŸ“– README.md                 # This file
β”œβ”€β”€ πŸ“„ LICENSE                   # MIT License
└── πŸ”§ CLAUDE.md                 # Development guidelines

πŸ”§ Configuration

Environment Variables

Variable Required Description Default
GEMINI_API_KEY βœ… Google Gemini API key (main agent) None
OPENAI_API_KEY βšͺ OpenAI API key (for council.py) None
GEMINI_API_KEY βšͺ Google Gemini API key (for council.py) None

πŸ› Troubleshooting

πŸ”‘ API Key Issues

API Key Not Found

# Verify API key is set
echo $GEMINI_API_KEY  # Unix/Linux/macOS
echo %GEMINI_API_KEY% # Windows

# Test API connectivity
python -c "import os; print('Key found' if os.getenv('GEMINI_API_KEY') else 'Key missing')"

# Check .env file exists and has correct format
cat .env | grep GEMINI_API_KEY

API Authentication Errors

# Test your API key validity
curl -H "Authorization: Bearer $DEEPSEEK_API_KEY" \
     -H "Content-Type: application/json" \
     https://api.deepseek.com/v1/models

# If council.py fails, check OpenAI/Gemini keys
python -c "import os; print('OpenAI:', bool(os.getenv('OPENAI_API_KEY'))); print('Gemini:', bool(os.getenv('GEMINI_API_KEY')))"
πŸ› οΈ Installation & Dependency Issues

Virtual Environment Problems

# Recreate virtual environment
rm -rf venv  # Remove existing venv
python -m venv venv

# Activate properly
source venv/bin/activate  # Unix/Linux/macOS
# OR
venv\Scripts\activate     # Windows

# Verify you're in the virtual environment
which python  # Should show path to venv/bin/python

Package Installation Failures

# Update pip first
pip install --upgrade pip

# Clear pip cache
pip cache purge

# Install with verbose output for debugging
pip install -v -e .

# Alternative: Use uv for faster installs
pip install uv && uv pip install -e .

Tool Loading Failures

# Check tool imports
python -c "from smold.agent import get_available_tools; print(len(get_available_tools()))"

# Verbose tool loading
python main.py "test" --verbose

# Check specific tool
python -c "from smold.tools.bash_tool import bash_tool; print('Bash tool OK')"
βš™οΈ Runtime & Performance Issues

Memory/Token Errors

# Check conversation context
python main.py -i
> context  # Shows current token usage

# Clear conversation history
> clear    # Resets context

# Reduce context if needed (edit system_prompt.py)
# Consider using shorter directory structures

Command Execution Issues

# Test bash/powershell directly
bash -c "echo 'Bash test'"        # Unix/Linux/macOS
powershell -c "echo 'PS test'"    # Windows

# Check PATH and permissions
echo $PATH  # Unix/Linux/macOS
echo $env:PATH  # Windows PowerShell

# Verify working directory
pwd && ls -la
πŸ”§ Permission & File Access Errors

File Permission Errors

# Fix script permissions
chmod +x main.py run_tool_tests.sh

# Check file ownership
ls -la main.py smold/

# Run with elevated privileges (if needed)
sudo python main.py "system command"  # Unix/Linux/macOS
# Run PowerShell as Administrator  # Windows

Directory Access Issues

# Check directory permissions
ls -ld $(pwd)

# Verify you can write to current directory
touch test_write && rm test_write

# Use absolute paths if relative paths fail
python main.py --cwd /full/path/to/project "your query"
πŸ–₯️ Platform-Specific Issues

Windows Specific

# PowerShell execution policy issues
Get-ExecutionPolicy
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

# Use 'py' launcher if 'python' doesn't work
py --version
py main.py "your query"

# Path separator issues in file operations
# Use forward slashes even on Windows: "src/main.py"

macOS Specific

# Install Python via Homebrew (recommended)
brew install [email protected]

# Fix zsh/bash compatibility
echo $SHELL  # Check current shell
bash        # Switch to bash if needed

# Xcode command line tools (may be required)
xcode-select --install

Linux Specific

# Ensure bash is available
which bash  # Should return /bin/bash

# Install Python development headers (if needed)
sudo apt-get install python3-dev  # Ubuntu/Debian
sudo yum install python3-devel    # CentOS/RHEL
πŸ†˜ Getting Help

Before Reporting Issues:

  1. βœ… Check this troubleshooting guide
  2. βœ… Verify your Python version: python --version
  3. βœ… Confirm API keys are properly set
  4. βœ… Try running with --debug flag for detailed logs
  5. βœ… Test with a fresh virtual environment

Report Issues:

  • πŸ› GitHub Issues - Bug reports and feature requests
  • πŸ“š Include your OS, Python version, and error messages
  • πŸ” Use --debug output for better diagnostics

Get Verbose Output:

# Maximum debugging information
python main.py --debug --verbose "your query"

# Check agent initialization
python -c "from smold.agent import create_agent; agent = create_agent(); print('Agent created successfully')"

πŸ”— Related Projects

πŸ“„ License

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

πŸ™ Acknowledgments

  • HuggingFace for the excellent smolagents framework
  • Google Gemini for providing powerful and affordable LLM APIs
  • The Python Community for the amazing ecosystem of tools and libraries

🐳 Docker Deployment

SmolD supports containerized deployment for consistent environments and easy distribution across different platforms.

πŸš€ Quick Docker Start

One-Command Setup

Production Dockerfile

Create a Dockerfile in your project root:

# Multi-stage build for smaller image size
FROM python:3.11-slim as builder

# Install build dependencies
RUN apt-get update && apt-get install -y \
    git \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy dependency files first for better layer caching
COPY pyproject.toml ./
COPY requirements.txt ./
COPY uv.lock ./

# Install Python dependencies
# Option 1: Using uv (faster, recommended)
RUN pip install --no-cache-dir uv && \
    uv pip install --system --no-cache-dir -r requirements.txt

# Option 2: Using standard pip (uncomment if you prefer)
# RUN pip install --no-cache-dir --upgrade pip && \
#     pip install --no-cache-dir -r requirements.txt

# Production stage
FROM python:3.11-slim

# Install runtime dependencies
RUN apt-get update && apt-get install -y \
    git \
    bash \
    curl \
    && rm -rf /var/lib/apt/lists/* \
    && useradd -m -u 1000 smold

# Copy installed packages from builder
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin

# Set working directory and copy source
WORKDIR /app
COPY --chown=smold:smold . .

# Install SmolD in development mode
RUN pip install -e .

# Create directories for logs and context
RUN mkdir -p /app/council-logs && \
    chown -R smold:smold /app

# Switch to non-root user
USER smold

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD python -c "from smold import create_agent; print('OK')" || exit 1

# Default command (interactive mode)
CMD ["python", "main.py", "-i"]

Docker Compose Setup

Create a docker-compose.yml for complete environment management:

version: '3.8'

services:
  smold:
    build: .
    container_name: smold-assistant
    environment:
      - DEEPSEEK_API_KEY=${DEEPSEEK_API_KEY}
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - GEMINI_API_KEY=${GEMINI_API_KEY}
    volumes:
      # Mount your project directory for development
      - ./workspace:/workspace
      # Persist conversation logs
      - smold-logs:/app/council-logs
      # Mount .env file for API keys
      - ./.env:/app/.env:ro
    working_dir: /workspace
    stdin_open: true
    tty: true
    restart: unless-stopped

volumes:
  smold-logs:
    driver: local

Building and Running

Quick Start:

# Build the image
docker build -t smold:latest .

# Run interactive session
docker run -it --rm \
  -e DEEPSEEK_API_KEY=your_key_here \
  -v $(pwd):/workspace \
  smold:latest

# Run single query
docker run --rm \
  -e DEEPSEEK_API_KEY=your_key_here \
  -v $(pwd):/workspace \
  smold:latest python main.py "What files are in this directory?"

Using Docker Compose:

# Start the service
docker-compose up -d

# Access interactive mode
docker-compose exec smold bash

# View logs
docker-compose logs -f smold

# Run council consultation
docker-compose exec smold python smold/council.py --prompt "Review my code"

# Stop and cleanup
docker-compose down -v

Development Setup

For development with live code reloading:

# Development Dockerfile (Dockerfile.dev)
FROM python:3.11-slim

RUN apt-get update && apt-get install -y git bash curl && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install uv for faster dependency management
RUN pip install uv

# Copy dependency files
COPY requirements.txt .
COPY pyproject.toml .

# Install dependencies (including dev tools)
RUN uv pip install --system -r requirements.txt

# Install in development mode when container starts (uses mounted volume)
CMD ["bash", "-c", "uv pip install --system -e . && python main.py -i"]
# Development docker-compose.override.yml
version: '3.8'

services:
  smold:
    build:
      dockerfile: Dockerfile.dev
    volumes:
      # Live code reloading
      - .:/app
      - ./workspace:/workspace
    environment:
      - PYTHONPATH=/app
      - DEVELOPMENT=true

Environment Variables

Create a .env file for secure API key management:

# .env file
DEEPSEEK_API_KEY=your_deepseek_api_key_here
OPENAI_API_KEY=your_openai_api_key_here
GEMINI_API_KEY=your_gemini_api_key_here

# Optional: Configure council consultation limits
COUNCIL_MAX_TOKENS=60000
COUNCIL_TIMEOUT=300

Production Considerations

Security:

  • Uses non-root user (smold) for container execution
  • API keys loaded from environment variables or mounted secrets
  • Read-only filesystem where possible

Performance:

  • Multi-stage build reduces final image size
  • Layer caching optimizes build times
  • Health checks ensure service availability

Monitoring:

# Monitor resource usage
docker stats smold-assistant

# Check health status
docker inspect --format='{{.State.Health.Status}}' smold-assistant

# Access conversation logs
docker exec smold-assistant ls -la council-logs/
---

About

SmolD is a sophisticated yet lightweight command-line code assistant that combines the power of Gemini 2.5 Large Language Models with a comprehensive suite of development tools.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published