aider-free mode

This commit is contained in:
AI Christianson 2025-02-26 20:15:00 -05:00
parent 4aeb52e41d
commit 65b8619517
4 changed files with 101 additions and 4 deletions

View File

@ -34,7 +34,7 @@ from ra_aid.logging_config import get_logger, setup_logging
from ra_aid.models_params import DEFAULT_TEMPERATURE, models_params
from ra_aid.project_info import format_project_info, get_project_info
from ra_aid.prompts import CHAT_PROMPT, WEB_RESEARCH_PROMPT_SECTION_CHAT
from ra_aid.tool_configs import get_chat_tools
from ra_aid.tool_configs import get_chat_tools, set_modification_tools
from ra_aid.tools.human import ask_human
from ra_aid.tools.memory import _global_memory
@ -170,6 +170,10 @@ Examples:
parser.add_argument(
"--aider-config", type=str, help="Specify the aider config file path"
)
parser.add_argument(
"--use-aider", action="store_true",
help="Use aider for code modifications instead of default file tools (file_str_replace, put_complete_file_contents)"
)
parser.add_argument(
"--test-cmd",
type=str,
@ -426,6 +430,9 @@ def main():
_global_memory["config"]["expert_model"] = args.expert_model
_global_memory["config"]["temperature"] = args.temperature
# Set modification tools based on use_aider flag
set_modification_tools(args.use_aider)
# Create chat agent with appropriate tools
chat_agent = create_agent(
chat_model,
@ -465,6 +472,7 @@ def main():
"cowboy_mode": args.cowboy_mode,
"web_research_enabled": web_research_enabled,
"aider_config": args.aider_config,
"use_aider": args.use_aider,
"limit_tokens": args.disable_limit_tokens,
"auto_test": args.auto_test,
"test_cmd": args.test_cmd,
@ -499,6 +507,9 @@ def main():
# Store temperature in global config
_global_memory["config"]["temperature"] = args.temperature
# Set modification tools based on use_aider flag
set_modification_tools(args.use_aider)
# Run research stage
print_stage_header("Research Stage")

View File

@ -29,6 +29,21 @@ from ra_aid.tools.agent import (
from ra_aid.tools.memory import one_shot_completed, plan_implementation_completed
def set_modification_tools(use_aider=False):
"""Set the MODIFICATION_TOOLS list based on configuration.
Args:
use_aider: Whether to use run_programming_task (True) or file modification tools (False)
"""
global MODIFICATION_TOOLS
if use_aider:
MODIFICATION_TOOLS.clear()
MODIFICATION_TOOLS.append(run_programming_task)
else:
MODIFICATION_TOOLS.clear()
MODIFICATION_TOOLS.extend([file_str_replace, put_complete_file_contents])
# Read-only tools that don't modify system state
def get_read_only_tools(
human_interaction: bool = False, web_research_enabled: bool = False
@ -80,10 +95,9 @@ def get_all_tools() -> list[BaseTool]:
# Define constant tool groups
READ_ONLY_TOOLS = get_read_only_tools()
# MODIFICATION_TOOLS will be set dynamically based on config, default defined here
MODIFICATION_TOOLS = [file_str_replace, put_complete_file_contents]
# MODIFICATION_TOOLS = [
# run_programming_task
# ] # having put_complete_file_contents causes trouble :(
COMMON_TOOLS = get_read_only_tools()
EXPERT_TOOLS = [emit_expert_context, ask_expert]
RESEARCH_TOOLS = [

View File

@ -198,3 +198,54 @@ def test_planner_model_provider_args(mock_dependencies):
config = _global_memory["config"]
assert config["planner_provider"] == "openai"
assert config["planner_model"] == "gpt-4"
def test_use_aider_flag(mock_dependencies):
"""Test that use-aider flag is correctly stored in config."""
import sys
from unittest.mock import patch
from ra_aid.tool_configs import MODIFICATION_TOOLS, set_modification_tools
from ra_aid.__main__ import main
_global_memory.clear()
# Reset to default state
set_modification_tools(False)
# Check default behavior (use_aider=False)
with patch.object(
sys,
"argv",
["ra-aid", "-m", "test message"],
):
main()
config = _global_memory["config"]
assert config.get("use_aider") is False
# Check that file tools are enabled by default
tool_names = [tool.name for tool in MODIFICATION_TOOLS]
assert "file_str_replace" in tool_names
assert "put_complete_file_contents" in tool_names
assert "run_programming_task" not in tool_names
_global_memory.clear()
# Check with --use-aider flag
with patch.object(
sys,
"argv",
["ra-aid", "-m", "test message", "--use-aider"],
):
main()
config = _global_memory["config"]
assert config.get("use_aider") is True
# Check that run_programming_task is enabled
tool_names = [tool.name for tool in MODIFICATION_TOOLS]
assert "file_str_replace" not in tool_names
assert "put_complete_file_contents" not in tool_names
assert "run_programming_task" in tool_names
# Reset to default state for other tests
set_modification_tools(False)

View File

@ -4,6 +4,8 @@ from ra_aid.tool_configs import (
get_read_only_tools,
get_research_tools,
get_web_research_tools,
set_modification_tools,
MODIFICATION_TOOLS,
)
@ -82,3 +84,22 @@ def test_get_web_research_tools():
assert sorted(tool_names_no_expert) == sorted(
["web_search_tavily", "emit_research_notes", "task_completed"]
)
def test_set_modification_tools():
# Test with use_aider=False (default setting)
set_modification_tools(use_aider=False)
tool_names = [tool.name for tool in MODIFICATION_TOOLS]
assert "file_str_replace" in tool_names
assert "put_complete_file_contents" in tool_names
assert "run_programming_task" not in tool_names
# Test with use_aider=True
set_modification_tools(use_aider=True)
tool_names = [tool.name for tool in MODIFICATION_TOOLS]
assert "file_str_replace" not in tool_names
assert "put_complete_file_contents" not in tool_names
assert "run_programming_task" in tool_names
# Reset to default for other tests
set_modification_tools(use_aider=False)