|
|
|
|
|
|
|
|
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} ===") |
|
|
|
|
|
|
|
|
contexts = build_contexts(db=db, config=config) |
|
|
|
|
|
|
|
|
prompt = build_prompt(contexts) |
|
|
llm_response = call_llm(prompt, config=config) |
|
|
|
|
|
|
|
|
if detect_stagnation(db, llm_response): |
|
|
print("⚠️ Стагнация выявлена. Активирован Anti-Stagnation Reflex.") |
|
|
llm_response = activate_anti_stagnation(db, config=config) |
|
|
|
|
|
|
|
|
update_llm_memory(db, llm_response) |
|
|
|
|
|
|
|
|
commands = extract_commands(llm_response) |
|
|
execute_commands(commands, db=db, config=config) |
|
|
|
|
|
|
|
|
db.write_llm_response(llm_response) |
|
|
db.update_agent_log(timestamp=tick_start) |
|
|
|
|
|
|
|
|
if config.get("idle_mode"): |
|
|
|
|
|
print("💤 Idle-mode активен. Ожидание события...") |
|
|
time.sleep(config.get("idle_check_interval", 30)) |
|
|
else: |
|
|
time.sleep(config.get("repl_interval", 5)) |
|
|
|