OpenBMB / XAgent

An Autonomous LLM Agent for Complex Task Solving
https://blog.x-agent.net/blog/xagent/
Apache License 2.0
7.82k stars 794 forks source link

执行python run.py 的时候报错KeyError: 0,错误定位在plan_exec.py line 178 #396

Open PowerQi opened 2 months ago

PowerQi commented 2 months ago

Issue Description / 问题描述

执行python run.py 的时候报错KeyError: 0,错误定位在plan_exec.py line 178

Steps to Reproduce / 复现步骤

在XAgent-server容器的实例,控制台执行python run.py --task "- I want to play game of 24, which use +, -, *, / to get 24 using 4 numbers. Each number can be used only once. Please give me 5 example combinations of numbers that can get 24. Write codes and show me!" --config-file "assets/config.yml"

Expected Behavior / 预期行为

按要求返回5个24游戏的示例

Environment / 环境信息

image

Error Screenshots or Logs / 错误截图或日志

image

Additional Notes / 其他备注

GPT4接口调用成功,有调用记录

LostQuant commented 2 months ago

Same error, suspecting this is something to do with the "TODO" label ?

line 163: "# TODO: not robust. dispatcher generated prompt may not contain these specified placeholders?"

BTW, this is my env (tho its probably not relevant at all :)

Name Version Build Channel

json5 0.9.25 pypi_0 pypi python 3.11.7 he1021f5_0 pycparser 2.22 pypi_0 pypi

LostQuant commented 2 months ago

After a few rounds of trial and error, this error is because, somehow, the new_message["function_call"]["arguments"] in line 178 of plan_exec.py is already an python object, causing the `json5.loads function fail to parse it.

subtasks = json5.loads(new_message["function_call"]["arguments"])

A quickfix is bypassing the json5.loads and simply assign the object to subtasks, unless it is indeed a STR or BYTES e.g.:

        subtasks = new_message["function_call"]["arguments"] 

        # To preserve the original flow in case `subtasks` is a string or bytes
        if isinstance(subtasks, (str, bytes)):
            subtasks = json5.loads(subtasks)
LostQuant commented 2 months ago

It turns out that everytime when its trying to parse serialized objects using JSON5.loads, the objects may NOT be serialized (but a simple DICT). So has to do the check everywhere when JSON5.loads is called. (at least under the OPENAI mode)

Raised the PR above hopefully the maintainer will approve and checkin the main branch.