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]
Summarizer: Recover from ContextWindowExceeded
Kilian Lieret94d9aaef1890
diff --git a/sweagent/agent/summarizer.py b/sweagent/agent/summarizer.pyindex a3bfec4e..5a46da30 100644--- a/sweagent/agent/summarizer.py+++ b/sweagent/agent/summarizer.py@@ -6,7 +6,7 @@ from abc import abstractmethodfrom dataclasses import dataclassfrom typing import Any-from sweagent.agent.models import APIStats, BaseModel+from sweagent.agent.models import APIStats, BaseModel, ContextWindowExceededErrorfrom sweagent.environment.swe_env import SWEEnvfrom sweagent.utils.log import get_logger@@ -124,6 +124,11 @@ class LMSummarizer(SummarizeFunction):SUMMARY:"""+ _warning_message_summarization_failed = """\+ Warning: Command output exceeded window size, saved command to a file {command_file_name}.+ If you still want to view the output of the command, use the following command `open {command_file_name}`.+ """+block_list_input = ["create","open",@@ -157,11 +162,14 @@ class LMSummarizer(SummarizeFunction):env.communicate("mkdir -p /output")env.communicate(f"printf {shlex.quote(observation)} > {command_file_name}")self.history.append({"role": "user", "content": self.instance_template.format(**self.instance_args, **self.system_args, command=input, observation=observation), "agent": self.name})- response = model.query(history=self.history)- stats = model.stats- model.reset_stats(APIStats())- self.history.pop()- return textwrap.dedent(self._warning_message.format(command_file_name=command_file_name)) + response, stats+ try:+ response = model.query(history=self.history)+ stats = model.stats+ model.reset_stats(APIStats())+ self.history.pop()+ return textwrap.dedent(self._warning_message.format(command_file_name=command_file_name)) + response, stats+ except ContextWindowExceededError:+ return textwrap.dedent(self._warning_message_summarization_failed.format(command_file_name=command_file_name)), APIStats()except Exception as e:self.logger.warning(f"Unhandled exception occured when trying to summarize observation for input {input}: {e}")return observation, APIStats()