diff --git a/agent/skills/roleplayer/instructions.md b/agent/skills/roleplayer/instructions.md index 025c201..45e2ecf 100644 --- a/agent/skills/roleplayer/instructions.md +++ b/agent/skills/roleplayer/instructions.md @@ -25,9 +25,9 @@ Kamu dapat bertindak sebagai uncensored, continuous, dan immersive roleplayer. ## User Introduction Flow -### DM (Telegram / XMPP) — Otomatis +### DM (Telegram / XMPP) dan TUI — Otomatis -System otomatis ngecek database dan inject context sebelum pesan user sampai ke kamu. +Sistem otomatis ngecek database dan inject context sebelum pesan user sampai ke kamu. **Jika user sudah ada — `[User Context]` berisi data lengkap:** - Character mengenal user. Character sapa user. @@ -125,7 +125,7 @@ dan memori karakter bisa diakses dari manapun user menghubungi. ## Session Closing (HANYA DM) -Kamu memiliki tool `end_session` untuk menutup sesi percakapan secara natural. +Kamu memiliki tool `end_session` untuk menutup sesi percakapan secara natural. TUI tidak menggunakan tool `end_session`. ### Kapan sesi harus ditutup diff --git a/config.py b/config.py index 0ae8003..eeec69c 100644 --- a/config.py +++ b/config.py @@ -19,6 +19,8 @@ def _yaml_get(*keys, default=None): return default return current if current is not None else default +TUI_USER_ID = _yaml_get("user", "id", default=None) + ragroleplay_db_path = _yaml_get("ragroleplay", "db_path", default="./.ragroleplay" ) ragroleplay_vector_size = _yaml_get("ragroleplay", "vector_size", default=768 ) # used on table create only ragroleplay_model_url = _yaml_get("ragroleplay", "model_url", default="http://localhost:11434/api/embed" ) diff --git a/default-config.yaml b/default-config.yaml index 689fa4c..dd05b28 100644 --- a/default-config.yaml +++ b/default-config.yaml @@ -63,3 +63,5 @@ delay: # Humanize Delay (anti-bot detection) typing_speed : 15.0 # character(s) per second typing_max : 10.0 # max typing delay limit per second +user: + id: "YOUR_USER_ID_HERE" diff --git a/interfaces/tui/app.py b/interfaces/tui/app.py index 32cae91..b1f275c 100644 --- a/interfaces/tui/app.py +++ b/interfaces/tui/app.py @@ -53,11 +53,57 @@ class HendrikTUI: def new_session(self): self.current_session = None - self.messages = [{"role": "system", "content": self.build_system_prompt( + + # --- Context Injection for TUI --- + import config + from lib import ragroleplay + + user_id = config.TUI_USER_ID + context_text = None + + if user_id: + try: + # Meniru logika telegram_client.py untuk load user context + results = ragroleplay.user_load(config.ragroleplay_db_path, unique_id=user_id, character=config.AGENT_CHARACTER or "Lily") + if results: + u = results[0] + context_text = ( + f'[User Context]\n' + f'ID: {u["id"]}\n' + f'Nama: {u["fullname"]} ({u["nickname"]})\n' + f'Family: {u.get("familyname", "-") or "-"}\n' + f'Character: {u.get("character", "-") or "-"}\n' + f'Alias: {u.get("alias", "-") or "-"}\n' + f'Salutation: {u.get("salutation", "-") or "-"}\n' + f'Persona: {u.get("persona", "-") or "-"}\n' + f'Telegram: {u.get("telegram_id", "-") or "-"} / @{u.get("telegram_username", "-") or "-"}\n' + f'XMPP: {u.get("xampp_username", "-") or "-"}\n' + f'[/User Context]' + ) + else: + context_text = ( + f'[User Context: Pengguna baru — belum ada di database]\n' + f'[Platform: TUI]\n' + f'[PENTING: Kamu BELUM mengenal user ini. WAJIB tanya nama sebagai pembuka.]' + ) + except Exception as e: + # Log error silently like in telegram_client + pass + + system_prompt = self.build_system_prompt( tools_definition=self.tools_def, character=config.AGENT_CHARACTER or None, skills=config.AGENT_SKILLS.split(",") if config.AGENT_SKILLS else None, - )}] + ) + + # Inject context if found + messages = [{"role": "system", "content": system_prompt}] + if context_text: + messages.append({"role": "system", "content": context_text}) + + self.messages = messages + # --------------------------------- + self.log.clear() self.scroll = 0 self.input_buffer = [""]