From ba51f99da506714c155b6132bab8b3eab699504f Mon Sep 17 00:00:00 2001 From: user Date: Sat, 21 Dec 2024 14:16:12 -0500 Subject: [PATCH] Added request_research_and_implementation. --- ra_aid/tool_configs.py | 2 +- ra_aid/tools/agent.py | 51 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/ra_aid/tool_configs.py b/ra_aid/tool_configs.py index 8ff270c..45a0d82 100644 --- a/ra_aid/tool_configs.py +++ b/ra_aid/tool_configs.py @@ -10,7 +10,7 @@ from ra_aid.tools import ( task_completed, plan_implementation_completed ) from ra_aid.tools.memory import one_shot_completed -from ra_aid.tools.agent import request_research, request_task_implementation +from ra_aid.tools.agent import request_research, request_research_and_implementation, request_task_implementation # Read-only tools that don't modify system state def get_read_only_tools(human_interaction: bool = False) -> list: diff --git a/ra_aid/tools/agent.py b/ra_aid/tools/agent.py index 8b32003..0a83be4 100644 --- a/ra_aid/tools/agent.py +++ b/ra_aid/tools/agent.py @@ -61,6 +61,57 @@ def request_research(query: str) -> Dict[str, Any]: "reason": reason } +@tool("request_research_and_implementation") +def request_research_and_implementation(query: str) -> Dict[str, Any]: + """Spawn a research agent to investigate and implement the given query. + + Args: + query: The research question or project description + + Returns: + Dict containing: + - notes: Research notes from the agent + - facts: Current key facts + - files: Related files + - success: Whether completed or interrupted + - reason: Reason for failure, if any + """ + # Initialize model from config + config = _global_memory.get('config', {}) + model = initialize_llm(config.get('provider', 'anthropic'), config.get('model', 'claude-3-5-sonnet-20241022')) + + try: + # Run research agent + from ..agent_utils import run_research_agent + result = run_research_agent( + query, + model, + expert_enabled=True, + research_only=False, + hil=_global_memory.get('config', {}).get('hil', False), + console_message=query + ) + + success = True + reason = None + except KeyboardInterrupt: + console.print("\n[yellow]Research interrupted by user[/yellow]") + success = False + reason = "cancelled_by_user" + except Exception as e: + console.print(f"\n[red]Error during research: {str(e)}[/red]") + success = False + reason = f"error: {str(e)}" + + # Gather results + return { + "facts": get_memory_value("key_facts"), + "files": list(get_related_files()), + "notes": get_memory_value("research_notes"), + "success": success, + "reason": reason + } + @tool("request_task_implementation") def request_task_implementation(task_spec: str) -> Dict[str, Any]: """Spawn an implementation agent to execute the given task.