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]
added simple summarization
Talor Abramovich98c67d832cd1
diff --git a/config/default_ctf.yaml b/config/default_ctf.yamlindex 619b8598..2dd57fe1 100644--- a/config/default_ctf.yaml+++ b/config/default_ctf.yaml@@ -86,7 +86,8 @@ state_command:fi};parse_function: ThoughtActionParser-summarizer_function: Identity+summarizer_function: SimpleSummarizer+summarizer_window_length: 105env_variables:WINDOW: 100OVERLAP: 2diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.pyindex 74970120..90bd74db 100644--- a/sweagent/agent/agents.py+++ b/sweagent/agent/agents.py@@ -63,6 +63,7 @@ class AgentConfig(FrozenSerializable):submit_command: str = "submit"parse_function: str = "ThoughtActionParser"summarizer_function: str = "SimpleSummarizer"+ summarizer_window_length: int = 105parse_command: str = "ParseCommandBash"history_processor: str = "DefaultHistoryProcessor"history_processor_args: dict[str, Any] = field(default_factory=dict)@@ -168,7 +169,7 @@ class AgentConfig(FrozenSerializable):"history_processor",HistoryProcessor.get(self.history_processor, **self.history_processor_args),)- object.__setattr__(self, "summarizer_function", SummarizeFunction.get(self.summarizer_function))+ object.__setattr__(self, "summarizer_function", SummarizeFunction.get(self.summarizer_function, self.summarizer_window_length))@dataclass(frozen=True)@@ -822,7 +823,7 @@ class Agent:for hook in self.hooks:hook.on_sub_action_started(sub_action=sub_action)obs, _, done, info = env.step(sub_action["action"])- obs = self.config.summarizer_function(obs, env)+ obs = self.config.summarizer_function(sub_action["action"], obs, env)for hook in self.hooks:hook.on_sub_action_executed(obs=obs, done=done)observations.append(obs)diff --git a/sweagent/agent/summarizer.py b/sweagent/agent/summarizer.pyindex 1ea963ff..4712a364 100644--- a/sweagent/agent/summarizer.py+++ b/sweagent/agent/summarizer.py@@ -1,10 +1,12 @@from __future__ import annotations+import shleximport textwrapfrom abc import abstractmethodfrom dataclasses import dataclassfrom sweagent.environment.swe_env import SWEEnv+from sweagent.utils.log import get_logger# ABSTRACT BASE CLASSES@@ -31,10 +33,12 @@ class SummarizeFunction(metaclass=SummarizeFunctionMeta):We use get to generate the right summarizer based on the name of the summarizer."""- _error_message = None+ def __init__(self, window_length: int):+ self._window_length = window_length+ self.logger = get_logger("summarizer")@abstractmethod- def __call__(self, observation, env: SWEEnv) -> str:+ def __call__(self, input: str, observation, env: SWEEnv) -> str:"""Abstract method for getting an observation and summarize it.The returned value should be a summation of the given observation.@@ -42,9 +46,9 @@ class SummarizeFunction(metaclass=SummarizeFunctionMeta):raise NotImplementedError@classmethod- def get(cls, name):+ def get(cls, name: str, window_length: int):try:- return cls._registry[name]()+ return cls._registry[name](window_length)except KeyError:msg = f"Model output summarizer ({name}) not found."raise ValueError(msg)@@ -58,8 +62,30 @@ class SimpleSummarizer(SummarizeFunction):Saves the output of the command to a file and uses the open command to show the output."""- def __call__(self, observation, env: SWEEnv):- return "0"+ block_list_input = [+ "create",+ "open",+ "edit",+ "scroll_up",+ "scroll_down",+ "goto",+ "search_file",+ "search_dir",+ ]++ def __call__(self, input: str, observation: str, env: SWEEnv) -> str:+ try:+ if any(input.startswith(s) for s in self.block_list_input) or len(observation.splitlines()) <= self._window_length:+ return observation+ self.logger.debug(f"Summarizing current observation for input {input}")+ command_file_name = "/output/" + input.replace(" ", "_").replace("/", "__")+ observation = f"COMMAND OUTPUT EXCEEDED WINDOW, SAVED COMMAND TO A FILE {command_file_name} AND OPENED THE FILE AT LINE 0.\n\n\n{observation}"+ env.communicate("mkdir -p /output")+ env.communicate(f"printf {shlex.quote(observation)} > {command_file_name}")+ return env.communicate(f"open {command_file_name}")+ except Exception as e:+ self.logger.warning(f"Unhandled exception occured when trying to summarize observation for input {input}: {e}")+ return observationclass Identity(SummarizeFunction):@@ -67,7 +93,7 @@ class Identity(SummarizeFunction):This summarizer does not do any summation. It returns the environment observation as is."""- def __call__(self, observation, env: SWEEnv):+ def __call__(self, input: str, observation: str, env: SWEEnv) -> str:"""This doesn't do any summarization. It just returns the environment observation."""