Track agent depth for all agents.

This commit is contained in:
user 2024-12-23 12:05:39 -05:00
parent c261c741f9
commit 9a53940dcd
3 changed files with 15 additions and 13 deletions

View File

@ -306,6 +306,10 @@ def run_agent_with_retry(agent, prompt: str, config: dict) -> Optional[str]:
with InterruptibleSection():
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):
check_interrupt()
try:
@ -325,5 +329,8 @@ def run_agent_with_retry(agent, prompt: str, config: dict) -> Optional[str]:
check_interrupt()
time.sleep(0.1)
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():
signal.signal(signal.SIGINT, original_handler)

View File

@ -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'))
# 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:
print_error("Maximum research recursion depth reached")
return {
@ -50,9 +50,6 @@ def request_research(query: str) -> ResearchResult:
reason = None
try:
# Increment depth counter
_global_memory['research_depth'] = current_depth + 1
# Run research agent
from ..agent_utils import run_research_agent
result = run_research_agent(
@ -72,9 +69,6 @@ def request_research(query: str) -> ResearchResult:
success = False
reason = f"error: {str(e)}"
finally:
# Always decrement depth counter
_global_memory['research_depth'] = current_depth
# Get completion message if available
completion_message = _global_memory.get('completion_message', 'Task was completed successfully.' if success else None)

View File

@ -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_file_id_counter': 1, # Counter for generating unique file IDs
'plan_completed': False,
'research_depth': 0,
'agent_depth': 0,
'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['completion_message'] = message
_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"))
log_work_event(f"Plan execution completed: {message}")
return "Plan completion noted and task list cleared."