Bug: react_agent
Line 163:
code_raw=content.split('<tool_call>')[1].split('</tool_call>')[0].split('')[1].split('')[0].strip()
The content contains the
For example:
content = """
<tool_call> {"name": "cssci_sql_query", "arguments": {"query": "..."}} </tool_call>
我们来试试那个。
<tool_call> {"name": "cssci_sql_query", "arguments": {"query": "SELECT title, author, year FROM cssci2023.cssci ORDER BY random() LIMIT 5;"}} </tool_call>"""
tool_call = content.split('<tool_call>')[-1].split('</tool_call>')[0] print(tool_call)
{'name': 'cssci_sql_query', 'arguments': {'query': '...'}}
However, we should want to get: {"name": "cssci_sql_query", "arguments": {"query": "SELECT title, author, year FROM cssci2023.cssci ORDER BY random() LIMIT 5;"}}
How to fix it:
code_raw=content.split('<tool_call>')[-1].split('</tool_call>')[0].split('')[1].split('')[0].strip()
Using the final <tool_call> block instead the first one.
Further, such exception parsing entirely break the tool using errors reporting. The LLM knows nothing about what errors really happen during tool using, and completely lead the llm to a false debugging direction.
try:
if "python" in tool_call.lower():
try:
code_raw=content.split('<tool_call>')[1].split('</tool_call>')[0].split('')[1].split('')[0].strip()
result = self.tool_map['PythonInterpreter'].call(code_raw)
except:
result = "[Python Interpreter Error]: Formatting error."
else:
tool_call = json5.loads(tool_call)
tool_name = tool_call.get('name', '')
tool_args = tool_call.get('arguments', {})
result = self.custom_call_tool(tool_name, tool_args)
except Exception as e:
result = 'Error: Tool call is not a valid JSON. Tool call must contain a valid "name" and "arguments" field.'
Look here: result = 'Error: Tool call is not a valid JSON. Tool call must contain a valid "name" and "arguments" field.' If a wrong sql is written, the tool still return 'Error: Tool call is not a valid JSON. Tool call must contain a valid "name" and "arguments" field.' This is definitely a wrong direction ~
i have save err, try to rewrite these code, it will be ok