Private
Public Access
0
0

fix(minimax): Prevent dangling tool calls during history truncation

- Update _trim_minimax_history to drop dangling 'tool' messages if their parent 'assistant' message is removed.
- Fixes 'invalid params, tool call result does not follow tool call (2013)' error when token limit is hit.
This commit is contained in:
2026-06-02 01:45:07 -04:00
parent 34a7f00cb3
commit 6e0d002d05
+7
View File
@@ -2131,6 +2131,13 @@ def _trim_minimax_history(system_blocks: list[dict[str, Any]], history: list[dic
removed = history.pop(1)
dropped += 1
est -= _estimate_message_tokens(removed)
# Ensure we don't leave dangling 'tool' messages if their parent 'assistant' was dropped.
# MiniMax strictly requires 'tool' messages to immediately follow 'assistant' with tool_calls.
while len(history) > 1 and history[1].get("role") == "tool":
removed_tool = history.pop(1)
dropped += 1
est -= _estimate_message_tokens(removed_tool)
return dropped
def _ensure_minimax_client() -> None: