# agents/repl.py import time from datetime import datetime from tools.context_builder import build_contexts, build_prompt 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 ( detect_stagnation, activate_anti_stagnation, update_llm_memory ) from tools.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) db.update_agent_log(timestamp=tick_start) # 7. ΠŸΠ΅Ρ€Π΅Ρ…ΠΎΠ΄ Π² idle-Ρ€Π΅ΠΆΠΈΠΌ ΠΈΠ»ΠΈ Π·Π°Π΄Π΅Ρ€ΠΆΠΊΠ° if config.get("idle_mode"): # TODO: Ρ€Π΅Π°Π»ΠΈΠ·ΠΎΠ²Π°Ρ‚ΡŒ ΠΏΡ€ΠΎΠ²Π΅Ρ€ΠΊΡƒ условий Π²Ρ‹Ρ…ΠΎΠ΄Π° ΠΈΠ· idle print("πŸ’€ Idle-mode Π°ΠΊΡ‚ΠΈΠ²Π΅Π½. ОТиданиС события...") time.sleep(config.get("idle_check_interval", 30)) else: time.sleep(config.get("repl_interval", 5))