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]
Enh: Defensive: allow missing message_type
Kilian Lieret6327b17c1fd3
diff --git a/sweagent/agent/history_processors.py b/sweagent/agent/history_processors.pyindex dba480ab..c22f57ea 100644--- a/sweagent/agent/history_processors.py+++ b/sweagent/agent/history_processors.py@@ -114,7 +114,7 @@ class LastNObservations(BaseModel):observation_indices = [idxfor idx, entry in enumerate(history)- if entry["message_type"] == "observation" and not entry.get("is_demo", False)+ if entry.get("message_type") == "observation" and not entry.get("is_demo", False)]last_removed_idx = max(0, (len(observation_indices) // self.polling) * self.polling - self.n)# Note: We never remove the first observation, as it is the instance template@@ -131,8 +131,8 @@ class LastNObservations(BaseModel):new_history.append(entry)else:data = entry.copy()- assert data["message_type"] == "observation", (- f"Expected observation for dropped entry, got: {data['message_type']}"+ assert data.get("message_type") == "observation", (+ f"Expected observation for dropped entry, got: {data.get('message_type')}")text = _get_content_text(data)_set_content_text(data, f"Old environment output: ({len(text.splitlines())} lines omitted)")@@ -161,12 +161,12 @@ class TagToolCallObservations(BaseModel):entry["tags"] = list(tags)def _should_add_tags(self, entry: HistoryItem) -> bool:- if entry["message_type"] != "action":+ if entry.get("message_type") != "action":return Falsefunction_calls = entry.get("tool_calls", [])if not function_calls:return False- function_names = {call["function"]["name"] for call in function_calls}+ function_names = {call["function"]["name"] for call in function_calls} # type: ignorereturn bool(self.function_names & function_names)def __call__(self, history: History) -> History: