agentscope icon indicating copy to clipboard operation
agentscope copied to clipboard

[Bug]:react_agent 执行完tool后开始胡乱回答,并没有使用tool执行的结果

Open ForgetThatNight opened this issue 1 year ago • 1 comments

Describe the bug query:品质最高的装备

################################################################################ ##################### ITER 1, STEP 1: REASONING ###################### 2024-04-19 11:23:32.633 | DEBUG | agentscope.models.response:to_dict:74 - Text before parsing 我需要使用"get_best_card"函数来找到品质最高的装备。 2024-04-19 11:23:32.634 | DEBUG | agentscope.models.response:to_dict:81 - Text after parsing

PARSE FUNCTION:

    @classmethod
    def to_dict(cls, response: ModelResponse) -> ModelResponse:
        """Parse the response text to a dict, and feed it into the `json`
        field."""
        text = response.text
        if text is not None:
            logger.debug(f"Text before parsing\n{text}")

            # extract from the first '{' to the last '}'
            index_start = max(text.find("{"), 0)
            index_end = min(text.rfind("}") + 1, len(text))

            text = text[index_start:index_end]
            logger.debug("Text after parsing", text)

            response.text = text
            response.json = json.loads(text)
            return response
        else:
            raise ValueError(
                f"The text field of the model response is None: {response}",
            )

ERROR INFO:

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

INPUT RESPONSE:

{ "text": "", "embedding": null, "image_urls": null, "json": null, "raw": { "id": "chatcmpl-9FZ8WHTmdbTiMHy4zkIVmACNMqeLZ", "choices": [ { "finish_reason": "stop", "index": 0, "logprobs": null, "message": { "content": "我需要使用"get_best_card"函数来找到品质最高的装备。", "role": "assistant", "function_call": null, "tool_calls": null }, "content_filter_results": { "hate": { "filtered": false, "severity": "safe" }, "self_harm": { "filtered": false, "severity": "safe" }, "sexual": { "filtered": false, "severity": "safe" }, "violence": { "filtered": false, "severity": "safe" } } } ], "created": 1713497012, "model": "gpt-35-turbo", "object": "chat.completion", "system_fingerprint": "fp_2f57f81c11", "usage": { "completion_tokens": 21, "prompt_tokens": 569, "total_tokens": 590 }, "prompt_filter_results": [ { "prompt_index": 0, "content_filter_results": { "hate": { "filtered": false, "severity": "safe" }, "self_harm": { "filtered": false, "severity": "safe" }, "sexual": { "filtered": false, "severity": "safe" }, "violence": { "filtered": false, "severity": "safe" } } } ] } } assistant: system: Your response is not a JSON object, and cannot be parsed by json.loads in parse function:

Your Response:

[YOUR RESPONSE BEGIN]

[YOUR RESPONSE END]

Error Information:

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Analyze the reason, and re-correct your response in the correct format. ##################### ITER 2, STEP 1: REASONING ###################### 2024-04-19 11:23:35.452 | DEBUG | agentscope.models.response:to_dict:74 - Text before parsing { "thought": "I need to use the 'get_best_card' function to find the best equipment.", "speak": "我将使用'get_best_card'函数来寻找最好的装备。", "function": [{"name": "get_best_card", "arguments": {"type": "装备", "level": true}}] } 2024-04-19 11:23:35.452 | DEBUG | agentscope.models.response:to_dict:81 - Text after parsing assistant: { "thought": "I need to use the 'get_best_card' function to find the best equipment.", "speak": "\u6211\u5c06\u4f7f\u7528'get_best_card'\u51fd\u6570\u6765\u5bfb\u627e\u6700\u597d\u7684\u88c5\u5907\u3002", "function": [ { "name": "get_best_card", "arguments": { "type": "\u88c5\u5907", "level": true } } ] } ####################### ITER 2, STEP 2: ACTION #######################

Executing function get_best_card ... END system: 根据 Execution Results 回答user最初的问题:

  1. get_best_card: [EXECUTE STATUS]: SUCCESS [EXECUTE RESULT]: ['力量系头盔金3', '力量系衣服金3', '力量系鞋子金3', '力量系武器金3', '敏捷系头盔金3', '敏捷系衣服金3', '敏捷系鞋子金3', '敏捷系武器金3', '智力系头盔金3', '智力系衣服金3', '智力系鞋子金3', '智力系武器金3']

##################### ITER 3, STEP 1: REASONING ###################### 2024-04-19 11:23:37.219 | DEBUG | agentscope.models.response:to_dict:74 - Text before parsing {"thought": "The best equipment has been successfully retrieved.", "speak": "已成功找到品质最高的装备。", "function": []} 2024-04-19 11:23:37.219 | DEBUG | agentscope.models.response:to_dict:81 - Text after parsing assistant: { "thought": "The best equipment has been successfully retrieved.", "speak": "\u5df2\u6210\u529f\u627e\u5230\u54c1\u8d28\u6700\u9ad8\u7684\u88c5\u5907\u3002", "function": [] }

ForgetThatNight avatar Apr 19 '24 03:04 ForgetThatNight

Hi!你好

  1. 看log应该已经是根据执行结果进行回答,但是没有回答更详细的内容,这个需要调整prompt进行调试,引导大模型把执行结果详细的表达出来。 image
  2. 关于打印出中文的转义码的问题,我这尝试复现了下,没有发现这个问题,可以尝试拉取最新的代码

DavdGao avatar Apr 25 '24 13:04 DavdGao

If you have any further questions or concerns, please feel free to create a new issue. Closing this for now.

DavdGao avatar May 07 '24 08:05 DavdGao