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]
identity summarizer
Talor Abramovich39c16ec99348
diff --git a/config/default_ctf.yaml b/config/default_ctf.yamlindex b77611ab..619b8598 100644--- a/config/default_ctf.yaml+++ b/config/default_ctf.yaml@@ -86,6 +86,7 @@ state_command:fi};parse_function: ThoughtActionParser+summarizer_function: Identityenv_variables:WINDOW: 100OVERLAP: 2diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.pyindex 6c6d3e37..74970120 100644--- a/sweagent/agent/agents.py+++ b/sweagent/agent/agents.py@@ -21,6 +21,7 @@ from sweagent.agent.models import (get_model,)from sweagent.agent.parsing import FormatError, ParseFunction+from sweagent.agent.summarizer import SummarizeFunctionfrom sweagent.environment.swe_env import SWEEnvfrom sweagent.utils.config import convert_paths_to_abspathfrom sweagent.utils.log import get_logger@@ -61,6 +62,7 @@ class AgentConfig(FrozenSerializable):util_functions: list[str] = field(default_factory=list)submit_command: str = "submit"parse_function: str = "ThoughtActionParser"+ summarizer_function: str = "SimpleSummarizer"parse_command: str = "ParseCommandBash"history_processor: str = "DefaultHistoryProcessor"history_processor_args: dict[str, Any] = field(default_factory=dict)@@ -166,6 +168,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))@dataclass(frozen=True)@@ -819,6 +822,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)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.pynew file mode 100644index 00000000..1ea963ff--- /dev/null+++ b/sweagent/agent/summarizer.py@@ -0,0 +1,75 @@+from __future__ import annotations++import textwrap+from abc import abstractmethod+from dataclasses import dataclass++from sweagent.environment.swe_env import SWEEnv+++# ABSTRACT BASE CLASSES+++class SummarizeFunctionMeta(type):+ """+ Registry maps all inherited classes to their names.+ """++ _registry = {}++ def __new__(cls, name, bases, attrs):+ new_cls = super().__new__(cls, name, bases, attrs)+ if name != "SummarizeFunction":+ cls._registry[name] = new_cls+ return new_cls+++@dataclass+class SummarizeFunction(metaclass=SummarizeFunctionMeta):+ """+ Abstract class for summarizing functions.+ We use get to generate the right summarizer based on the name of the summarizer.+ """++ _error_message = None++ @abstractmethod+ def __call__(self, observation, env: SWEEnv) -> str:+ """+ Abstract method for getting an observation and summarize it.+ The returned value should be a summation of the given observation.+ """+ raise NotImplementedError++ @classmethod+ def get(cls, name):+ try:+ return cls._registry[name]()+ except KeyError:+ msg = f"Model output summarizer ({name}) not found."+ raise ValueError(msg)+++# DEFINE NEW SUMMARIZE FUNCTIONS BELOW THIS LINE+++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"+++class Identity(SummarizeFunction):+ """+ This summarizer does not do any summation. It returns the environment observation as is.+ """++ def __call__(self, observation, env: SWEEnv):+ """+ This doesn't do any summarization. It just returns the environment observation.+ """+ return observation+