Files
aiagent/backend
renjianbo bc06bc12db fix: trim_messages prevents orphaned tool messages after history truncation
When conversation history exceeds max_history, the blind slice in trim_messages
could cut between an assistant(tool_calls) message and its tool result messages.
DeepSeek/OpenAI requires every role:"tool" message to follow a preceding
assistant message with matching tool_calls.

The fix detects when the slice boundary lands on a tool message, then scans
backwards to include the parent assistant(tool_calls) message(s). If the parent
cannot be found (e.g. cut at a user boundary), the orphaned tool messages are
removed. This fixes the "Messages with role 'tool' must be a response to a
preceding message with 'tool_calls'" error from DeepSeek.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-07 23:59:42 +08:00
..
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-23 09:49:45 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00
2026-01-19 00:09:36 +08:00