Multi-Agent Coding Assistant

A sophisticated multi-agent coding assistant powered by LangGraph and Ollama, designed to help with complex software development tasks through specialized AI agents.

๐Ÿš€ Features

  • Multi-Agent Architecture: Coordinated agents working together for complex tasks
  • Local AI Models: Uses Ollama for privacy and control over your AI models
  • Per-Agent Model Optimization: Different models optimized for each agent's specialty
  • Automatic Model Management: Download required models on first run
  • Automatic Background Indexing: Real-time codebase analysis with file watching
  • Flexible Indexing Control: Enable/disable automatic indexing with CLI options
  • Command Safety Controls: Three security modes for system command execution
  • Specialized Agents (10 total):
    • ๐Ÿ” WebSearchAgent (llama3.1:8b): Searches for documentation, examples, best practices
    • ๐Ÿ” CodeReviewAgent (qwen2.5-coder:32b): Analyzes code quality, bugs, security issues
    • ๐Ÿ“Š CodeAnalyzerAgent (qwen2.5-coder:32b): Indexes codebases, tracks dependencies, AST analysis
    • ๐Ÿ“ FileOperationsAgent (qwen2.5-coder:32b): Direct file manipulation - read, write, edit files
    • ๐Ÿงช TestGeneratorAgent (qwen2.5-coder:32b): Creates comprehensive unit and integration tests
    • ๐Ÿ”„ RefactoringAgent (qwen2.5-coder:32b): Code optimization, design patterns, modernization
    • ๐Ÿ“ GitAgent (llama3.1:8b): Git workflows, commit messages, merge conflict resolution
    • ๐Ÿ“š DocumentationAgent (llama3.1:8b): README files, API docs, docstrings, user guides
    • ๐Ÿ–ฅ๏ธ CommandLineAgent (llama3.1:8b): System command execution with safety controls
    • ๐ŸŽฏ SupervisorAgent (qwen2.5:32b): Orchestrates multi-agent workflows using LangGraph

๐Ÿ“‹ Prerequisites

  • Python 3.9+
  • Ollama installed and running locally
  • qwen2.5-coder:32b model (or your preferred coding model)

๐Ÿ› ๏ธ Installation

  1. Clone the repository:
git clone git@github.com:adam-hanna/ollama-agentic-coder.git
cd ollama-agentic-coder
  1. Create a virtual environment:
python -m venv .venv
source ./.venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt -r requirements-dev.txt
  1. Install Ollama (if not already installed):
# macOS
brew install ollama

# Linux
curl -fsSL https://ollama.ai/install.sh | sh

# Windows - Download from https://ollama.ai/download
  1. Pull the models:
ollama pull qwen2.5-coder:32b
ollama pull qwen2.5:32b
ollama pull llama3.1:8b

โš™๏ธ Configuration

The system can be configured via environment variables or the default config:

Environment Variables

# Ollama settings
export OLLAMA_HOST="http://localhost:11434"
export OLLAMA_MODEL="qwen2.5-coder:32b"
export OLLAMA_TEMPERATURE="0.1"
export OLLAMA_MAX_TOKENS="4096"
export OLLAMA_TIMEOUT="300"

Available Models

You can use any Ollama-compatible model:

# Other excellent coding models
ollama pull deepseek-coder:33b
ollama pull codellama:34b
ollama pull starcoder2:15b

Command Line Safety Modes

The CommandLineAgent operates in three safety modes:

  • SAFE (default): Only pre-approved read-only commands (ls, cat, grep, etc.)
  • WHITELIST: Safe commands + user-approved commands (prompts for approval)
  • YOLO: All commands allowed (use with extreme caution)

Configure via environment variable:

export COMMAND_SAFETY_MODE="safe"  # or "whitelist" or "yolo"

๐Ÿš€ Usage

Basic Usage

  1. Run ollama:
ollama serve
  1. Run the application:
python main.py

CLI Options

python main.py --help
python main.py --host http://localhost:11434 --model qwen2.5-coder:32b --temperature 0.1

# Indexing control options
python main.py --no-auto-index        # Disable automatic background indexing
python main.py --no-file-watch        # Disable file change watching
python main.py --no-auto-index --no-file-watch  # Disable both

Interactive Commands

Once running, you can use these commands:

  • /help - Show available commands and indexing status
  • /index - Manual indexing commands:
    • /index - Index current directory
    • /index [path] - Index specific directory
    • /index auto - Toggle automatic background indexing
    • /index stop - Stop background indexing
  • /config - Show current configuration
  • /agents - List available agents and their assigned models
  • /clear - Clear conversation history
  • /exit - Exit the application

Example Interactions

Code Review:

You: Review this Python file for bugs and security issues: src/auth.py

File Operations:

You: Create a new config.py file with database settings
You: Edit the main.py file to add logging configuration

Test Generation:

You: Generate comprehensive unit tests for the User class
You: Create integration tests for the authentication workflow

Refactoring:

You: Analyze auth.py for refactoring opportunities and suggest improvements
You: Refactor this complex function to use better design patterns

Git Operations:

You: Generate a commit message for my current changes
You: Help me resolve this merge conflict in src/models.py

Documentation:

You: Create a README for this project
You: Add comprehensive docstrings to all functions in this file

Web Search:

You: Search for best practices for async Python error handling

Command Line Operations:

You: List all Python files in the current directory
You: Check the status of the development server
You: Run the test suite and show me the results

Complex Multi-Agent Tasks:

You: I need to implement user authentication. Create the models, generate tests, add documentation, and suggest a Git workflow.
You: Refactor my authentication system, generate tests for the changes, and update the documentation.

๐Ÿ—๏ธ Architecture

Agent Structure

SupervisorAgent (qwen2.5:32b) - LangGraph Orchestration
โ”œโ”€โ”€ WebSearchAgent (llama3.1:8b) - DuckDuckGo + Web Search
โ”œโ”€โ”€ CodeReviewAgent (qwen2.5-coder:32b) - AST + Static Analysis
โ”œโ”€โ”€ CodeAnalyzerAgent (qwen2.5-coder:32b) - Tree-sitter + Indexing
โ”œโ”€โ”€ FileOperationsAgent (qwen2.5-coder:32b) - File System Operations
โ”œโ”€โ”€ TestGeneratorAgent (qwen2.5-coder:32b) - Test Creation & Coverage
โ”œโ”€โ”€ RefactoringAgent (qwen2.5-coder:32b) - Code Optimization
โ”œโ”€โ”€ GitAgent (llama3.1:8b) - Version Control Operations
โ”œโ”€โ”€ DocumentationAgent (llama3.1:8b) - Documentation Generation
โ””โ”€โ”€ CommandLineAgent (llama3.1:8b) - System Command Execution

Data Flow

  1. User Input โ†’ SupervisorAgent analyzes request
  2. Task Analysis โ†’ AI determines which agent(s) are needed
  3. Agent Selection โ†’ Route to appropriate specialized agent(s)
  4. Background Processing โ†’ Real-time codebase indexing if enabled
  5. Agent Execution โ†’ Specialized agents work on their tasks
  6. Result Synthesis โ†’ SupervisorAgent combines results into coherent response

Model Optimization Strategy

  • Coding Tasks: qwen2.5-coder:32b - Specialized for code analysis, generation, review
  • General Tasks: llama3.1:8b - Lighter, faster for search, git, documentation
  • Orchestration: qwen2.5:32b - Strong reasoning for task coordination

๐Ÿ”ง Customization

Adding New Agents

  1. Create a new agent class inheriting from BaseAgent:
from core.base_agent import BaseAgent, AgentState

class MyCustomAgent(BaseAgent):
    def _default_system_prompt(self) -> str:
        return "Your specialized agent prompt here"
    
    async def process(self, state: AgentState) -> AgentState:
        # Your agent logic here
        pass
  1. Register it in the SupervisorAgent workflow

Custom Models

The system supports any Ollama model. You can customize per-agent models in core/config.py:

models: Dict[str, str] = {
    "supervisor": "qwen2.5:32b",
    "websearch": "llama3.1:8b", 
    "code_review": "qwen2.5-coder:32b",
    "file_operations": "qwen2.5-coder:32b",
    # ... customize as needed
}

Popular model choices:

  • qwen2.5-coder:32b - Excellent for coding tasks
  • deepseek-coder:33b - Strong coding capabilities
  • codellama:34b - Meta's coding model
  • starcoder2:15b - Smaller but capable
  • llama3.1:8b - Fast general purpose model
  • qwen2.5:32b - Strong reasoning for coordination

๐Ÿงช Testing

# Run the test suite
python -m pytest tests/

# Test specific components
python -m pytest tests/test_agents.py

๐Ÿ“ Project Structure

langgraph-ollama-agent/
โ”œโ”€โ”€ core/                   # Core components
โ”‚   โ”œโ”€โ”€ config.py          # Configuration management
โ”‚   โ”œโ”€โ”€ ollama_client.py   # Ollama API client
โ”‚   โ””โ”€โ”€ base_agent.py      # Base agent class
โ”œโ”€โ”€ agents/                # Specialized agents
โ”‚   โ”œโ”€โ”€ websearch_agent.py
โ”‚   โ”œโ”€โ”€ code_review_agent.py
โ”‚   โ”œโ”€โ”€ code_analyzer_agent.py
โ”‚   โ”œโ”€โ”€ file_operations_agent.py
โ”‚   โ”œโ”€โ”€ test_generator_agent.py
โ”‚   โ”œโ”€โ”€ refactoring_agent.py
โ”‚   โ”œโ”€โ”€ git_agent.py
โ”‚   โ”œโ”€โ”€ documentation_agent.py
โ”‚   โ”œโ”€โ”€ command_line_agent.py
โ”‚   โ””โ”€โ”€ supervisor_agent.py
โ”œโ”€โ”€ cli/                   # Command line interface
โ”‚   โ””โ”€โ”€ main.py
โ”œโ”€โ”€ utils/                 # Utility functions
โ”œโ”€โ”€ tests/                 # Test files
โ”œโ”€โ”€ requirements.txt       # Dependencies
โ”œโ”€โ”€ main.py               # Entry point
โ””โ”€โ”€ README.md             # This file

๐Ÿ› Troubleshooting

Common Issues

Ollama Connection Error:

# Check if Ollama is running
ollama list

# Start Ollama if needed
ollama serve

Model Not Found:

# Pull the required model
ollama pull qwen2.5-coder:32b

Memory Issues:

  • Use smaller models like qwen2.5-coder:14b or starcoder2:7b
  • Reduce max_tokens in configuration

Slow Performance:

  • Use GPU acceleration if available
  • Reduce model size (use smaller variants like qwen2.5-coder:14b)
  • Disable background indexing: --no-auto-index
  • Disable file watching: --no-file-watch
  • Adjust temperature settings

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

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

๐Ÿ™ Acknowledgments

๐Ÿ”ฎ Future Enhancements

  • File system operations (read, write, edit) โœ… Implemented
  • Git integration for version control โœ… Implemented
  • Test generation and coverage analysis โœ… Implemented
  • Code refactoring and optimization โœ… Implemented
  • Documentation generation โœ… Implemented
  • Command line operations with safety controls โœ… Implemented
  • Automatic model downloading and management โœ… Implemented
  • Integration with popular IDEs (VS Code extension)
  • Web interface option
  • Custom workflow definitions via YAML/JSON
  • Plugin system for extending agents
  • Collaborative multi-user sessions
  • Database integration agent
  • Deployment and DevOps agent
  • Security scanning and vulnerability assessment
  • Performance profiling and optimization agent