From ff34f98e3adf7899fb3857eabb80471ca51f8156 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Thu, 4 Jun 2026 14:49:45 -0400 Subject: Add locked-down research tools --- main.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'main.py') diff --git a/main.py b/main.py index 5e1e61a..af4f657 100644 --- a/main.py +++ b/main.py @@ -35,21 +35,20 @@ TICKER_RE = re.compile(r"\$([A-Z]{1,5})") # Regex to detect @mention of slop / slopbot MENTION_RE = re.compile(r"@\*\*slop[^*]*\*\*", re.IGNORECASE) +BASE_DIR = Path(__file__).parent + AGENT_TIMEOUT = int(os.environ.get("SLOPBOT_AGENT_TIMEOUT", "120")) AGENT_MODEL = os.environ.get("SLOPBOT_AGENT_MODEL", "parasail/kimi-k26") AGENT_BIN = os.environ.get("SLOPBOT_AGENT", "agent") +AGENT_PATH = os.environ.get("SLOPBOT_AGENT_PATH", os.environ.get("PATH", "")) WORKERS = int(os.environ.get("SLOPBOT_WORKERS", "4")) AGENT_WORKERS = int(os.environ.get("SLOPBOT_AGENT_WORKERS", "1")) -HISTORY_LIMIT = 20 +HISTORY_LIMIT = int(os.environ.get("SLOPBOT_HISTORY_LIMIT", "20")) +SYSTEM_PROMPT_PATH = Path(os.environ.get("SLOPBOT_SYSTEM_PROMPT", "prompts/system.md")) +if not SYSTEM_PROMPT_PATH.is_absolute(): + SYSTEM_PROMPT_PATH = BASE_DIR / SYSTEM_PROMPT_PATH -SYSTEM_PROMPT = """You are slop-bot in the meshheads.org Zulip chat: technically sharp, -opinionated, libertarian-leaning, dryly funny, and peer-level with the audience. -Assume the audience knows CS basics; do not over-explain and do not be obsequious. -Use the provided topic history for conversational context, but answer the latest user. -Search the web for current facts, news, sources, or prices using your search tool; -when you use it, cite source URLs in your final answer. -Keep replies short (2-4 sentences max unless asked for more). -You are participating in an ongoing Zulip thread. Stay in character.""" +SYSTEM_PROMPT = SYSTEM_PROMPT_PATH.read_text().strip() log.info("Connecting to Zulip...") client = zulip.Client(config_file=".zuliprc") @@ -112,14 +111,16 @@ def fetch_topic_history(msg: dict, limit: int = HISTORY_LIMIT) -> str: def _agent(prompt: str) -> tuple[int, str, str]: """Run agent once; return (returncode, stdout, stderr).""" + env = os.environ.copy() + env["PATH"] = AGENT_PATH result = subprocess.run( [ AGENT_BIN, "--model", AGENT_MODEL, - "--eval-cwd", str(Path(__file__).parent), + "--eval-cwd", str(BASE_DIR), prompt, ], - capture_output=True, text=True, timeout=AGENT_TIMEOUT, + capture_output=True, text=True, timeout=AGENT_TIMEOUT, env=env, ) return result.returncode, result.stdout.strip(), result.stderr.strip() -- cgit v1.2.3