auto-sync: 2026-05-26 23:28:23

This commit is contained in:
cfdaily
2026-05-26 23:28:23 +08:00
parent 3d5ca48a9c
commit 62fb62f981
+28 -21
View File
@@ -75,29 +75,36 @@ def extract_text_from_content(content) -> str:
return ' '.join(parts)
def extract_tool_info(content) -> tuple:
"""Extract tool names and whether there are tool_results with errors."""
if not isinstance(content, list):
return [], False
def extract_tool_info(role: str, content) -> tuple:
"""Extract tool names and whether there are tool_results with errors.
v3 format: toolCall blocks in assistant messages, toolResult as separate role.
"""
tool_uses = []
has_error = False
for block in content:
if not isinstance(block, dict):
continue
btype = block.get('type', '')
if btype == 'tool_use':
tool_uses.append(block.get('name', ''))
elif btype == 'tool_result':
result_text = ''
rc = block.get('content', '')
if isinstance(rc, str):
result_text = rc
elif isinstance(rc, list):
for sub in rc:
if isinstance(sub, dict) and sub.get('type') == 'text':
result_text += sub.get('text', '')
if any(e in result_text for e in ERROR_INDICATORS):
has_error = True
# Extract tool calls from assistant messages
if isinstance(content, list):
for block in content:
if not isinstance(block, dict):
continue
btype = block.get('type', '')
# v3 uses 'toolCall', some formats use 'tool_use'
if btype in ('toolCall', 'tool_use'):
tool_uses.append(block.get('name', ''))
# Check for errors in toolResult role messages
if role == 'toolResult':
result_text = ''
if isinstance(content, str):
result_text = content
elif isinstance(content, list):
for sub in content:
if isinstance(sub, dict) and sub.get('type') == 'text':
result_text += sub.get('text', '')
if any(e in result_text for e in ERROR_INDICATORS):
has_error = True
return tool_uses, has_error