DeepResearch icon indicating copy to clipboard operation
DeepResearch copied to clipboard

Bug: react_agent

Open zhudanhao opened this issue 5 months ago • 2 comments

Line 163: code_raw=content.split('<tool_call>')[1].split('</tool_call>')[0].split('')[1].split('')[0].strip()

The content contains the .... If '<tool_call>' is included in thinking, this parser will get a tool calling from the first internal thinking, rather than final output.

For example:

content = """ 看起来这个工具期望一个 JSON 对象,其属性是 "name" 和 "arguments"。在之前的尝试中,我使用了错误的格式。正确的消息格式是:

<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.

zhudanhao avatar Sep 22 '25 01:09 zhudanhao

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 ~

zhudanhao avatar Sep 22 '25 01:09 zhudanhao

i have save err, try to rewrite these code, it will be ok

shenzifanhy avatar Sep 25 '25 12:09 shenzifanhy