Skip to content

Commit

Permalink
chore: remove useless browsing code in CodeActSWEAgent (All-Hands-AI#…
Browse files Browse the repository at this point in the history
…2438)

* remove useless

* fix integration test

* Regenerate test_ipython_module artifacts for CodeActSWEAgent

---------

Co-authored-by: Boxuan Li <liboxuan@connect.hku.hk>
  • Loading branch information
yufansong and li-boxuan committed Jun 15, 2024
1 parent ac6ef8e commit 426e429
Show file tree
Hide file tree
Showing 24 changed files with 89 additions and 3,302 deletions.
14 changes: 2 additions & 12 deletions agenthub/codeact_swe_agent/codeact_swe_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
from opendevin.events.action import (
Action,
AgentFinishAction,
BrowseInteractiveAction,
CmdRunAction,
IPythonRunCellAction,
MessageAction,
)
from opendevin.events.observation import (
BrowserOutputObservation,
CmdOutputObservation,
IPythonRunCellObservation,
)
Expand All @@ -34,17 +32,14 @@ def action_to_str(action: Action) -> str:
return f'{action.thought}\n<execute_bash>\n{action.command}\n</execute_bash>'
elif isinstance(action, IPythonRunCellAction):
return f'{action.thought}\n<execute_ipython>\n{action.code}\n</execute_ipython>'
elif isinstance(action, BrowseInteractiveAction):
return f'{action.thought}\n<execute_browse>\n{action.browser_actions}\n</execute_browse>'
elif isinstance(action, MessageAction):
return action.content
return ''


def get_action_message(action: Action) -> dict[str, str] | None:
if (
isinstance(action, BrowseInteractiveAction)
or isinstance(action, CmdRunAction)
isinstance(action, CmdRunAction)
or isinstance(action, IPythonRunCellAction)
or isinstance(action, MessageAction)
):
Expand Down Expand Up @@ -74,9 +69,6 @@ def get_observation_message(obs) -> dict[str, str] | None:
content = '\n'.join(splitted)
content = truncate_observation(content)
return {'role': 'user', 'content': content}
elif isinstance(obs, BrowserOutputObservation):
content = 'OBSERVATION:\n' + truncate_observation(obs.content)
return {'role': 'user', 'content': content}
return None


Expand Down Expand Up @@ -119,7 +111,7 @@ class CodeActSWEAgent(Agent):
AgentSkillsRequirement(),
JupyterRequirement(),
]
runtime_tools: list[RuntimeTool] = [RuntimeTool.BROWSER]
runtime_tools: list[RuntimeTool] = []

system_message: str = get_system_message()
in_context_example: str = f"Here is an example of how you can interact with the environment for task solving:\n{get_in_context_example()}\n\nNOW, LET'S START!"
Expand Down Expand Up @@ -156,7 +148,6 @@ def step(self, state: State) -> Action:
Returns:
- CmdRunAction(command) - bash command to run
- IPythonRunCellAction(code) - IPython code to run
- BrowseInteractiveAction(browsergym_command) - BrowserGym commands to run
- MessageAction(content) - Message action to run (e.g. ask for clarification)
- AgentFinishAction() - end the interaction
"""
Expand Down Expand Up @@ -187,7 +178,6 @@ def step(self, state: State) -> Action:
stop=[
'</execute_ipython>',
'</execute_bash>',
'</execute_browse>',
],
temperature=0.0,
)
Expand Down
4 changes: 2 additions & 2 deletions agenthub/codeact_swe_agent/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"""

SYSTEM_SUFFIX = """The assistant's response should be concise.
The assistant should include ONLY ONE <execute_ipython> or <execute_bash> or <execute_browse> in every one of the responses, unless the assistant is finished with the task or need more input or action from the user in order to proceed.
IMPORTANT: Whenever possible, execute the code for the user using <execute_ipython> or <execute_bash> or <execute_browse> instead of providing it.
The assistant should include ONLY ONE <execute_ipython> or <execute_bash> in every one of the responses, unless the assistant is finished with the task or need more input or action from the user in order to proceed.
IMPORTANT: Whenever possible, execute the code for the user using <execute_ipython> or <execute_bash> instead of providing it.
"""

SWE_EXAMPLE = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ parse_pptx(file_path: str) -> None:
Please note that THE `edit_file` FUNCTION REQUIRES PROPER INDENTATION. If the assistant would like to add the line ' print(x)', it 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.

The assistant's response should be concise.
The assistant should include ONLY ONE <execute_ipython> or <execute_bash> or <execute_browse> in every one of the responses, unless the assistant is finished with the task or need more input or action from the user in order to proceed.
IMPORTANT: Whenever possible, execute the code for the user using <execute_ipython> or <execute_bash> or <execute_browse> instead of providing it.
The assistant should include ONLY ONE <execute_ipython> or <execute_bash> in every one of the responses, unless the assistant is finished with the task or need more input or action from the user in order to proceed.
IMPORTANT: Whenever possible, execute the code for the user using <execute_ipython> or <execute_bash> instead of providing it.


----------
Expand Down Expand Up @@ -536,4 +536,4 @@ NOW, LET'S START!

Fix typos in bad.txt. Do not ask me for confirmation at any point.

ENVIRONMENT REMINDER: You have 9 turns left to complete the task.
ENVIRONMENT REMINDER: You have 9 turns left to complete the task.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ parse_pptx(file_path: str) -> None:
Please note that THE `edit_file` FUNCTION REQUIRES PROPER INDENTATION. If the assistant would like to add the line ' print(x)', it 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.

The assistant's response should be concise.
The assistant should include ONLY ONE <execute_ipython> or <execute_bash> or <execute_browse> in every one of the responses, unless the assistant is finished with the task or need more input or action from the user in order to proceed.
IMPORTANT: Whenever possible, execute the code for the user using <execute_ipython> or <execute_bash> or <execute_browse> instead of providing it.
The assistant should include ONLY ONE <execute_ipython> or <execute_bash> in every one of the responses, unless the assistant is finished with the task or need more input or action from the user in order to proceed.
IMPORTANT: Whenever possible, execute the code for the user using <execute_ipython> or <execute_bash> instead of providing it.


----------
Expand Down Expand Up @@ -553,4 +553,4 @@ OBSERVATION:
4|Enjoy!


ENVIRONMENT REMINDER: You have 8 turns left to complete the task.
ENVIRONMENT REMINDER: You have 8 turns left to complete the task.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ parse_pptx(file_path: str) -> None:
Please note that THE `edit_file` FUNCTION REQUIRES PROPER INDENTATION. If the assistant would like to add the line ' print(x)', it 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.

The assistant's response should be concise.
The assistant should include ONLY ONE <execute_ipython> or <execute_bash> or <execute_browse> in every one of the responses, unless the assistant is finished with the task or need more input or action from the user in order to proceed.
IMPORTANT: Whenever possible, execute the code for the user using <execute_ipython> or <execute_bash> or <execute_browse> instead of providing it.
The assistant should include ONLY ONE <execute_ipython> or <execute_bash> in every one of the responses, unless the assistant is finished with the task or need more input or action from the user in order to proceed.
IMPORTANT: Whenever possible, execute the code for the user using <execute_ipython> or <execute_bash> instead of providing it.


----------
Expand Down Expand Up @@ -576,4 +576,4 @@ OBSERVATION:
[File updated. Please review the changes and make sure they are correct (correct indentation, no duplicate lines, etc). Edit the file again if necessary.]


ENVIRONMENT REMINDER: You have 7 turns left to complete the task.
ENVIRONMENT REMINDER: You have 7 turns left to complete the task.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ parse_pptx(file_path: str) -> None:
Please note that THE `edit_file` FUNCTION REQUIRES PROPER INDENTATION. If the assistant would like to add the line ' print(x)', it 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.

The assistant's response should be concise.
The assistant should include ONLY ONE <execute_ipython> or <execute_bash> or <execute_browse> in every one of the responses, unless the assistant is finished with the task or need more input or action from the user in order to proceed.
IMPORTANT: Whenever possible, execute the code for the user using <execute_ipython> or <execute_bash> or <execute_browse> instead of providing it.
The assistant should include ONLY ONE <execute_ipython> or <execute_bash> in every one of the responses, unless the assistant is finished with the task or need more input or action from the user in order to proceed.
IMPORTANT: Whenever possible, execute the code for the user using <execute_ipython> or <execute_bash> instead of providing it.


----------
Expand Down Expand Up @@ -536,4 +536,4 @@ NOW, LET'S START!

Install and import pymsgbox==1.0.9 and print it's version in /workspace/test.txt. Do not ask me for confirmation at any point.

ENVIRONMENT REMINDER: You have 9 turns left to complete the task.
ENVIRONMENT REMINDER: You have 9 turns left to complete the task.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ parse_pptx(file_path: str) -> None:
Please note that THE `edit_file` FUNCTION REQUIRES PROPER INDENTATION. If the assistant would like to add the line ' print(x)', it 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.

The assistant's response should be concise.
The assistant should include ONLY ONE <execute_ipython> or <execute_bash> or <execute_browse> in every one of the responses, unless the assistant is finished with the task or need more input or action from the user in order to proceed.
IMPORTANT: Whenever possible, execute the code for the user using <execute_ipython> or <execute_bash> or <execute_browse> instead of providing it.
The assistant should include ONLY ONE <execute_ipython> or <execute_bash> in every one of the responses, unless the assistant is finished with the task or need more input or action from the user in order to proceed.
IMPORTANT: Whenever possible, execute the code for the user using <execute_ipython> or <execute_bash> instead of providing it.


----------
Expand Down Expand Up @@ -538,15 +538,22 @@ Install and import pymsgbox==1.0.9 and print it's version in /workspace/test.txt

----------

Let's start by installing the `pymsgbox` package.
<execute_bash>
pip install pymsgbox==1.0.9
</execute_bash>
Understood! Let's proceed by installing the `pymsgbox` package version 1.0.9:


```
pythonCopy code``
```
Once the installation is complete, we'll import `pymsgbox` and print its version to a file named `test.txt` in the `/workspace` directory. Let's continue!
<execute_ipython>
# Install pymsgbox version 1.0.9
%pip install pymsgbox==1.0.9
</execute_ipython>

----------

OBSERVATION:
Package installed successfully
[Command -1 finished with exit code 0]]
[Package installed successfully]
[Kernel restarted successfully to load the package]

ENVIRONMENT REMINDER: You have 8 turns left to complete the task.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ parse_pptx(file_path: str) -> None:
Please note that THE `edit_file` FUNCTION REQUIRES PROPER INDENTATION. If the assistant would like to add the line ' print(x)', it 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.

The assistant's response should be concise.
The assistant should include ONLY ONE <execute_ipython> or <execute_bash> or <execute_browse> in every one of the responses, unless the assistant is finished with the task or need more input or action from the user in order to proceed.
IMPORTANT: Whenever possible, execute the code for the user using <execute_ipython> or <execute_bash> or <execute_browse> instead of providing it.
The assistant should include ONLY ONE <execute_ipython> or <execute_bash> in every one of the responses, unless the assistant is finished with the task or need more input or action from the user in order to proceed.
IMPORTANT: Whenever possible, execute the code for the user using <execute_ipython> or <execute_bash> instead of providing it.


----------
Expand Down Expand Up @@ -538,39 +538,47 @@ Install and import pymsgbox==1.0.9 and print it's version in /workspace/test.txt

----------

Let's start by installing the `pymsgbox` package.
<execute_bash>
pip install pymsgbox==1.0.9
</execute_bash>
Understood! Let's proceed by installing the `pymsgbox` package version 1.0.9:


```
pythonCopy code``
```
Once the installation is complete, we'll import `pymsgbox` and print its version to a file named `test.txt` in the `/workspace` directory. Let's continue!
<execute_ipython>
# Install pymsgbox version 1.0.9
%pip install pymsgbox==1.0.9
</execute_ipython>

----------

OBSERVATION:
Package installed successfully
[Command -1 finished with exit code 0]]
[Package installed successfully]
[Kernel restarted successfully to load the package]

----------

Next, let's import `pymsgbox`, get its version, and write it to `/workspace/test.txt`.
Now that `pymsgbox` is installed, let's import it and print its version to a file named `test.txt`:


```
pythonCopy code``
```
This will import `pymsgbox`, retrieve its version, and then write the version to the `test.txt` file in the `/workspace` directory.
<execute_ipython>
import pymsgbox

version = pymsgbox.__version__
# Get the version of pymsgbox
pymsgbox_version = pymsgbox.__version__

with open("/workspace/test.txt", "w") as file:
file.write(f"pymsgbox version: {version}\n")
# Write the version to a file
with open("/workspace/test.txt", "w") as f:
f.write(pymsgbox_version)
</execute_ipython>

----------

OBSERVATION:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 1
----> 1 import pymsgbox
3 version = pymsgbox.__version__
5 with open("/workspace/test.txt", "w") as file:

ModuleNotFoundError: No module named 'pymsgbox'
[Code executed successfully with no output]

ENVIRONMENT REMINDER: You have 7 turns left to complete the task.
Loading

0 comments on commit 426e429

Please sign in to comment.