Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Fix: Work around count_token bug in litellm

Kilian Lieret0c27f286303a
diff --git a/sweagent/agent/models.py b/sweagent/agent/models.py
index 2c98681c..ea159fb7 100644
--- a/sweagent/agent/models.py
+++ b/sweagent/agent/models.py
@@ -652,7 +652,12 @@ class LiteLLMModel(AbstractModel):
self, messages: list[dict[str, str]], n: int | None = None, temperature: float | None = None
) -> list[dict]:
self._sleep()
- input_tokens: int = litellm.utils.token_counter(messages=messages, model=self.config.name)
+ # Workaround for litellm bug https://github.com/SWE-agent/SWE-agent/issues/1109
+ messages_no_cache_control = copy.deepcopy(messages)
+ for message in messages_no_cache_control:
+ if "cache_control" in message:
+ del message["cache_control"]
+ input_tokens: int = litellm.utils.token_counter(messages=messages_no_cache_control, model=self.config.name)
if self.model_max_input_tokens is None:
msg = (
f"No max input tokens found for model {self.config.name!r}. "