Improve error status display.
This commit is contained in:
parent
59af95acf7
commit
c73e9ada84
|
|
@ -48,3 +48,11 @@ def print_error(message: str) -> None:
|
||||||
message: The error message to display (supports Markdown formatting)
|
message: The error message to display (supports Markdown formatting)
|
||||||
"""
|
"""
|
||||||
console.print(Panel(Markdown(message), title="Error", border_style="red bold"))
|
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"))
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ from typing_extensions import TypeAlias
|
||||||
ResearchResult = Dict[str, Union[str, bool, Dict[int, Any], List[Any], None]]
|
ResearchResult = Dict[str, Union[str, bool, Dict[int, Any], List[Any], None]]
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from ra_aid.tools.memory import _global_memory
|
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 .memory import get_memory_value, get_related_files
|
||||||
from ..llm import initialize_llm
|
from ..llm import initialize_llm
|
||||||
from ..console import print_task_header
|
from ..console import print_task_header
|
||||||
|
|
@ -32,7 +33,7 @@ def request_research(query: str) -> ResearchResult:
|
||||||
# Check recursion depth
|
# Check recursion depth
|
||||||
current_depth = _global_memory.get('research_depth', 0)
|
current_depth = _global_memory.get('research_depth', 0)
|
||||||
if current_depth >= RESEARCH_AGENT_RECURSION_LIMIT:
|
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 {
|
return {
|
||||||
"completion_message": "Research stopped - maximum recursion depth reached",
|
"completion_message": "Research stopped - maximum recursion depth reached",
|
||||||
"key_facts": get_memory_value("key_facts"),
|
"key_facts": get_memory_value("key_facts"),
|
||||||
|
|
@ -61,11 +62,11 @@ def request_research(query: str) -> ResearchResult:
|
||||||
console_message=query
|
console_message=query
|
||||||
)
|
)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
console.print("\n[yellow]Research interrupted by user[/yellow]")
|
print_interrupt("Research interrupted by user")
|
||||||
success = False
|
success = False
|
||||||
reason = "cancelled_by_user"
|
reason = "cancelled_by_user"
|
||||||
except Exception as e:
|
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
|
success = False
|
||||||
reason = f"error: {str(e)}"
|
reason = f"error: {str(e)}"
|
||||||
finally:
|
finally:
|
||||||
|
|
@ -173,11 +174,11 @@ def request_task_implementation(task_spec: str) -> Dict[str, Any]:
|
||||||
success = True
|
success = True
|
||||||
reason = None
|
reason = None
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
console.print("\n[yellow]Task implementation interrupted by user[/yellow]")
|
print_interrupt("Task implementation interrupted by user")
|
||||||
success = False
|
success = False
|
||||||
reason = "cancelled_by_user"
|
reason = "cancelled_by_user"
|
||||||
except Exception as e:
|
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
|
success = False
|
||||||
reason = f"error: {str(e)}"
|
reason = f"error: {str(e)}"
|
||||||
|
|
||||||
|
|
@ -222,11 +223,11 @@ def request_implementation(task_spec: str) -> Dict[str, Any]:
|
||||||
success = True
|
success = True
|
||||||
reason = None
|
reason = None
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
console.print("\n[yellow]Planning interrupted by user[/yellow]")
|
print_interrupt("Planning interrupted by user")
|
||||||
success = False
|
success = False
|
||||||
reason = "cancelled_by_user"
|
reason = "cancelled_by_user"
|
||||||
except Exception as e:
|
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
|
success = False
|
||||||
reason = f"error: {str(e)}"
|
reason = f"error: {str(e)}"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -295,7 +295,7 @@ def one_shot_completed(message: str) -> str:
|
||||||
|
|
||||||
_global_memory['task_completed'] = True
|
_global_memory['task_completed'] = True
|
||||||
_global_memory['completion_message'] = message
|
_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."
|
return "Completion noted."
|
||||||
|
|
||||||
@tool("task_completed")
|
@tool("task_completed")
|
||||||
|
|
@ -325,7 +325,7 @@ def plan_implementation_completed(message: str) -> str:
|
||||||
"""
|
"""
|
||||||
_global_memory['plan_completed'] = True
|
_global_memory['plan_completed'] = True
|
||||||
_global_memory['completion_message'] = message
|
_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."
|
return "Plan completion noted."
|
||||||
|
|
||||||
def get_related_files() -> Set[str]:
|
def get_related_files() -> Set[str]:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue