|
|
||
|---|---|---|
| .github/workflows | ||
| assets | ||
| dist | ||
| ra_aid | ||
| scripts | ||
| tests | ||
| .gitignore | ||
| CHANGELOG.md | ||
| LICENSE | ||
| MANIFEST.in | ||
| README.md | ||
| pyproject.toml | ||
| requirements-dev.txt | ||
README.md
██▀███ ▄▄▄ ▄▄▄ ██▓▓█████▄
▓██ ▒ ██▒▒████▄ ▒████▄ ▓██▒▒██▀ ██▌
▓██ ░▄█ ▒▒██ ▀█▄ ▒██ ▀█▄ ▒██▒░██ █▌
▒██▀▀█▄ ░██▄▄▄▄██ ░██▄▄▄▄██ ░██░░▓█▄ ▌
░██▓ ▒██▒ ▓█ ▓██▒ ██▓ ▓█ ▓██▒░██░░▒████▓
░ ▒▓ ░▒▓░ ▒▒ ▓▒█░ ▒▓▒ ▒▒ ▓▒█░░▓ ▒▒▓ ▒
░▒ ░ ▒░ ▒ ▒▒ ░ ░▒ ▒ ▒▒ ░ ▒ ░ ░ ▒ ▒
░░ ░ ░ ▒ ░ ░ ▒ ▒ ░ ░ ░ ░
░ ░ ░ ░ ░ ░ ░ ░
░ ░
Here's a video of RA.Aid adding a feature to itself:
👋 Pull requests are very welcome! As a technical founder with limited time (who uses RA.Aid to save time), I greatly appreciate any contributions to this repository. Don't be shy - your help makes a real difference!
💬 Join our Discord community: Click here to join
RA.Aid
RA.Aid (ReAct Aid) is a powerful AI-driven command-line tool that integrates aider (https://aider.chat/) within a LangChain ReAct agent loop. This unique combination allows developers to leverage aider's code editing capabilities while benefiting from LangChain's agent-based task execution framework. The tool provides an intelligent assistant that can help with research, planning, and implementation of development tasks.
⚠️ IMPORTANT: USE AT YOUR OWN RISK ⚠️
- This tool can and will automatically execute shell commands on your system
- Shell commands require interactive approval unless --cowboy-mode is enabled
- The --cowboy-mode flag disables command approval and should be used with extreme caution
- No warranty is provided, either express or implied
- Always review the actions the agent proposes before allowing them to proceed
Key Features
-
Multi-Step Task Planning: The agent breaks down complex tasks into discrete, manageable steps and executes them sequentially. This systematic approach ensures thorough implementation and reduces errors.
-
Automated Command Execution: The agent can run shell commands automatically to accomplish tasks. While this makes it powerful, it also means you should carefully review its actions.
-
Three-Stage Architecture:
- Research: Analyzes codebases and gathers context
- Planning: Breaks down tasks into specific, actionable steps
- Implementation: Executes each planned step sequentially
What sets RA.Aid apart is its ability to handle complex programming tasks that extend beyond single-shot code edits. By combining research, strategic planning, and implementation into a cohesive workflow, RA.Aid can:
- Break down and execute multi-step programming tasks
- Research and analyze complex codebases to answer architectural questions
- Plan and implement significant code changes across multiple files
- Provide detailed explanations of existing code structure and functionality
- Execute sophisticated refactoring operations with proper planning
Table of Contents
- Features
- Installation
- Usage
- Architecture
- Dependencies
- Development Setup
- Contributing
- License
- Contact
Features
-
Three-Stage Architecture: The workflow consists of three powerful stages:
- Research 🔍 - Gather and analyze information
- Planning 📋 - Develop execution strategy
- Implementation ⚡ - Execute the plan with AI assistance
Each stage is powered by dedicated AI agents and specialized toolsets.
-
Advanced AI Integration: Built on LangChain and leverages the latest LLMs for natural language understanding and generation.
-
Comprehensive Toolset:
- Shell command execution
- Expert querying system
- File operations and management
- Memory management
- Research and planning tools
- Code analysis capabilities
-
Interactive CLI Interface: Simple yet powerful command-line interface for seamless interaction
-
Modular Design: Structured as a Python package with specialized modules for console output, processing, text utilities, and tools
-
Git Integration: Built-in support for Git operations and repository management
Installation
RA.Aid can be installed directly using pip:
pip install ra-aid
Prerequisites
Before using RA.Aid, you'll need:
- Python package
aiderinstalled and available in your PATH:
pip install aider-chat
- API keys for the required AI services:
# Set up API keys based on your preferred provider:
# For Anthropic Claude models (recommended)
export ANTHROPIC_API_KEY=your_api_key_here
# For OpenAI models
export OPENAI_API_KEY=your_api_key_here
# For OpenRouter provider (optional)
export OPENROUTER_API_KEY=your_api_key_here
# For OpenAI-compatible providers (optional)
export OPENAI_API_BASE=your_api_base_url
Note: The programmer tool (aider) will automatically select its model based on your available API keys:
- If ANTHROPIC_API_KEY is set, it will use Claude models
- If only OPENAI_API_KEY is set, it will use OpenAI models
- You can set multiple API keys to enable different features
You can get your API keys from:
- Anthropic API key: https://console.anthropic.com/
- OpenAI API key: https://platform.openai.com/api-keys
- OpenRouter API key: https://openrouter.ai/keys
Usage
RA.Aid is designed to be simple yet powerful. Here's how to use it:
# Basic usage
ra-aid -m "Your task or query here"
# Research-only mode (no implementation)
ra-aid -m "Explain the authentication flow" --research-only
Command Line Options
-m, --message: The task or query to be executed (required)--research-only: Only perform research without implementation--cowboy-mode: Skip interactive approval for shell commands--provider: Specify the model provider (See Model Configuration section)--model: Specify the model name (See Model Configuration section)--expert-provider: Specify the provider for the expert tool (defaults to OpenAI)--expert-model: Specify the model name for the expert tool (defaults to o1-preview for OpenAI)
Model Configuration
RA.Aid supports multiple AI providers and models. The default model is Anthropic's Claude 3 Sonnet (claude-3-5-sonnet-20241022).
The programmer tool (aider) automatically selects its model based on your available API keys. It will use Claude models if ANTHROPIC_API_KEY is set, or fall back to OpenAI models if only OPENAI_API_KEY is available.
Note: The expert tool can be configured to use different providers (OpenAI, Anthropic, OpenRouter) using the --expert-provider flag along with the corresponding EXPERT_*API_KEY environment variables. Each provider requires its own API key set through the appropriate environment variable.
Environment Variables
RA.Aid supports multiple providers through environment variables:
ANTHROPIC_API_KEY: Required for the default Anthropic providerOPENAI_API_KEY: Required for OpenAI providerOPENROUTER_API_KEY: Required for OpenRouter providerOPENAI_API_BASE: Required for OpenAI-compatible providers along withOPENAI_API_KEY
Expert Tool Environment Variables:
EXPERT_OPENAI_API_KEY: API key for expert tool using OpenAI providerEXPERT_ANTHROPIC_API_KEY: API key for expert tool using Anthropic providerEXPERT_OPENROUTER_API_KEY: API key for expert tool using OpenRouter providerEXPERT_OPENAI_API_BASE: Base URL for expert tool using OpenAI-compatible provider
You can set these permanently in your shell's configuration file (e.g., ~/.bashrc or ~/.zshrc):
# Default provider (Anthropic)
export ANTHROPIC_API_KEY=your_api_key_here
# For OpenAI features and expert tool
export OPENAI_API_KEY=your_api_key_here
# For OpenRouter provider
export OPENROUTER_API_KEY=your_api_key_here
# For OpenAI-compatible providers
export OPENAI_API_BASE=your_api_base_url
Note: The expert tool defaults to OpenAI's o1-preview model with the OpenAI provider, but this can be configured using the --expert-provider flag along with the corresponding EXPERT_*_KEY environment variables.
Examples
-
Using Anthropic (Default)
# Uses default model (claude-3-5-sonnet-20241022) ra-aid -m "Your task" # Or explicitly specify: ra-aid -m "Your task" --provider anthropic --model claude-3-5-sonnet-20241022 -
Using OpenAI
ra-aid -m "Your task" --provider openai --model gpt-4o -
Using OpenRouter
ra-aid -m "Your task" --provider openrouter --model mistralai/mistral-large-2411 -
Configuring Expert Provider
The expert tool is used by the agent for complex logic and debugging tasks. It can be configured to use different providers (OpenAI, Anthropic, OpenRouter) using the --expert-provider flag along with the corresponding EXPERT_*API_KEY environment variables.
# Use Anthropic for expert tool export EXPERT_ANTHROPIC_API_KEY=your_anthropic_api_key ra-aid -m "Your task" --expert-provider anthropic --expert-model claude-3-5-sonnet-20241022 # Use OpenRouter for expert tool export OPENROUTER_API_KEY=your_openrouter_api_key ra-aid -m "Your task" --expert-provider openrouter --expert-model mistralai/mistral-large-2411 # Use default OpenAI for expert tool export EXPERT_OPENAI_API_KEY=your_openai_api_key ra-aid -m "Your task" --expert-provider openai --expert-model o1-preview
Important Notes:
- Performance varies between models. The default Claude 3 Sonnet model currently provides the best and most reliable results.
- Model configuration is done via command line arguments:
--providerand--model - The
--modelargument is required for all providers except Anthropic (which defaults toclaude-3-5-sonnet-20241022)
Example Tasks
-
Code Analysis:
ra-aid -m "Explain how the authentication middleware works" --research-only -
Complex Changes:
ra-aid -m "Refactor the database connection code to use connection pooling" --cowboy-mode -
Automated Updates:
ra-aid -m "Update deprecated API calls across the entire codebase" --cowboy-mode -
Code Research:
ra-aid -m "Analyze the current error handling patterns" --research-only -
Code Research:
ra-aid -m "Explain how the authentication middleware works" --research-only -
Refactoring:
ra-aid -m "Refactor the database connection code to use connection pooling" --cowboy-mode
Automating Code Changes with Cowboy Mode 🏇
For situations where you need to automate code modifications without manual intervention—such as continuous integration/continuous deployment (CI/CD) pipelines, scripted batch operations, or large-scale refactoring—you can use the --cowboy-mode flag. This mode executes commands non-interactively, bypassing the usual confirmation prompts.
ra-aid -m "Update all deprecated API calls" --cowboy-mode
In the example above, the command will automatically find and update all deprecated API calls in your codebase without asking for confirmation before each change.
⚠️ Use with Extreme Caution: Cowboy mode is a powerful tool that removes safety checks designed to prevent unintended modifications. While it enables efficient automation, it also increases the risk of errors propagating through your codebase. Ensure you have proper backups or version control in place before using this mode.
Appropriate Use Cases for Cowboy Mode:
- CI/CD Pipelines: Automate code changes as part of your deployment process.
- Scripted Batch Operations: Apply repetitive changes across multiple files without manual approval.
- Controlled Environments: Use in environments where changes can be reviewed and reverted if necessary.
When Not to Use Cowboy Mode:
- Research or Experimental Changes: When you are exploring solutions and unsure of the outcomes.
- Critical Codebases Without Backups: If you don't have a way to revert changes, it's safer to use the interactive mode.
Environment Variables
See the Model Configuration section for details on provider-specific environment variables.
Architecture
RA.Aid implements a three-stage architecture for handling development and research tasks:
-
Research Stage:
- Gathers information and context
- Analyzes requirements
- Identifies key components and dependencies
-
Planning Stage:
- Develops detailed implementation plans
- Breaks down tasks into manageable steps
- Identifies potential challenges and solutions
-
Implementation Stage:
- Executes planned tasks
- Generates code or documentation
- Performs necessary system operations
Core Components
- Console Module (
console/): Handles console output formatting and user interaction - Processing Module (
proc/): Manages interactive processing and workflow control - Text Module (
text/): Provides text processing and manipulation utilities - Tools Module (
tools/): Contains various utility tools for file operations, search, and more
Dependencies
Core Dependencies
langchain-anthropic: LangChain integration with Anthropic's Claudelanggraph: Graph-based workflow managementrich>=13.0.0: Terminal formatting and outputGitPython==3.1.41: Git repository managementfuzzywuzzy==0.18.0: Fuzzy string matchingpython-Levenshtein==0.23.0: Fast string matchingpathspec>=0.11.0: Path specification utilities
Development Dependencies
pytest>=7.0.0: Testing frameworkpytest-timeout>=2.2.0: Test timeout management
Development Setup
- Clone the repository:
git clone https://github.com/ai-christianson/ra-aid.git
cd ra-aid
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
- Install development dependencies:
pip install -r requirements-dev.txt
- Run tests:
python -m pytest
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature-name
- Make your changes and commit:
git commit -m 'Add some feature'
- Push to your fork:
git push origin feature/your-feature-name
- Open a Pull Request
Guidelines
- Follow PEP 8 style guidelines
- Add tests for new features
- Update documentation as needed
- Keep commits focused and message clear
- Ensure all tests pass before submitting PR
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Copyright (c) 2024 AI Christianson
Contact
- Issues: Please report bugs and feature requests on our Issue Tracker
- Repository: https://github.com/ai-christianson/ra-aid
- Documentation: https://github.com/ai-christianson/ra-aid#readme