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]

Ref: Renaming best response picker -> action sampler

Kilian Lieret2b3774f0de3f
diff --git a/sweagent/agent/best_response_picker.py b/sweagent/agent/action_sampler.py
similarity index 95%
rename from sweagent/agent/best_response_picker.py
rename to sweagent/agent/action_sampler.py
index e47d41ab..91f12ecc 100644
--- a/sweagent/agent/best_response_picker.py
+++ b/sweagent/agent/action_sampler.py
@@ -15,14 +15,14 @@ from sweagent.utils.log import get_logger
logger = get_logger(__name__)
-class GetActionOutput(BaseModel):
+class ActionSamplerOutput(BaseModel):
completion: dict[str, Any]
messages: list[dict[str, Any]] = []
trajectory_items: list[dict[str, Any]] = []
extra_info: dict[str, Any] = {}
-class AbstractBestActionPicker(BaseModel):
+class AbstractActionSampler(BaseModel):
def setup(self, model: AbstractModel, tools: ToolHandler):
self._model = model
self._tools = tools
@@ -34,12 +34,12 @@ class AbstractBestActionPicker(BaseModel):
trajectory: Trajectory,
history: list[dict[str, Any]],
completions: list[dict[str, Any]],
- ) -> GetActionOutput:
+ ) -> ActionSamplerOutput:
"""Returns action with tool calls"""
pass
-class AskColleagues(AbstractBestActionPicker):
+class AskColleagues(AbstractActionSampler):
type: Literal["ask_colleagues"] = "ask_colleagues"
def get_colleague_discussion(self, completions: list[dict[str, Any]]) -> str:
@@ -70,7 +70,7 @@ class AskColleagues(AbstractBestActionPicker):
trajectory: Trajectory,
history: list[dict[str, Any]],
completions: list[dict[str, Any]],
- ) -> GetActionOutput:
+ ) -> ActionSamplerOutput:
"""Returns action with tool calls"""
discussion = self.get_colleague_discussion(completions)
logger.info(f"COLLEAGUE DISCUSSION:\n{discussion}")
@@ -78,13 +78,13 @@ class AskColleagues(AbstractBestActionPicker):
{"role": "user", "content": discussion},
]
final_completion = self._model.query(history + new_messages) # type: ignore
- return GetActionOutput(
+ return ActionSamplerOutput(
completion=final_completion,
extra_info={"colleagues": discussion},
)
-class BinaryTrajectoryComparison(AbstractBestActionPicker):
+class BinaryTrajectoryComparison(AbstractActionSampler):
type: Literal["binary_trajectory_comparison"] = "binary_trajectory_comparison"
system_template: str = """<setting>You are an expert software engineer overseeing junior developers. They suggest actions to take to solve a problem. You must choose the best action to take. </setting>"""
@@ -221,7 +221,7 @@ class BinaryTrajectoryComparison(AbstractBestActionPicker):
trajectory: Trajectory,
history: list[dict[str, Any]],
completions: list[dict[str, Any]],
- ) -> GetActionOutput:
+ ) -> ActionSamplerOutput:
parsed_completions = self.parse_completions(completions)
parsed_completions = self.filter_duplicates(parsed_completions)
if len(parsed_completions) == 1:
@@ -251,7 +251,7 @@ class BinaryTrajectoryComparison(AbstractBestActionPicker):
)
best_idx = i if idx == 1 else best_idx
- return GetActionOutput(
+ return ActionSamplerOutput(
completion=completions[best_idx],
extra_info={"comparison_log": comparison_log},
)
@@ -267,4 +267,4 @@ class BinaryTrajectoryComparison(AbstractBestActionPicker):
return 0
-BestResponsePicker = BinaryTrajectoryComparison | AskColleagues
+ActionSampler = BinaryTrajectoryComparison | AskColleagues
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.py
index 21916540..42df518e 100644
--- a/sweagent/agent/agents.py
+++ b/sweagent/agent/agents.py
@@ -16,7 +16,7 @@ from tenacity import RetryError
from typing_extensions import Self
from sweagent import __version__, get_agent_commit_hash, get_rex_commit_hash, get_rex_version
-from sweagent.agent.best_response_picker import BestResponsePicker
+from sweagent.agent.action_sampler import ActionSampler
from sweagent.agent.history_processors import DefaultHistoryProcessor, HistoryProcessor
from sweagent.agent.hooks.abstract import AbstractAgentHook, CombinedAgentHook
from sweagent.agent.models import (
@@ -132,19 +132,11 @@ class AgentConfig(BaseModel):
formatting error, a blocked action, or a bash syntax error.
"""
review_loop: ReviewLoopConfig | None = None
- best_response_picker: BestResponsePicker | None = None
- n_samples: int = 1
+ best_response_picker: ActionSampler | None = None
# pydantic config
model_config = ConfigDict(extra="forbid")
- @model_validator(mode="after")
- def validate_n_samples(self) -> Self:
- if self.n_samples is not None and self.n_samples > 1 and self.best_response_picker is None:
- msg = "n_samples must be 1 when best_response_picker is not set"
- raise ValueError(msg)
- return self
-
class _BlockedActionError(Exception):
"""Raised when the agent's action is blocked"""
@@ -173,7 +165,7 @@ class Agent:
_catch_errors: bool = True,
_always_require_zero_exit_code: bool = False,
review_loop_config: ReviewLoopConfig | None = None,
- best_response_picker: BestResponsePicker | None = None,
+ best_response_picker: ActionSampler | None = None,
n_samples: int = 1,
):
"""The agent handles the behaviour of the model and how it interacts with the environment.