All-Hands-AI / OpenHands

🙌 OpenHands: Code Less, Make More
https://all-hands.dev
MIT License
33.52k stars 3.84k forks source link

Improving `edit_file_by_replace` method of `file_ops` plugin #3554

Closed a6kme closed 3 days ago

a6kme commented 2 months ago

Summary I was playing with OpenHands and noticed that agent makes suboptimal decisions when using edit_file_by_replace. Here is an instance where it goes into an suboptimal route trying to fix a test file. The issue can be summarised as below.

@pytest.fixture def client(): with app.test_client() as client: yield client

def test_full_ssrf(client, requests_mock):

Mock the external request

requests_mock.get("https://test.example.com/data/", text="mocked response")

# Simulate a request to the endpoint
response = client.get("/full_ssrf?subdomain=test")

# Check the response
assert response.status_code == 200
assert response.data.decode() == "mocked response"

"""

edit_file_by_replace('test.py', to_replace="from flask import Flask", new_content=EDITED_CODE)



**Motivation**
We would like to avoid similar actions by the agent.

**Technical Design**
There are two choices that I can think of to improve the plugin
1. We include a new function `replace_file_content` in `file_ops.py` plugin which can replace the old file with new content
3. We modify the prompt of `edit_file_by_replace` to add something on the lines of `If you wish to replace the content of the entire file, set to_replace to the entire content of the file`.

**Alternatives to Consider**

**Additional context**
I was using OpenAI's GPT-4 model for session.

Thank you!
mamoodi commented 2 months ago

Related: https://github.com/All-Hands-AI/OpenHands/issues/3231

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 1 week ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 3 days ago

This issue was closed because it has been stalled for over 30 days with no activity.