RD-Agent icon indicating copy to clipboard operation
RD-Agent copied to clipboard

[Bug Report] TypeError: data must be str, not dict during fin_quant coding step**

Open xiaosprq opened this issue 3 months ago • 8 comments

🐛 Bug Description

When running the rdagent fin_quant scenario, a TypeError: data must be str, not dict occurs intermittently. The error consistently happens at the 25% progress mark of the workflow, during the step_name=coding phase.

The root cause appears to be that the agent framework receives a structured dictionary (dict) from the LLM (GPT-4 Turbo) when its file-writing function expects a raw Python code string (str). This happens even with REASONING_THINK_RM=True enabled in the .env file.

To Reproduce

Steps to reproduce the behavior:

  1. Set up a clean server with Ubuntu 22.04 LTS.
  2. Clone the latest main branch of the RD-Agent repository.
  3. Create and activate a Conda environment with Python 3.10.
  4. Install dependencies: pip install pyqlib, clone the qlib repository and install from source (pip install -e .), and finally run make dev in the RD-Agent directory.
  5. Configure a .env file with a valid OpenAI API key, setting MODEL="gpt-4-turbo", IS_US_STOCK=True, and REASONING_THINK_RM=True.
  6. Prepare a custom Qlib data source using .bin files and configure ~/.qlib/qlib_config/qlib.yaml (and /root/.qlib/qlib_config/qlib.yaml) to point to it.
  7. Run the command: conda run -n rdagent rdagent fin_quant.
  8. Observe the potential TypeError at the 25% mark, which can be intermittent.

Expected Behavior

The agent should robustly parse the response from the LLM. It should be able to extract the Python code string, even if the response is a dictionary, and then save it to a file, allowing the workflow to proceed without raising a TypeError.

Screenshot

The error log from the terminal is as follows:

xiaosprq avatar Sep 04 '25 00:09 xiaosprq

same issue here

是不是很多个版本都有这个问题了?

k2o333 avatar Sep 07 '25 16:09 k2o333

same issue here by using GPT-5-Nano, hope to be fixed soon

markatally avatar Sep 12 '25 05:09 markatally

Same issue here when using GPT-4o.

TGtongga avatar Sep 26 '25 06:09 TGtongga

看得懂中文的人 我最后发觉问题出在没有用指定版本的qlib

当然,就算你用了 后面还是会有llm上下文窗口的问题,除非你全程用gemini模型

k2o333 avatar Sep 26 '25 06:09 k2o333

看得懂中文的人 我最后发觉问题出在没有用指定版本的qlib

当然,就算你用了 后面还是会有llm上下文窗口的问题,除非你全程用gemini模型

请问解决了吗,请教一下解决方法

lsm1041321457 avatar Sep 28 '25 04:09 lsm1041321457

看得懂中文的人 我最后发觉问题出在没有用指定版本的qlib 当然,就算你用了 后面还是会有llm上下文窗口的问题,除非你全程用gemini模型

请问解决了吗,请教一下解决方法

I've solved this problem by modifing the function of assign_code_list_to_evo under factor_coder's and model_coder's evolving_strategy.py

我是在factor_coder和model_coder各自的evolving_strategy.py里的assign_code_list_to_evo作了修改,解决了这个问题

Image

TGtongga avatar Sep 28 '25 05:09 TGtongga

看得懂中文的人 我最后发觉问题出在没有用指定版本的qlib 当然,就算你用了 后面还是会有llm上下文窗口的问题,除非你全程用gemini模型

请问解决了吗,请教一下解决方法

I've solved this problem by modifing the function of assign_code_list_to_evo under factor_coder's and model_coder's evolving_strategy.py

我是在factor_coder和model_coder各自的evolving_strategy.py里的assign_code_list_to_evo作了修改,解决了这个问题

Image

谢谢 已修复

lsm1041321457 avatar Sep 28 '25 06:09 lsm1041321457

This issue is fixed in PR 1279, you can install the latest version (0.8.0) of RD-Agent or pull the latest code and retry.

SunsetWolf avatar Nov 07 '25 07:11 SunsetWolf