A Lightweight Code Assistant with Powerful Tool Integration
Built on HuggingFace's smolagents framework with Google Gemini 2.5 Flash integration
- SmolD
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.
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.
- π§ 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
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 β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
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 |
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.
- 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
-
Clone and Navigate
git clone https://github.com/fabiopauli/smold-gemini.git cd smold-gemini
-
Environment Setup
# Create virtual environment python -m venv venv # Activate (Unix/Linux/macOS) source venv/bin/activate # Activate (Windows) venv\Scripts\activate
-
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 .
-
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
- β
Use
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"
π 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"
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
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
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
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 |
π 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:
- β Check this troubleshooting guide
- β
Verify your Python version:
python --version
- β Confirm API keys are properly set
- β
Try running with
--debug
flag for detailed logs - β 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')"
- smolagents - The underlying agent framework
- LiteLLM - Multi-provider LLM interface
This project is licensed under the MIT License - see the LICENSE file for details.
- 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
SmolD supports containerized deployment for consistent environments and easy distribution across different platforms.
One-Command Setup
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"]
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
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
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
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
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/