geekan / MetaGPT

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
https://deepwisdom.ai/
MIT License
44.01k stars 5.24k forks source link

The following error appears on every run #1115

Open yxl23 opened 6 months ago

yxl23 commented 6 months ago

image

2024-03-27 11:15:59.019 | ERROR | metagpt.utils.common:wrapper:631 - Exception occurs, start to serialize the project, exp: Traceback (most recent call last): File "D:\andconda\envs\metagpt\lib\site-packages\tenacity__init.py", line 382, in call__ result = fn(*args, **kwargs) File "d:\下载\metagpt-main\metagpt\utils\repair_llm_raw_output.py", line 296, in retry_parse_json_text parsed_data = CustomDecoder(strict=False).decode(output) json.decoder.JSONDecodeError: Unterminated string starting at: line 13 column 25 (char 3485)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "D:\andconda\envs\metagpt\lib\site-packages\tenacity_asyncio.py", line 50, in call result = await fn(*args, **kwargs) File "d:\下载\metagpt-main\metagpt\actions\action_node.py", line 425, in _aask_v1 parsed_data = llm_output_postprocess( tenacity.RetryError: RetryError[<Future at 0x1f1a7f31d30 state=finished raised JSONDecodeError>]

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "d:\下载\metagpt-main\metagpt\utils\common.py", line 640, in wrapper return await func(self, *args, **kwargs) File "d:\下载\metagpt-main\metagpt\roles\role.py", line 550, in run rsp = await self.react() tenacity.RetryError: RetryError[<Future at 0x1f1a7f31160 state=finished raised RetryError>]

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "d:\下载\metagpt-main\metagpt\utils\common.py", line 626, in wrapper result = await func(self, *args, *kwargs) File "d:\下载\metagpt-main\metagpt\team.py", line 134, in run await self.env.run() Exception: Traceback (most recent call last): File "D:\andconda\envs\metagpt\lib\site-packages\tenacity__init.py", line 382, in call__ result = fn(args, **kwargs) File "d:\下载\metagpt-main\metagpt\utils\repair_llm_raw_output.py", line 296, in retry_parse_json_text parsed_data = CustomDecoder(strict=False).decode(output) File "d:\下载\metagpt-main\metagpt\utils\custom_decoder.py", line 297, in decode return super().decode(s) File "D:\andconda\envs\metagpt\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "D:\andconda\envs\metagpt\lib\json\decoder.py", line 353, in raw_decode obj, end = self.scan_once(s, idx) File "d:\下载\metagpt-main\metagpt\utils\custom_decoder.py", line 65, in scan_once return _scan_once(string, idx) File "d:\下载\metagpt-main\metagpt\utils\custom_decoder.py", line 36, in _scan_once return parse_object((string, idx + 1), strict, _scan_once, object_hook, object_pairs_hook, memo) File "d:\下载\metagpt-main\metagpt\utils\custom_decoder.py", line 164, in JSONObject value, end = scan_once(s, end) File "d:\下载\metagpt-main\metagpt\utils\custom_decoder.py", line 34, in _scan_once return parse_string(string, idx + 1, strict, delimiter=nextchar) File "d:\下载\metagpt-main\metagpt\utils\custom_decoder.py", line 227, in py_scanstring raise JSONDecodeError("Unterminated string starting at", s, begin) json.decoder.JSONDecodeError: Unterminated string starting at: line 13 column 25 (char 3485)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "D:\andconda\envs\metagpt\lib\site-packages\tenacity_asyncio.py", line 50, in call result = await fn(*args, *kwargs) File "d:\下载\metagpt-main\metagpt\actions\action_node.py", line 425, in _aask_v1 parsed_data = llm_output_postprocess( File "d:\下载\metagpt-main\metagpt\provider\postprocess\llm_output_postprocess.py", line 19, in llm_output_postprocess result = postprocess_plugin.run(output=output, schema=schema, req_key=req_key) File "d:\下载\metagpt-main\metagpt\provider\postprocess\base_postprocess_plugin.py", line 68, in run new_output = self.run_repair_llm_output(output=output, schema=schema, req_key=req_key) File "d:\下载\metagpt-main\metagpt\provider\postprocess\base_postprocess_plugin.py", line 32, in run_repair_llm_output parsed_data = self.run_retry_parse_json_text(content) File "d:\下载\metagpt-main\metagpt\provider\postprocess\base_postprocess_plugin.py", line 47, in run_retry_parse_json_text parsed_data = retry_parse_json_text(output=content) # should use output=content File "D:\andconda\envs\metagpt\lib\site-packages\tenacity__init__.py", line 289, in wrapped_f return self(f, args, **kw) File "D:\andconda\envs\metagpt\lib\site-packages\tenacity__init.py", line 379, in call do = self.iter(retry_state=retry_state) File "D:\andconda\envs\metagpt\lib\site-packages\tenacity\init__.py", line 326, in iter raise retry_exc from fut.exception() tenacity.RetryError: RetryError[<Future at 0x1f1a7f31d30 state=finished raised JSONDecodeError>]

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "d:\下载\metagpt-main\metagpt\utils\common.py", line 640, in wrapper return await func(self, *args, *kwargs) File "d:\下载\metagpt-main\metagpt\roles\role.py", line 550, in run rsp = await self.react() File "d:\下载\metagpt-main\metagpt\roles\role.py", line 517, in react rsp = await self._react() File "d:\下载\metagpt-main\metagpt\roles\role.py", line 463, in _react rsp = await self._act() File "d:\下载\metagpt-main\metagpt\roles\role.py", line 392, in _act response = await self.rc.todo.run(self.rc.history) File "d:\下载\metagpt-main\metagpt\actions\design_api.py", line 58, in run doc = await self._update_system_design(filename=filename) File "d:\下载\metagpt-main\metagpt\actions\design_api.py", line 86, in _update_system_design system_design = await self._new_system_design(context=prd.content) File "d:\下载\metagpt-main\metagpt\actions\design_api.py", line 73, in _new_system_design node = await DESIGN_API_NODE.fill(context=context, llm=self.llm) File "d:\下载\metagpt-main\metagpt\actions\action_node.py", line 505, in fill return await self.simple_fill(schema=schema, mode=mode, images=images, timeout=timeout, exclude=exclude) File "d:\下载\metagpt-main\metagpt\actions\action_node.py", line 457, in simple_fill content, scontent = await self._aask_v1( File "D:\andconda\envs\metagpt\lib\site-packages\tenacity_asyncio.py", line 88, in async_wrapped return await fn(args, **kwargs) File "D:\andconda\envs\metagpt\lib\site-packages\tenacity_asyncio.py", line 47, in call do = self.iter(retry_state=retry_state) File "D:\andconda\envs\metagpt\lib\site-packages\tenacity__init__.py", line 326, in iter raise retry_exc from fut.exception() tenacity.RetryError: RetryError[<Future at 0x1f1a7f31160 state=finished raised RetryError>]

iorisa commented 6 months ago
截屏2024-03-27 12 55 51

This issue is caused by the invalid response from LLM. MetaGPT had tried to repair the invalid response but failed. What is the LLM?

yxl23 commented 6 months ago

I use zero and one thousand things

geekan commented 6 months ago

I thought maybe we could evaluate whether each LLM has the ability to run the data interpreter and metagpt.

But so far, I still recommend using gpt-4-turbo-preview for the main process of metagpt.

zchem commented 6 months ago

I'm getting a similar error,

2024-03-27 12:45:05.084 | WARNING  | metagpt.provider.openai_api:_calc_usage:244 - usage calculation failed: num_tokens_from_messages() is not implemented for model mixtral. See https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken for information on how messages are converted to tokens.
2024-03-27 12:45:05.088 | WARNING  | metagpt.utils.repair_llm_raw_output:extract_content_from_output:320 - extract_content try another pattern: \[CONTENT\]([\s\S]*)\[/CONTENT\]
2024-03-27 12:45:05.088 | WARNING  | metagpt.utils.repair_llm_raw_output:run_and_passon:268 - parse json from content inside [CONTENT][/CONTENT] failed at retry 1, exp: Invalid \escape: '_': line 5 column 30 (char 457)
2024-03-27 12:45:05.088 | INFO     | metagpt.utils.repair_llm_raw_output:repair_invalid_json:237 - repair_invalid_json, raw error: Invalid \escape: '_': line 5 column 30 (char 457)
2024-03-27 12:45:05.089 | ERROR    | metagpt.utils.common:log_it:554 - Finished call to 'metagpt.actions.action_node.ActionNode._aask_v1' after 139.066(s), this was the 1st time calling it. exp: RetryError[<Future at 0x7f9fc4a14310 state=finished raised JSONDecodeError>]

I'm running mixtral with ollama.

$ cat ~/.metagpt/config2.yaml
# Full Example: https://github.com/geekan/MetaGPT/blob/main/config/config2.example.yaml
# Reflected Code: https://github.com/geekan/MetaGPT/blob/main/metagpt/config2.py
llm:
  api_type: "openai"  # or azure / ollama / open_llm etc. Check LLMType for more options
    #model: "gpt-4-turbo-preview"  # or gpt-3.5-turbo-1106 / gpt-4-1106-preview
  model: "mixtral"
    #base_url: "https://api.openai.com/v1"  # or forward url / other llm url
  base_url: "http://localhost:11434/v1"
  api_key: "mytestkey"
  pricing_plan: ""
JustWeZero commented 5 months ago

I got a similar error when I using DataInterpreter. Here is how I solve ther problem. My LLM is zhipuai, chatglm4.Here is my code:

import asyncio
import re

from metagpt.logs import logger
from metagpt.roles.di.data_interpreter import DataInterpreter
from metagpt.utils.recovery_util import save_history

async def main(requirement: str = ""):
    di = DataInterpreter()
    rsp = await di.run(requirement)
    logger.info(rsp)
    save_history(role=di)

if __name__ == "__main__":
    requirement = "告诉我中国下次吃月饼是在多少天之后"
    asyncio.run(main(requirement))

and running log:

2024-04-29 09:57:27.580 | INFO     | metagpt.const:get_metagpt_package_root:29 - Package root set to E:\Python_Project\MetaGPT
[
    {
        "task_id": "1",
        "dependent_task_ids": [],
        "instruction": "Determine the date of the next Mid-Autumn Festival, which is when Chinese traditionally eat mooncakes.",
        "task_type": "other"
    },
    {
        "task_id": "2",
        "dependent_task_ids": ["1"],
        "instruction": "Calculate the number of days from today to the date of the next Mid-Autumn Festival.",
        "task_type": "other"
    }
] 

The Mid-Autumn Festival, also known as the Moon Festival, is based on the lunar calendar, so the date changes every year. To answer your question, we need to find out the date of the next Mid-Autumn Festival and then calculate the number of days from today to that date. Tasks 1 and 2 outline this process.
2024-04-29 09:57:44.887 | INFO     | metagpt.utils.cost_manager:update_cost:57 - Total running cost: $0.008 | Max budget: $10.000 | Current cost: $0.008, prompt_tokens: 395, completion_tokens: 183
2024-04-29 09:57:44.888 | ERROR    | metagpt.utils.common:parse_code:282 - ```.*?\s+(.*?)``` not match following text:
2024-04-29 09:57:44.889 | ERROR    | metagpt.utils.common:parse_code:283 - [
    {
        "task_id": "1",
        "dependent_task_ids": [],
        "instruction": "Determine the date of the next Mid-Autumn Festival, which is when Chinese traditionally eat mooncakes.",
        "task_type": "other"
    },
    {
        "task_id": "2",
        "dependent_task_ids": ["1"],
        "instruction": "Calculate the number of days from today to the date of the next Mid-Autumn Festival.",
        "task_type": "other"
    }
] 

The Mid-Autumn Festival, also known as the Moon Festival, is based on the lunar calendar, so the date changes every year. To answer your question, we need to find out the date of the next Mid-Autumn Festival and then calculate the number of days from today to that date. Tasks 1 and 2 outline this process.
2024-04-29 09:57:44.889 | WARNING  | metagpt.strategy.planner:update_plan:82 - The generated plan is not valid with error: Extra data: line 16 column 1 (char 448), try regenerating, remember to generate either the whole plan or the single changed task only
[
    {
        "task_id": "1",
        "dependent_task_ids": [],
        "instruction": "Determine the date of the next Mid-Autumn Festival, which is celebrated on the 15th day of the eighth lunar month.",
        "task_type": "other"
    },
    {
        "task_id": "2",
        "dependent_task_ids": ["1"],
        "instruction": "Calculate the number of days from today to the date of the next Mid-Autumn Festival.",
        "task_type": "other"
    }
]

The plan involves two tasks. The first task is to find out the date of the next Mid-Autumn Festival, which is based on the lunar calendar and celebrated on the 15th day of the eighth lunar month. Once we have that date, the second task is to calculate the number of days from today to that date.
2024-04-29 09:57:52.609 | INFO     | metagpt.utils.cost_manager:update_cost:57 - Total running cost: $0.011 | Max budget: $10.000 | Current cost: $0.011, prompt_tokens: 622, completion_tokens: 184
2024-04-29 09:57:52.609 | ERROR    | metagpt.utils.common:parse_code:282 - ```.*?\s+(.*?)``` not match following text:
2024-04-29 09:57:52.611 | ERROR    | metagpt.utils.common:parse_code:283 - [
    {
        "task_id": "1",
        "dependent_task_ids": [],
        "instruction": "Determine the date of the next Mid-Autumn Festival, which is celebrated on the 15th day of the eighth lunar month.",
        "task_type": "other"
    },
    {
        "task_id": "2",
        "dependent_task_ids": ["1"],
        "instruction": "Calculate the number of days from today to the date of the next Mid-Autumn Festival.",
        "task_type": "other"
    }
]

The plan involves two tasks. The first task is to find out the date of the next Mid-Autumn Festival, which is based on the lunar calendar and celebrated on the 15th day of the eighth lunar month. Once we have that date, the second task is to calculate the number of days from today to that date.
2024-04-29 09:57:52.611 | WARNING  | metagpt.strategy.planner:update_plan:82 - The generated plan is not valid with error: Extra data: line 16 column 1 (char 459), try regenerating, remember to generate either the whole plan or the single changed task only
[
    {
        "task_id": "1",
        "dependent_task_ids": [],
        "instruction": "Determine the date of the next Mid-Autumn Festival, which is celebrated on the 15th day of the eighth lunar month.",
        "task_type": "other"
    },
    {
        "task_id": "2",
        "dependent_task_ids": ["1"],
        "instruction": "Calculate the number of days from the current date to the date of the next Mid-Autumn Festival.",
        "task_type": "other"
    }
]

The plan involves two tasks. The first task is to find out the date of the next Mid-Autumn Festival, which is based on the lunar calendar and celebrated on the 15th day of the eighth lunar month. The second task is to calculate the number of days from the current date to the date of the next Mid-Autumn Festival. Since these tasks are not in the defined categories such as eda, data preprocessing, etc., the task_type is set to "other".
2024-04-29 09:58:02.217 | INFO     | metagpt.utils.cost_manager:update_cost:57 - Total running cost: $0.015 | Max budget: $10.000 | Current cost: $0.015, prompt_tokens: 850, completion_tokens: 218
2024-04-29 09:58:02.218 | ERROR    | metagpt.utils.common:parse_code:282 - ```.*?\s+(.*?)``` not match following text:
2024-04-29 09:58:02.218 | ERROR    | metagpt.utils.common:parse_code:283 - [
    {
        "task_id": "1",
        "dependent_task_ids": [],
        "instruction": "Determine the date of the next Mid-Autumn Festival, which is celebrated on the 15th day of the eighth lunar month.",
        "task_type": "other"
    },
    {
        "task_id": "2",
        "dependent_task_ids": ["1"],
        "instruction": "Calculate the number of days from the current date to the date of the next Mid-Autumn Festival.",
        "task_type": "other"
    }
]

The plan involves two tasks. The first task is to find out the date of the next Mid-Autumn Festival, which is based on the lunar calendar and celebrated on the 15th day of the eighth lunar month. The second task is to calculate the number of days from the current date to the date of the next Mid-Autumn Festival. Since these tasks are not in the defined categories such as eda, data preprocessing, etc., the task_type is set to "other".
2024-04-29 09:58:02.218 | WARNING  | metagpt.strategy.planner:update_plan:82 - The generated plan is not valid with error: Extra data: line 16 column 1 (char 470), try regenerating, remember to generate either the whole plan or the single changed task only
[
    {
        "task_id": "1",
        "dependent_task_ids": [],
        "instruction": "Determine the date of the next Mid-Autumn Festival, which is celebrated on the 15th day of the eighth lunar month.",
        "task_type": "other"
    },
    {
        "task_id": "2",
        "dependent_task_ids": ["1"],
        "instruction": "Calculate the number of days from the current date to the date of the next Mid-Autumn Festival.",
        "task_type": "other"
    }
]

The plan involves two tasks. The first task is to find out the date of the next Mid-Autumn Festival, which is based on the lunar calendar and celebrated on the 15th day of the eighth lunar month. The second task is to calculate the number of days from the current date to the date of the next Mid-Autumn Festival. Both tasks fall under the "other" category as they do not fit into the defined task types such as eda, data preprocessing, etc.
2024-04-29 09:58:11.474 | INFO     | metagpt.utils.cost_manager:update_cost:57 - Total running cost: $0.019 | Max budget: $10.000 | Current cost: $0.019, prompt_tokens: 1112, completion_tokens: 219
2024-04-29 09:58:11.474 | ERROR    | metagpt.utils.common:parse_code:282 - ```.*?\s+(.*?)``` not match following text:
2024-04-29 09:58:11.474 | ERROR    | metagpt.utils.common:parse_code:283 - [
    {
        "task_id": "1",
        "dependent_task_ids": [],
        "instruction": "Determine the date of the next Mid-Autumn Festival, which is celebrated on the 15th day of the eighth lunar month.",
        "task_type": "other"
    },
    {
        "task_id": "2",
        "dependent_task_ids": ["1"],
        "instruction": "Calculate the number of days from the current date to the date of the next Mid-Autumn Festival.",
        "task_type": "other"
    }
]

The plan involves two tasks. The first task is to find out the date of the next Mid-Autumn Festival, which is based on the lunar calendar and celebrated on the 15th day of the eighth lunar month. The second task is to calculate the number of days from the current date to the date of the next Mid-Autumn Festival. Both tasks fall under the "other" category as they do not fit into the defined task types such as eda, data preprocessing, etc.
2024-04-29 09:58:11.475 | WARNING  | metagpt.utils.common:wrapper:649 - There is a exception in role's execution, in order to resume, we delete the newest role communication message in the role's memory.
Traceback (most recent call last):
  File "E:\Python_Project\MetaGPT\metagpt\utils\common.py", line 640, in wrapper
    return await func(self, *args, **kwargs)
  File "E:\Python_Project\MetaGPT\metagpt\roles\role.py", line 555, in run
    rsp = await self.react()
  File "E:\Python_Project\MetaGPT\metagpt\roles\role.py", line 526, in react
    rsp = await self._plan_and_act()
  File "E:\Python_Project\MetaGPT\metagpt\roles\di\data_interpreter.py", line 95, in _plan_and_act
    raise e
  File "E:\Python_Project\MetaGPT\metagpt\roles\di\data_interpreter.py", line 90, in _plan_and_act
    rsp = await super()._plan_and_act()
  File "E:\Python_Project\MetaGPT\metagpt\roles\role.py", line 486, in _plan_and_act
    await self.planner.update_plan(goal=goal)
  File "E:\Python_Project\MetaGPT\metagpt\strategy\planner.py", line 89, in update_plan
    update_plan_from_rsp(rsp=rsp, current_plan=self.plan)
  File "E:\Python_Project\MetaGPT\metagpt\actions\di\write_plan.py", line 55, in update_plan_from_rsp
    rsp = json.loads(rsp)
  File "E:\Anaconda3\envs\metagpt\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "E:\Anaconda3\envs\metagpt\lib\json\decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 16 column 1 (char 470)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\Python_Project\MetaGPT\my_test\my_test_di.py", line 18, in <module>
    asyncio.run(main(requirement))
  File "E:\Anaconda3\envs\metagpt\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "E:\Anaconda3\envs\metagpt\lib\asyncio\base_events.py", line 647, in run_until_complete
    return future.result()
  File "E:\Python_Project\MetaGPT\my_test\my_test_di.py", line 11, in main
    rsp = await di.run(requirement)
  File "E:\Python_Project\MetaGPT\metagpt\utils\common.py", line 662, in wrapper
    raise Exception(format_trackback_info(limit=None))
Exception: Traceback (most recent call last):
  File "E:\Python_Project\MetaGPT\metagpt\utils\common.py", line 640, in wrapper
    return await func(self, *args, **kwargs)
  File "E:\Python_Project\MetaGPT\metagpt\roles\role.py", line 555, in run
    rsp = await self.react()
  File "E:\Python_Project\MetaGPT\metagpt\roles\role.py", line 526, in react
    rsp = await self._plan_and_act()
  File "E:\Python_Project\MetaGPT\metagpt\roles\di\data_interpreter.py", line 95, in _plan_and_act
    raise e
  File "E:\Python_Project\MetaGPT\metagpt\roles\di\data_interpreter.py", line 90, in _plan_and_act
    rsp = await super()._plan_and_act()
  File "E:\Python_Project\MetaGPT\metagpt\roles\role.py", line 486, in _plan_and_act
    await self.planner.update_plan(goal=goal)
  File "E:\Python_Project\MetaGPT\metagpt\strategy\planner.py", line 89, in update_plan
    update_plan_from_rsp(rsp=rsp, current_plan=self.plan)
  File "E:\Python_Project\MetaGPT\metagpt\actions\di\write_plan.py", line 55, in update_plan_from_rsp
    rsp = json.loads(rsp)
  File "E:\Anaconda3\envs\metagpt\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "E:\Anaconda3\envs\metagpt\lib\json\decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 16 column 1 (char 470)

I debugged codes and I found variable rsp is:

[
    {
        "task_id": "1",
        "dependent_task_ids": [],
        "instruction": "Determine the date of the Mid-Autumn Festival in the current year",
        "task_type": "other"
    },
    {
        "task_id": "2",
        "dependent_task_ids": ["1"],
        "instruction": "Calculate the number of days until the Mid-Autumn Festival",
        "task_type": "other"
    }
]

The plan above is valid and outlines the necessary steps to achieve the goal. Task 1 involves determining the date of the Mid-Autumn Festival for the current year, which is categorized as 'other' since it involves date calculations. Task 2 depends on the completion of Task 1 and involves calculating the number of days until the determined date of the Mid-Autumn Festival, also categorized as 'other'.

so I decide to get only json substring from plan. I append 1 line in metagpt/strategy/planner.py, line 75:

        while not plan_confirmed:
            context = self.get_useful_memories()
            rsp = await WritePlan().run(context, max_tasks=max_tasks)
            # 截取计划中的json部分
            rsp = rsp[rsp.index("["): rsp.rfind("]") + 1]

and everything works fine for me.

But it may be not a very good solution. Can someone give a more general and elegant solution?

geekan commented 4 months ago

Using ActionNode may be better. @garylin2099

RaulButuc commented 2 months ago

Getting the same error on every run with the latest model gpt-4o-2024-05-13.