tenseleyflow/loader / 4d661fd

Browse files

debug: add logging to trace bracket-format tool call extraction

Authored by espadonne
SHA
4d661fdcf4a387f892bab7929afc22df40344a08
Parents
67e6c0d
Tree
ddec648

1 changed file

StatusFile+-
M src/loader/agent/loop.py 35 0
src/loader/agent/loop.pymodified
@@ -993,7 +993,19 @@ class Agent:
993993
             # No tool calls - check if model outputted raw JSON tool calls as text
994994
             # Some small models do this instead of using the proper API
995995
             if not tool_calls:
996
+                try:
997
+                    with open("/tmp/loader_debug.log", "a") as f:
998
+                        f.write(f"[loop] no tool_calls, checking for raw JSON/bracket format in content (len={len(content)})\n")
999
+                except Exception:
1000
+                    pass
9961001
                 raw_tool_calls = self._extract_raw_json_tool_calls(content)
1002
+                try:
1003
+                    with open("/tmp/loader_debug.log", "a") as f:
1004
+                        f.write(f"[loop] _extract_raw_json_tool_calls returned {len(raw_tool_calls)} calls\n")
1005
+                        for tc in raw_tool_calls:
1006
+                            f.write(f"[loop]   - {tc.name}: {list(tc.arguments.keys())}\n")
1007
+                except Exception:
1008
+                    pass
9971009
                 if raw_tool_calls:
9981010
                     # Successfully extracted tool calls from raw JSON - use them
9991011
                     tool_calls = raw_tool_calls
@@ -1002,9 +1014,19 @@ class Agent:
10021014
 
10031015
             # If we now have tool calls (from raw JSON extraction), execute them
10041016
             if tool_calls:
1017
+                try:
1018
+                    with open("/tmp/loader_debug.log", "a") as f:
1019
+                        f.write(f"[loop] executing {len(tool_calls)} extracted tool calls\n")
1020
+                except Exception:
1021
+                    pass
10051022
                 # This duplicates the tool execution logic above, but that's intentional
10061023
                 # to handle the case where raw JSON tool calls are extracted
10071024
                 for tc in tool_calls:
1025
+                    try:
1026
+                        with open("/tmp/loader_debug.log", "a") as f:
1027
+                            f.write(f"[loop] executing extracted tool: {tc.name} args={tc.arguments}\n")
1028
+                    except Exception:
1029
+                        pass
10081030
                     actions_taken.append(f"{tc.name}: {str(tc.arguments)[:50]}...")
10091031
                     await emit(AgentEvent(
10101032
                         type="tool_call",
@@ -1343,6 +1365,16 @@ class Agent:
13431365
         tool_calls = []
13441366
         tool_names = ["write", "read", "edit", "bash", "glob", "grep"]
13451367
 
1368
+        # Debug log
1369
+        def debug(msg):
1370
+            try:
1371
+                with open("/tmp/loader_debug.log", "a") as f:
1372
+                    f.write(f"[extract] {msg}\n")
1373
+            except Exception:
1374
+                pass
1375
+
1376
+        debug(f"checking content len={len(content)}")
1377
+
13461378
         # First, try to extract bracket format: [calls bash tool with: ...]
13471379
         # or [USE bash tool: ...] or similar variations
13481380
         bracket_patterns = [
@@ -1352,11 +1384,14 @@ class Agent:
13521384
         ]
13531385
 
13541386
         for pattern in bracket_patterns:
1387
+            debug(f"trying pattern: {pattern}")
13551388
             for match in re.finditer(pattern, content, re.IGNORECASE):
13561389
                 tool_name = match.group(1).lower()
13571390
                 args_str = match.group(2).strip()
1391
+                debug(f"  matched: tool={tool_name}, args={args_str[:50]}...")
13581392
 
13591393
                 if tool_name not in tool_names:
1394
+                    debug(f"  skipping - tool_name '{tool_name}' not in tool_names")
13601395
                     continue
13611396
 
13621397
                 try: