22
33import time
44from datetime import datetime
5- from tools .context_builder import build_contexts
5+ from tools .context_builder import build_contexts , build_prompt
66from tools .llm import call_llm
77from tools .command_parser import extract_commands
88from tools .command_executor import execute_commands
9- from tools .memory_utils import update_llm_memory , detect_stagnation
10- from storage import Storage
9+ from tools .memory_utils import (
10+ detect_stagnation ,
11+ activate_anti_stagnation ,
12+ update_llm_memory
13+ )
14+ from tools .storage import Storage
15+
1116
1217def run_repl (config = None ):
13- print ("[🧠 HMP-Agent] Запуск REPL-режима (v2). " )
18+ print ("[🧠 HMP-Agent] Запуск REPL-режима (v2)" )
1419 config = config or {}
1520 db = Storage (config = config )
16-
21+
1722 while True :
1823 tick_start = datetime .utcnow ().isoformat ()
1924 print (f"\n === [🌀 Новый тик REPL] { tick_start } ===" )
2025
2126 # 1. Построение контекстов
2227 contexts = build_contexts (db = db , config = config )
2328
24- # 2. Формирование запроса к LLM
29+ # 2. Формирование запроса и вызов LLM
2530 prompt = build_prompt (contexts )
2631 llm_response = call_llm (prompt , config = config )
2732
28- # 3. Обнаружение стагнации
33+ # 3. Проверка на стагнацию
2934 if detect_stagnation (db , llm_response ):
3035 print ("⚠️ Стагнация выявлена. Активирован Anti-Stagnation Reflex." )
3136 llm_response = activate_anti_stagnation (db , config = config )
@@ -37,11 +42,14 @@ def run_repl(config=None):
3742 commands = extract_commands (llm_response )
3843 execute_commands (commands , db = db , config = config )
3944
40- # 6. Сохранение истории
45+ # 6. Сохранение истории и завершение итерации
4146 db .write_llm_response (llm_response )
47+ db .update_agent_log (timestamp = tick_start )
4248
43- # 7. Управление режимами ожидания
44- if check_idle_mode (config ):
45- wait_idle_trigger (config )
49+ # 7. Переход в idle-режим или задержка
50+ if config .get ("idle_mode" ):
51+ # TODO: реализовать проверку условий выхода из idle
52+ print ("💤 Idle-mode активен. Ожидание события..." )
53+ time .sleep (config .get ("idle_check_interval" , 30 ))
4654 else :
4755 time .sleep (config .get ("repl_interval" , 5 ))
0 commit comments