From c73e9ada84122a885d05b42b8807521a5937916b Mon Sep 17 00:00:00 2001 From: user Date: Sun, 22 Dec 2024 10:02:50 -0500 Subject: [PATCH] Improve error status display. --- ra_aid/console/formatting.py | 8 ++++++++ ra_aid/tools/agent.py | 15 ++++++++------- ra_aid/tools/memory.py | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/ra_aid/console/formatting.py b/ra_aid/console/formatting.py index 5164f91..444c2b8 100644 --- a/ra_aid/console/formatting.py +++ b/ra_aid/console/formatting.py @@ -48,3 +48,11 @@ def print_error(message: str) -> None: message: The error message to display (supports Markdown formatting) """ console.print(Panel(Markdown(message), title="Error", border_style="red bold")) + +def print_interrupt(message: str) -> None: + """Print an interruption message in a yellow-bordered panel with appropriate emoji. + + Args: + message: The interruption message to display (supports Markdown formatting) + """ + console.print(Panel(Markdown(message), title="Interrupted", border_style="yellow bold")) diff --git a/ra_aid/tools/agent.py b/ra_aid/tools/agent.py index 612f159..3501f5d 100644 --- a/ra_aid/tools/agent.py +++ b/ra_aid/tools/agent.py @@ -7,6 +7,7 @@ from typing_extensions import TypeAlias ResearchResult = Dict[str, Union[str, bool, Dict[int, Any], List[Any], None]] from rich.console import Console from ra_aid.tools.memory import _global_memory +from ra_aid.console.formatting import print_error, print_interrupt from .memory import get_memory_value, get_related_files from ..llm import initialize_llm from ..console import print_task_header @@ -32,7 +33,7 @@ def request_research(query: str) -> ResearchResult: # Check recursion depth current_depth = _global_memory.get('research_depth', 0) if current_depth >= RESEARCH_AGENT_RECURSION_LIMIT: - console.print("\n[red]Maximum research recursion depth reached[/red]") + print_error("Maximum research recursion depth reached") return { "completion_message": "Research stopped - maximum recursion depth reached", "key_facts": get_memory_value("key_facts"), @@ -61,11 +62,11 @@ def request_research(query: str) -> ResearchResult: console_message=query ) except KeyboardInterrupt: - console.print("\n[yellow]Research interrupted by user[/yellow]") + print_interrupt("Research interrupted by user") success = False reason = "cancelled_by_user" except Exception as e: - console.print(f"\n[red]Error during research: {str(e)}[/red]") + print_error(f"Error during research: {str(e)}") success = False reason = f"error: {str(e)}" finally: @@ -173,11 +174,11 @@ def request_task_implementation(task_spec: str) -> Dict[str, Any]: success = True reason = None except KeyboardInterrupt: - console.print("\n[yellow]Task implementation interrupted by user[/yellow]") + print_interrupt("Task implementation interrupted by user") success = False reason = "cancelled_by_user" except Exception as e: - console.print(f"\n[red]Error during task implementation: {str(e)}[/red]") + print_error(f"Error during task implementation: {str(e)}") success = False reason = f"error: {str(e)}" @@ -222,11 +223,11 @@ def request_implementation(task_spec: str) -> Dict[str, Any]: success = True reason = None except KeyboardInterrupt: - console.print("\n[yellow]Planning interrupted by user[/yellow]") + print_interrupt("Planning interrupted by user") success = False reason = "cancelled_by_user" except Exception as e: - console.print(f"\n[red]Error during planning: {str(e)}[/red]") + print_error(f"Error during planning: {str(e)}") success = False reason = f"error: {str(e)}" diff --git a/ra_aid/tools/memory.py b/ra_aid/tools/memory.py index 246f38a..efc1a1b 100644 --- a/ra_aid/tools/memory.py +++ b/ra_aid/tools/memory.py @@ -295,7 +295,7 @@ def one_shot_completed(message: str) -> str: _global_memory['task_completed'] = True _global_memory['completion_message'] = message - console.print(Panel(Markdown(message), title="✅ One-Shot Task Completed")) + console.print(Panel(Markdown(message), title="✅ Task Completed")) return "Completion noted." @tool("task_completed") @@ -325,7 +325,7 @@ def plan_implementation_completed(message: str) -> str: """ _global_memory['plan_completed'] = True _global_memory['completion_message'] = message - console.print(Panel(Markdown(message), title="✅ Plan Implementation Completed")) + console.print(Panel(Markdown(message), title="✅ Plan Executed")) return "Plan completion noted." def get_related_files() -> Set[str]: