Filter Snowflake Claude preserved tool results

This commit is contained in:
alex-clawd
2026-06-02 05:08:02 -07:00
parent 60f432eb0e
commit 13f5cd844b
2 changed files with 50 additions and 1 deletions

View File

@@ -190,7 +190,12 @@ class SnowflakeCompletion(OpenAICompletion):
if expected_ids.issubset(tool_result_ids):
sanitized.append(message)
sanitized.extend(messages[index + 1 : lookahead])
sanitized.extend(
tool_message
for tool_message in messages[index + 1 : lookahead]
if tool_message.get("role") == "tool"
and tool_message.get("tool_call_id") in expected_ids
)
index = lookahead

View File

@@ -218,6 +218,50 @@ class TestSnowflakeRequests:
}
assert messages[-1]["role"] == "user"
def test_claude_model_drops_unrelated_tool_results_from_preserved_pair(
self, monkeypatch: pytest.MonkeyPatch
):
_snowflake_env(monkeypatch)
llm = SnowflakeCompletion(model="claude-sonnet-4-5")
messages = llm._format_messages(
[
{"role": "user", "content": "Use the tool."},
{
"role": "assistant",
"content": None,
"tool_calls": [
{
"id": "call_1",
"type": "function",
"function": {"name": "lookup", "arguments": "{}"},
}
],
},
{
"role": "tool",
"tool_call_id": "call_1",
"content": "valid result",
},
{
"role": "tool",
"tool_call_id": "unrelated_call",
"content": "unrelated result",
},
]
)
assert messages[-3]["role"] == "assistant"
assert messages[-2] == {
"role": "tool",
"tool_call_id": "call_1",
"content": "valid result",
}
assert all(
message.get("tool_call_id") != "unrelated_call" for message in messages
)
assert messages[-1]["role"] == "user"
def test_claude_model_maps_max_tokens_to_max_completion_tokens(
self, monkeypatch: pytest.MonkeyPatch
):