Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

Merge branch 'mgx_ops' into feature-swe-agent

seeker5b7ca5c99d61
diff --cc metagpt/prompts/di/swe_agent.py
index a1c491210,e2cddf389..78a8ce846
--- a/metagpt/prompts/di/swe_agent.py
+++ b/metagpt/prompts/di/swe_agent.py
@@@ -5,9 -5,9 +5,9 @@@ https://github.com/princeton-nlp/SWE-ag
"""
SWE_AGENT_SYSTEM_TEMPLATE = """
- SETTING: You are an autonomous programmer, and you're working directly in the environment line with a special interface.
+ SETTING: You are an autonomous programmer, and you're working directly in the environment line with a special interface.Let's work step by step.
-The special interface consists of a file editor that shows you {WINDOW} lines of a file at a time.
+The special interface consists of a file editor that shows you 100 lines of a file at a time.
Please note that THE EDIT COMMAND REQUIRES PROPER INDENTATION. Pay attention to the original indentation when replacing the function.
If you'd like to add the line ' print(x)' you must fully write that out, with all those spaces before the code! Indentation is important and code that is not indented correctly will fail and require fixing before it can be run.
diff --cc metagpt/roles/di/swe_agent.py
index 7150c0a67,ecb57b512..e3cca3330
--- a/metagpt/roles/di/swe_agent.py
+++ b/metagpt/roles/di/swe_agent.py
@@@ -32,7 -35,8 +32,7 @@@ class SWEAgent(RoleZero)
run_eval: bool = False
async def _think(self) -> bool:
- self._format_instruction()
- self._update_system_msg()
+ await self._format_instruction()
res = await super()._think()
if self.run_eval:
await self._parse_commands_for_eval()
@@@ -47,19 -51,33 +47,17 @@@
}
)
- def _format_instruction(self):
- def _update_system_msg(self):
- """
- Sets the system message for the SWE agent.
-
- Sets the `_bash_window_size` from the environment variable `WINDOW` if it exists.
- Formats the `_system_msg` template with the current `_bash_window_size`.
- """
- if os.getenv("WINDOW"):
- self._bash_window_size = int(os.getenv("WINDOW"))
- self.system_msg = [self._system_msg.format(WINDOW=self._bash_window_size)]
-
+ async def _format_instruction(self):
"""
Formats the instruction message for the SWE agent.
Runs the "state" command in the terminal, parses its output as JSON,
and uses it to format the `_instruction` template.
"""
- state_output = self.terminal.run("state")
+ state_output = await self.terminal.run("state")
bash_state = json.loads(state_output)
-
- self.instruction = self._instruction.format(
- WINDOW=self._bash_window_size, examples=MINIMAL_EXAMPLE, **bash_state
- ).strip()
-
- return self.instruction
+ self.instruction = self._instruction.format(**bash_state).strip()
- return self.instruction
-
async def _parse_commands_for_eval(self):
"""
Handles actions based on parsed commands.