Hermes Agent
9220a876bc
fix: strip orphaned tool messages before sending history to API ( fixes #534 )
...
Extends _sanitize_messages_for_api() with a two-pass approach:
1. Collect all tool_call_ids declared in assistant messages (handles
both OpenAI 'id' and Anthropic 'call_id' field names).
2. Drop any tool-role messages whose tool_call_id was not declared
by a preceding assistant message.
Strictly-conformant providers (Mercury-2/Inception, newer OpenAI
models) reject histories with orphaned tool results with a 400 error:
'Message has tool role, but there was no previous assistant message
with a tool call.' This can happen when histories are edited, when
switching between providers, or when partial messages are stored.
Adds 13 regression tests covering: valid roundtrip preservation,
multiple tool calls, partial orphan filtering, Anthropic call_id,
edge cases (None tool_calls, missing tool_call_id, non-dict entries).
2026-04-15 16:57:31 +00:00
..
2026-03-30 20:40:19 -07:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-09 18:05:23 -07:00
2026-04-15 07:47:18 +00:00
2026-04-11 10:17:52 -07:00
2026-04-14 17:14:01 +00:00
2026-04-15 13:10:50 +08:00
2026-04-13 14:28:24 -07:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-13 00:08:30 -07:00
2026-04-14 21:13:33 +00:00
2026-04-13 11:40:15 -07:00
2026-04-13 12:36:11 -07:00
2026-04-13 22:41:31 -07:00
2026-04-14 22:14:31 +00:00
2026-04-14 21:14:00 +00:00
2026-04-14 21:14:33 +00:00
2026-04-14 21:52:34 +00:00
2026-04-14 22:09:36 +00:00
2026-04-14 17:13:03 +00:00
2026-04-13 22:57:58 -07:00
2026-04-14 17:14:01 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:35:52 +00:00
2026-04-14 17:13:03 +00:00
2026-04-14 19:06:35 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-12 00:11:41 -07:00
2026-04-13 22:57:58 -07:00
2026-04-15 16:57:31 +00:00
2026-04-13 00:51:55 -07:00
2026-04-13 22:11:45 -07:00
2026-04-15 08:04:03 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:10:23 +00:00
2026-04-14 19:04:48 +00:00
2026-04-11 20:06:37 -07:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-15 13:10:50 +08:00
2026-04-14 19:04:48 +00:00
2026-04-14 19:04:48 +00:00
2026-04-11 12:19:12 -07:00
2026-04-14 19:04:48 +00:00
2026-04-12 10:51:48 -07:00
2026-04-15 07:24:53 +00:00
2026-04-12 12:50:32 -07:00
2026-04-12 14:07:00 -07:00
2026-04-12 14:26:00 -07:00
2026-04-14 22:14:31 +00:00
2026-04-12 14:28:16 -07:00
2026-04-12 21:45:25 -07:00
2026-04-14 21:04:37 +00:00
2026-04-13 11:11:56 -07:00
2026-04-13 23:25:26 -07:00
2026-04-14 19:04:48 +00:00
2026-04-09 18:08:29 -07:00
2026-04-10 10:02:28 -07:00
2026-04-12 00:19:33 -07:00
2026-04-13 22:11:45 -07:00