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]
Fix: Hierarchical merge of multiple configs (#1123)
Kilian Lieret40a1268962a8
diff --git a/docs/usage/cl_tutorial.md b/docs/usage/cl_tutorial.mdindex 59049a7a..2b192510 100644--- a/docs/usage/cl_tutorial.md+++ b/docs/usage/cl_tutorial.md@@ -82,6 +82,7 @@ But we can also split it up into multiple files and additional command line opti=== "Command line"```bash+ # Note that you need --config in front of every config filepython run.py --config agent.yaml --config env.yaml \--problem_statement.text="Hey, can you fix all the bugs?"```@@ -103,6 +104,12 @@ But we can also split it up into multiple files and additional command line optigithub_url: https://github.com/SWE-agent/test-repo```+!!! warning "Multiple config files"+ Prior to version SWE-agent 1.1.0, configs were merged with simple dictionary updates,+ rather than a hierarchical merge, so specifying `agent` (or any key with subkeys) in the+ second config would completely overwrite all `agent` settings of the first config.+ This is fixed since SWE-agent 1.1.0.+The default config file is `config/anthropic_filemap.yaml`. Let's take a look at it:<details>diff --git a/sweagent/run/common.py b/sweagent/run/common.pyindex f3b3d037..8e45c323 100644--- a/sweagent/run/common.py+++ b/sweagent/run/common.py@@ -287,7 +287,7 @@ class BasicCLI:self.logger.warning(f"Config file {_f} is empty")continue_loaded = yaml.safe_load(txt)- config_merged.update(_loaded)+ merge_nested_dicts(config_merged, _loaded)elif self.default_settings and not cli_args.no_config_file:config_file = CONFIG_DIR / "anthropic_filemap.yaml"config_files.append(config_file)diff --git a/sweagent/utils/serialization.py b/sweagent/utils/serialization.pyindex 4edc0500..310730f2 100644--- a/sweagent/utils/serialization.py+++ b/sweagent/utils/serialization.py@@ -34,6 +34,9 @@ def _yaml_serialization_with_linebreaks(data: Any) -> str:def merge_nested_dicts(d1: dict, d2: dict) -> dict:+ """Merge two nested dictionaries, updating d1 in place.+ If a key exists in both dictionaries, the value from d2 will be used.+ """for key, value in d2.items():if isinstance(value, dict):d1[key] = merge_nested_dicts(d1.get(key, {}), value)