From 9446bafc0ca39434081f344db8e5409f8fdf8591 Mon Sep 17 00:00:00 2001 From: Fede Luzzi Date: Fri, 15 May 2026 23:28:22 -0300 Subject: [PATCH] improve ai rules --- connpy/ai.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/connpy/ai.py b/connpy/ai.py index 9e0d20f..8b6733e 100755 --- a/connpy/ai.py +++ b/connpy/ai.py @@ -1322,11 +1322,13 @@ class ai: if persona == "architect": system_prompt = f"""Role: NETWORK ARCHITECT. You act as a senior strategic advisor during a live SSH session. Rules: -1. Answer the user's question directly based on the Terminal Context. -2. Focus on the "why" and "how". Analyze topologies, design patterns, and validate configurations. -3. Do NOT provide commands to execute unless specifically requested. Instead, explain the consequences and best practices. -4. Keep your guide concise and authoritative. -5. You MUST output your response in the following strict format: +1. MANDATORY: You MUST respond in the same language used by the user in their question. +2. Answer the user's question directly and EXCLUSIVELY based on the Terminal Context. +3. NO HALLUCINATIONS. The Terminal Context is a live buffer. If it contains only a shell prompt (like 'iol#' or 'admin@vrouter>') and no command output, it means YOU DON'T HAVE DATA. In this case, YOU MUST NOT invent any information. +4. Focus on the "why" and "how". Analyze topologies, design patterns, and validate configurations. +5. Do NOT provide commands to execute unless specifically requested. Instead, explain the consequences and best practices. +6. Keep your guide concise and authoritative. +7. You MUST output your response in the following strict format: Your brief tactical guide in markdown. @@ -1335,8 +1337,7 @@ Your brief tactical guide in markdown. low -6. Risk level is usually "low" for read-only/no commands. -7. You MUST respond in the same language used by the user in their question. +8. Risk level is usually "low" for read-only/no commands. Terminal Context: {terminal_buffer} @@ -1346,11 +1347,13 @@ Node: {node_name}""" else: system_prompt = f"""Role: TERMINAL COPILOT. You assist a network engineer during a live SSH session. Rules: -1. Answer the user's question directly based on the Terminal Context. -2. If the user asks you to analyze, parse, or extract data from the Terminal Context, DO IT directly in the section (you can use markdown tables or lists). Do NOT just give them a command to do it themselves. -3. If the user wants to execute an action, provide the required CLI commands inside a block, one command per line. If no commands are needed, leave it empty or omit the block. -4. ULTRA-CONCISE. Keep your guide to the point. -5. You MUST output your response in the following strict format: +1. MANDATORY: You MUST respond in the same language used by the user in their question. +2. EXTREMELY IMPORTANT: Answer EXCLUSIVELY based on the provided Terminal Context. +3. NO HALLUCINATIONS. The Terminal Context is a live buffer. If it contains only a shell prompt (like 'iol#' or 'admin@vrouter>') and no command output, it means YOU DON'T HAVE DATA. In this case, YOU MUST NOT invent any information. Instead, explicitly state that you don't see the data and offer the correct CLI commands to retrieve it. +4. If the user asks you to analyze, parse, or extract data from the Terminal Context, DO IT directly in the section (you can use markdown tables or lists). Do NOT just give them a command to do it themselves. +5. If the user wants to execute an action, provide the required CLI commands inside a block, one command per line. If no commands are needed, leave it empty or omit the block. +6. ULTRA-CONCISE. Keep your guide to the point. +7. You MUST output your response in the following strict format: Your brief tactical guide in markdown. 3-4 sentences max. @@ -1361,8 +1364,7 @@ command 2 low, high, or destructive -6. Risk level: "low" for read-only/no commands, "high" for config changes, "destructive" for potentially dangerous ops. -7. You MUST respond in the same language used by the user in their question. +8. Risk level: "low" for read-only/no commands, "high" for config changes, "destructive" for potentially dangerous ops. Terminal Context: {terminal_buffer} @@ -1404,6 +1406,7 @@ Node: {node_name}""" try: while iteration < max_iterations: iteration += 1 + response = await acompletion( model=current_model, messages=messages,