Track agent depth for all agents.
This commit is contained in:
parent
c261c741f9
commit
9a53940dcd
|
|
@ -306,6 +306,10 @@ def run_agent_with_retry(agent, prompt: str, config: dict) -> Optional[str]:
|
||||||
|
|
||||||
with InterruptibleSection():
|
with InterruptibleSection():
|
||||||
try:
|
try:
|
||||||
|
# Track agent execution depth
|
||||||
|
current_depth = _global_memory.get('agent_depth', 0)
|
||||||
|
_global_memory['agent_depth'] = current_depth + 1
|
||||||
|
|
||||||
for attempt in range(max_retries):
|
for attempt in range(max_retries):
|
||||||
check_interrupt()
|
check_interrupt()
|
||||||
try:
|
try:
|
||||||
|
|
@ -325,5 +329,8 @@ def run_agent_with_retry(agent, prompt: str, config: dict) -> Optional[str]:
|
||||||
check_interrupt()
|
check_interrupt()
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
finally:
|
finally:
|
||||||
|
# Reset depth tracking
|
||||||
|
_global_memory['agent_depth'] = _global_memory.get('agent_depth', 1) - 1
|
||||||
|
|
||||||
if original_handler and threading.current_thread() is threading.main_thread():
|
if original_handler and threading.current_thread() is threading.main_thread():
|
||||||
signal.signal(signal.SIGINT, original_handler)
|
signal.signal(signal.SIGINT, original_handler)
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ def request_research(query: str) -> ResearchResult:
|
||||||
model = initialize_llm(config.get('provider', 'anthropic'), config.get('model', 'claude-3-5-sonnet-20241022'))
|
model = initialize_llm(config.get('provider', 'anthropic'), config.get('model', 'claude-3-5-sonnet-20241022'))
|
||||||
|
|
||||||
# Check recursion depth
|
# Check recursion depth
|
||||||
current_depth = _global_memory.get('research_depth', 0)
|
current_depth = _global_memory.get('agent_depth', 0)
|
||||||
if current_depth >= RESEARCH_AGENT_RECURSION_LIMIT:
|
if current_depth >= RESEARCH_AGENT_RECURSION_LIMIT:
|
||||||
print_error("Maximum research recursion depth reached")
|
print_error("Maximum research recursion depth reached")
|
||||||
return {
|
return {
|
||||||
|
|
@ -50,9 +50,6 @@ def request_research(query: str) -> ResearchResult:
|
||||||
reason = None
|
reason = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Increment depth counter
|
|
||||||
_global_memory['research_depth'] = current_depth + 1
|
|
||||||
|
|
||||||
# Run research agent
|
# Run research agent
|
||||||
from ..agent_utils import run_research_agent
|
from ..agent_utils import run_research_agent
|
||||||
result = run_research_agent(
|
result = run_research_agent(
|
||||||
|
|
@ -72,15 +69,12 @@ def request_research(query: str) -> ResearchResult:
|
||||||
success = False
|
success = False
|
||||||
reason = f"error: {str(e)}"
|
reason = f"error: {str(e)}"
|
||||||
finally:
|
finally:
|
||||||
# Always decrement depth counter
|
# Get completion message if available
|
||||||
_global_memory['research_depth'] = current_depth
|
completion_message = _global_memory.get('completion_message', 'Task was completed successfully.' if success else None)
|
||||||
|
|
||||||
# Get completion message if available
|
# Clear completion state from global memory
|
||||||
completion_message = _global_memory.get('completion_message', 'Task was completed successfully.' if success else None)
|
_global_memory['completion_message'] = ''
|
||||||
|
_global_memory['task_completed'] = False
|
||||||
# Clear completion state from global memory
|
|
||||||
_global_memory['completion_message'] = ''
|
|
||||||
_global_memory['task_completed'] = False
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"completion_message": completion_message,
|
"completion_message": completion_message,
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ _global_memory: Dict[str, Union[List[Any], Dict[int, str], Dict[int, SnippetInfo
|
||||||
'related_files': {}, # Dict[int, str] - ID to filepath mapping
|
'related_files': {}, # Dict[int, str] - ID to filepath mapping
|
||||||
'related_file_id_counter': 1, # Counter for generating unique file IDs
|
'related_file_id_counter': 1, # Counter for generating unique file IDs
|
||||||
'plan_completed': False,
|
'plan_completed': False,
|
||||||
'research_depth': 0,
|
'agent_depth': 0,
|
||||||
'work_log': [] # List[WorkLogEntry] - Timestamped work events
|
'work_log': [] # List[WorkLogEntry] - Timestamped work events
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -340,6 +340,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
|
||||||
_global_memory['tasks'].clear() # Clear task list when plan is completed
|
_global_memory['tasks'].clear() # Clear task list when plan is completed
|
||||||
|
_global_memory['task_id_counter'] = 1
|
||||||
console.print(Panel(Markdown(message), title="✅ Plan Executed"))
|
console.print(Panel(Markdown(message), title="✅ Plan Executed"))
|
||||||
log_work_event(f"Plan execution completed: {message}")
|
log_work_event(f"Plan execution completed: {message}")
|
||||||
return "Plan completion noted and task list cleared."
|
return "Plan completion noted and task list cleared."
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue