tenseleyflow/loader / a97c3af

Browse files

fix: improve chatbot mode detection and recovery

Enhances detection of tutorial-style responses to catch small models that give
numbered instructions instead of using tools.

**New Detection Patterns:**
- Numbered lists (1., 2., 3. Open..., Create..., Navigate...)
- Sequenced steps (First..., Next..., Then...)
- Tutorial starters ('Open your terminal...', 'Navigate to...')
- How-to preambles ('Here's how you can...')

**Stronger Steering:**
- More explicit error message when chatbot mode is detected
- Clear examples of what NOT to do vs what TO do
- User-visible warning when auto-correction is triggered

This helps smaller models like llama3.2:3b stay in agent mode instead
of reverting to chatbot/tutorial behavior.
Authored by espadonne
SHA
a97c3af7ade0f5d5341357f7127a66f165d5f912
Parents
ee05471
Tree
9cad6c4

1 changed file

StatusFile+-
M src/loader/agent/loop.py 28 3
src/loader/agent/loop.pymodified
@@ -1288,15 +1288,25 @@ class Agent:
12881288
             # No tool calls - check if model is describing instead of acting
12891289
             if self._contains_unexecuted_code(content) and iterations < self.config.max_iterations - 1:
12901290
                 # Model outputted code blocks without using tools - nudge it
1291
+                await emit(AgentEvent(
1292
+                    type="error",
1293
+                    content="⚠ Chatbot mode detected - steering agent to use tools instead of giving instructions",
1294
+                ))
12911295
                 self.messages.append(Message(
12921296
                     role=Role.ASSISTANT,
12931297
                     content=response_content,
12941298
                 ))
12951299
                 self.messages.append(Message(
12961300
                     role=Role.USER,
1297
-                    content="STOP. Do not show me code to copy. USE YOUR TOOLS to execute the actions. "
1298
-                            "Call the bash tool to run commands. Call the write tool to create files. "
1299
-                            "Execute the task NOW using tool calls.",
1301
+                    content="CRITICAL ERROR: You are giving me instructions to copy instead of EXECUTING the task.\n\n"
1302
+                            "DO NOT write:\n"
1303
+                            "- Numbered steps (1., 2., 3.)\n"
1304
+                            "- Instructions like 'Open your terminal...'\n"
1305
+                            "- Code blocks for me to copy\n"
1306
+                            "- 'You can run...', 'Create this file...'\n\n"
1307
+                            "INSTEAD: Use your bash and write tools RIGHT NOW to execute the task.\n"
1308
+                            "Example: [call write tool], [call bash tool]\n"
1309
+                            "DO IT NOW - don't describe it.",
13001310
                 ))
13011311
                 continue
13021312
 
@@ -1573,8 +1583,23 @@ class Agent:
15731583
             'execute this', 'paste this',
15741584
         ]
15751585
 
1586
+        # Tutorial/instruction patterns
1587
+        tutorial_patterns = [
1588
+            r'^\s*\d+\.\s+(open|create|navigate|run|execute|make)',  # Numbered instructions
1589
+            r'(first|second|third|next|then),?\s+(open|create|navigate)',  # Sequenced steps
1590
+            r'open your (terminal|command|shell)',  # Tutorial starter
1591
+            r'navigate to (the|your|~/)',  # Navigation instruction
1592
+            r'here\'s how you can (quickly|easily)?',  # How-to preamble
1593
+            r'you can (start by|begin by|follow these)',  # Tutorial start
1594
+        ]
1595
+
15761596
         content_lower = content.lower()
15771597
 
1598
+        # Check for tutorial patterns
1599
+        for pattern in tutorial_patterns:
1600
+            if re.search(pattern, content_lower, re.MULTILINE | re.IGNORECASE):
1601
+                return True
1602
+
15781603
         # If chatbot phrases present with code blocks, it's describing not doing
15791604
         for phrase in chatbot_phrases:
15801605
             if phrase in content_lower: