From 5a65a6b7131967bb72e32d0d6de916b0d88d2c96 Mon Sep 17 00:00:00 2001 From: jtstothard Date: Tue, 28 Apr 2026 11:52:38 +0100 Subject: [PATCH] fix(copilot): handle deprecated function role and move integration test - Add 'function' to role check in determine_x_initiator() so legacy function-call format is treated as agent continuation (no premium charge) - Move test_github_copilot_billing.py from tests/llm_responses_api_testing/ to tests/integration/github_copilot/ (real API calls belong in integration, not alongside mock-only tests) - Add unit test for legacy function role --- litellm/llms/github_copilot/common_utils.py | 4 ++-- .../github_copilot}/test_github_copilot_billing.py | 0 .../llms/github_copilot/test_conversation_id.py | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) rename tests/{llm_responses_api_testing => integration/github_copilot}/test_github_copilot_billing.py (100%) diff --git a/litellm/llms/github_copilot/common_utils.py b/litellm/llms/github_copilot/common_utils.py index 11e86948621..2976d892ff7 100644 --- a/litellm/llms/github_copilot/common_utils.py +++ b/litellm/llms/github_copilot/common_utils.py @@ -188,8 +188,8 @@ def determine_x_initiator(messages_or_input: Union[list, str]) -> str: # No role = agent-initiated (Responses API role-less item types) if role is None: return "agent" - # assistant or tool role = agent continuation - if role in ("assistant", "tool"): + # assistant, tool, or legacy function role = agent continuation + if role in ("assistant", "tool", "function"): return "agent" return "user" diff --git a/tests/llm_responses_api_testing/test_github_copilot_billing.py b/tests/integration/github_copilot/test_github_copilot_billing.py similarity index 100% rename from tests/llm_responses_api_testing/test_github_copilot_billing.py rename to tests/integration/github_copilot/test_github_copilot_billing.py diff --git a/tests/test_litellm/llms/github_copilot/test_conversation_id.py b/tests/test_litellm/llms/github_copilot/test_conversation_id.py index aa94f9504f0..7f7f90ed016 100644 --- a/tests/test_litellm/llms/github_copilot/test_conversation_id.py +++ b/tests/test_litellm/llms/github_copilot/test_conversation_id.py @@ -129,5 +129,13 @@ class TestDetermineXInitiator: def test_string_input_returns_user(self): assert determine_x_initiator("What is 2+2?") == "user" + def test_legacy_function_role_returns_agent(self): + """Deprecated role:function must be treated as agent continuation.""" + messages = [ + {"role": "user", "content": "Call a function"}, + {"role": "function", "content": "result", "name": "my_fn"}, + ] + assert determine_x_initiator(messages) == "agent" + def test_empty_list_returns_user(self): assert determine_x_initiator([]) == "user"