Skip to content

[Bug] LLM压缩上下文进行压缩时报错。 #8484

@AkinaSioga

Description

@AkinaSioga

What happened / 发生了什么

原本使用的是v4.22.0版本,更新到最新版本v4.25.2。原本原配置能正常压缩上下文,更新后报错且无法压缩。
在配置文件>上下文管理策略里改为由LLM压缩上下文(使用的是DeepSeek-V4-Pro)进行压缩时报错:TypeError: Object of type TextPart is not JSON serializable

Reproduce / 如何复现?

更新至astrbot v4.25.2。使用由LLM压缩上下文

AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

V4.25.2,Linux Ubuntu Docker,提供商:AihubMix,QQ。

OS

Windows

Logs / 报错日志

[2026-06-01 14:30:41.187] [Core]
[ERRO]
[v4.25.2] [context.manager:79]: Error during context processing: Object of type TextPart is not JSON serializable
Traceback (most recent call last):
File "/AstrBot/astrbot/core/agent/context/manager.py", line 75, in process
result = await self._run_compression(result, total_tokens)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/AstrBot/astrbot/core/agent/context/manager.py", line 97, in _run_compression
messages = await self.compressor(messages)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/AstrBot/astrbot/core/agent/context/compressor.py", line 203, in call
old_text = rounds_to_text(old_rounds)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/AstrBot/astrbot/core/agent/context/round_utils.py", line 36, in rounds_to_text
content = json.dumps(content, ensure_ascii=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/json/init.py", line 238, in dumps
**kw).encode(obj)
^^^^^^^^^^^
File "/usr/local/lib/python3.12/json/encoder.py", line 200, in encode
chunks = self.iterencode(o, _one_shot=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/json/encoder.py", line 258, in iterencode
return _iterencode(o, 0)
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/json/encoder.py", line 180, in default
raise TypeError(f'Object of type {o.class.name} '
TypeError: Object of type TextPart is not JSON serializable

Are you willing to submit a PR? / 你愿意提交 PR 吗?

  • Yes!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions