address greptile review feedback (greploop iteration 1)

- Restore backward compat for leading assistant(tool_calls) — always prepend user_continue
- Replace partial assertions with full list assertion in trailing tool-call test

Made-with: Cursor
This commit is contained in:
Sameer Kankute 2026-03-18 16:41:26 +05:30
parent 0941e40363
commit 67f5ce9c7c
2 changed files with 22 additions and 11 deletions

View file

@ -287,11 +287,9 @@ def _insert_user_continue_message(
result_messages = messages.copy() # Don't modify the input list
continue_message = user_continue_message or DEFAULT_USER_CONTINUE_MESSAGE
# Handle first counted message if it's an assistant message
if (
result_messages[0]["role"] == "assistant"
and _counts_for_alternation(result_messages[0])
):
# Handle first message if it's an assistant message — always prepend
# user_continue regardless of tool_calls, to preserve backward compatibility.
if result_messages[0]["role"] == "assistant":
result_messages.insert(0, continue_message)
# Handle consecutive assistant messages in the counted sequence

View file

@ -929,12 +929,25 @@ def test_ensure_alternating_roles_trailing_tool_call_assistant():
ensure_alternating_roles=True,
)
# Backward compat: trailing assistant (even with tool_calls) gets user_continue
# appended, then assistant_continue bridges the user→user gap.
assert transformed_messages[-1] == {"role": "user", "content": "Please continue."}
assert transformed_messages[0] == {"role": "user", "content": "What's the weather?"}
assert transformed_messages[1]["role"] == "assistant"
assert transformed_messages[1].get("tool_calls") is not None
assert transformed_messages == [
{"role": "user", "content": "What's the weather?"},
{
"role": "assistant",
"content": None,
"tool_calls": [
{
"id": "call_abc",
"type": "function",
"function": {
"name": "get_weather",
"arguments": '{"location": "NYC"}',
},
}
],
},
{"role": "assistant", "content": "Please continue."},
{"role": "user", "content": "Please continue."},
]
def test_alternating_roles_e2e():