agentscope-ai / agentscope-ai/agentscope

Session replay fails with 400 when empty assistant turn saved on crash

未关闭
#1,426 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
stale-issue
主要语言
Python
星标
31.5k
派生
3.5k
平均合并
1 天 23 小时
30 天内合并 PR
95

描述

Summary:
When the agent process crashes mid-response (e.g. during MCP SSE teardown), AgentScope saves an empty assistant message to the session JSON. On next load, the full session history including the empty turn is replayed to the LLM API, which returns 400 - messages[N] assistant must provide content or tool_calls.

Steps to reproduce:

1. Run a ReActAgent with MCP tools via SSE transport
2. Agent crashes during SSE teardown (known anyio cancel scope issue on Python 3.10/3.11)
3. Session is saved with empty assistant content at the last turn
4. On next invocation, session loads and replays to API
5. API returns 400

Expected: Session loader should validate messages and skip/remove empty assistant turns before replaying

Actual: Session replays as-is, causing hard crash on every subsequent invocation until session is manually deleted

Environment:

• AgentScope version: 1.0.18
• Python: 3.11.15
• Model: Anthropic-compatible API (Xiaomi MiMo endpoint)
• OS: Linux (Docker container)

Workaround: Manually delete session.json

## Full Stack Trace

Full stack trace:

Error when executing Friday
2026-04-06 09:59:00,754 | INFO | _json_session:load_session_state:115 - Load session state from /app/data/.local/share/AgentScope-Studio/Friday/session.json successfully.
Traceback (most recent call last):
File "/app/dist/app/friday/main.py", line 169, in
asyncio.run(main())
File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/app/dist/app/friday/main.py", line 159, in main
await agent(Msg("user", json5.loads(args.query), "user"))
File "/usr/local/lib/python3.11/site-packages/agentscope/agent/_agent_base.py", line 455, in __call__
reply_msg = await self.reply(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/agentscope/agent/_agent_meta.py", line 120, in async_wrapper
current_output = await original_func(
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/agentscope/tracing/_trace.py", line 390, in wrapper
return await func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/agentscope/agent/_react_agent.py", line 437, in reply
msg_reasoning = await self._reasoning(tool_choice)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/agentscope/agent/_agent_meta.py", line 120, in async_wrapper
current_output = await original_func(
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/agentscope/agent/_react_agent.py", line 568, in _reasoning
res = await self.model(
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/agentscope/tracing/_trace.py", line 602, in async_wrapper
return await func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/agentscope/model/_anthropic_model.py", line 257, in __call__
response = await self.client.messages.create(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/anthropic/resources/messages/messages.py", line 2443, in create
return await self._post(
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1998, in post
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1783, in request
raise self._make_status_error_from_response(err.response) from None
anthropic.BadRequestError: Error code: 400 - {'error': {'code': '400', 'message': 'Param Incorrect', 'param': 'messages[292] assistant must provide content or tool_calls', 'type': ''}}
Unclosed client session
client_session:
Exception ignored in:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 454, in __del__
File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 224, in release
File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 835, in _release
File "/usr/local/lib/python3.11/site-packages/aiohttp/client_proto.py", line 93, in close
File "/usr/local/lib/python3.11/asyncio/selector_even

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。