Skip to content

fix(memory): skip empty assistant turns when loading session state#1436

Open
octo-patch wants to merge 1 commit intoagentscope-ai:mainfrom
octo-patch:fix/issue-1426-filter-empty-assistant-turns
Open

fix(memory): skip empty assistant turns when loading session state#1436
octo-patch wants to merge 1 commit intoagentscope-ai:mainfrom
octo-patch:fix/issue-1426-filter-empty-assistant-turns

Conversation

@octo-patch
Copy link
Copy Markdown
Contributor

Fixes #1426

Problem

When an agent crashes mid-response (e.g., during MCP SSE teardown), AgentScope saves an empty assistant message to the session JSON. On the 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

This causes a hard crash on every subsequent invocation until the session file is manually deleted.

Solution

In InMemoryMemory.load_state_dict, skip assistant messages whose content is falsy (empty string or empty list) when deserializing saved session state.

Testing

  • Verified empty-content assistant messages are silently skipped on load
  • Verified normal assistant messages still load correctly

When an agent crashes mid-response (e.g. during MCP SSE teardown),
an empty assistant message may be saved to the session JSON. On the
next load, replaying this empty turn to the LLM API causes a 400
error: 'assistant must provide content or tool_calls'.

Filter out assistant messages with no content during load_state_dict
so corrupt session state no longer causes hard failures on restart.

Fixes agentscope-ai#1426
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant