# agents/repl.py import time from datetime import datetime from tools.context_builder import build_contexts from tools.llm import call_llm from tools.command_parser import extract_commands from tools.command_executor import execute_commands from tools.memory_utils import update_llm_memory, detect_stagnation from storage import Storage def run_repl(config=None): print("[🧠 HMP-Agent] Запуск REPL-Ρ€Π΅ΠΆΠΈΠΌΠ° (v2).") config = config or {} db = Storage(config=config) while True: tick_start = datetime.utcnow().isoformat() print(f"\n=== [πŸŒ€ Новый Ρ‚ΠΈΠΊ REPL] {tick_start} ===") # 1. ΠŸΠΎΡΡ‚Ρ€ΠΎΠ΅Π½ΠΈΠ΅ контСкстов contexts = build_contexts(db=db, config=config) # 2. Π€ΠΎΡ€ΠΌΠΈΡ€ΠΎΠ²Π°Π½ΠΈΠ΅ запроса ΠΊ LLM prompt = build_prompt(contexts) llm_response = call_llm(prompt, config=config) # 3. ΠžΠ±Π½Π°Ρ€ΡƒΠΆΠ΅Π½ΠΈΠ΅ стагнации if detect_stagnation(db, llm_response): print("⚠️ Бтагнация выявлСна. Активирован Anti-Stagnation Reflex.") llm_response = activate_anti_stagnation(db, config=config) # 4. ОбновлСниС памяти update_llm_memory(db, llm_response) # 5. Π˜Π·Π²Π»Π΅Ρ‡Π΅Π½ΠΈΠ΅ ΠΈ Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ ΠΊΠΎΠΌΠ°Π½Π΄ commands = extract_commands(llm_response) execute_commands(commands, db=db, config=config) # 6. Π‘ΠΎΡ…Ρ€Π°Π½Π΅Π½ΠΈΠ΅ истории db.write_llm_response(llm_response) # 7. Π£ΠΏΡ€Π°Π²Π»Π΅Π½ΠΈΠ΅ Ρ€Π΅ΠΆΠΈΠΌΠ°ΠΌΠΈ оТидания if check_idle_mode(config): wait_idle_trigger(config) else: time.sleep(config.get("repl_interval", 5))