Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(enh) AgentSkills: fix \n handling with file editing (iPython) #3904

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

tobitege
Copy link
Collaborator

@tobitege tobitege commented Sep 16, 2024

Short description of the problem this fixes or functionality that this introduces. This may be used for the CHANGELOG

Fixed handling of literal "\n" in file editing operations via iPython.


Give a summary of what the PR does, explaining any non-trivial design decisions

  • in file_ops.py and CodeActAgent.py fixed handling of literal line breaks
  • helps fix errors when LLM calls edit_file_by_replace but errors with [No exact match found in xxx]
    this contributed to an excessive amount of steps needed (and often failing the bench test instance)
  • with this change the Aider bench instance 57 is finally successful as it doesn't run out of steps
  • added several more unit tests

TODO:

  • Aider bench (done)
  • SWE bench

In below example, the to_replace value with this PR has the \n correctly treated as text, whereas in main it would be shown as an actual line break:

THOUGHT: Thank you for providing the content of the `accumulate.py` file. Now, let's implement the `accumulate` function according to the given instructions. We'll modify the file to include the correct implementation:
CODE:
edit_file_by_replace(
    'accumulate.py',
    to_replace="def accumulate(collection, operation):\n    pass",
    new_content="""def accumulate(collection, operation):
    return [operation(item) for item in collection]"""
)

Link of any specific issues this addresses

Fixes #3650

@tobitege tobitege added agent quality Problems with specific agents severity:critical Affecting all users eval-this labels Sep 16, 2024
@tobitege tobitege marked this pull request as draft September 16, 2024 21:00
@tobitege tobitege changed the title (enh) AgentSkills: fix \n handling with file editing (enh) AgentSkills: fix \n handling with file editing (iPython) Sep 16, 2024
openhands/core/config.py Outdated Show resolved Hide resolved
@tobitege
Copy link
Collaborator Author

I'm still looking into formatting issues with linebreaks with this.
Even though the fix is working to have more correct search hits in edit_file_by_replace in e.g. IPython code snippets, it doesn't correctly replace "\n" for display in logs.

@tobitege
Copy link
Collaborator Author

tobitege commented Sep 17, 2024

Preliminary Aider bench result (unit tests enabled, 30-steps limit):
Passed 124 tests, failed 9 tests, resolve rate = 93.23%
grafik

Copy link
Contributor

@xingyaoww xingyaoww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a stab at this! This is a very tricky issue that somewhat lead me to believe we need to implement an EditAction (#3777) 😢

openhands/core/config.py Outdated Show resolved Hide resolved
f'[File: {temp_file_path} (4 lines total after edit)]\n'
'(this is the beginning of the file)\n'
'1|Line 1\\n\n'
'2|Line 2\n'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this Line 2 get replaced? because to_replace='Line 2\r\nLine 3\\r\\n',

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually not in this case as the search term is Line 2\r\nLine 3\\r\\n (note the \r)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, since "Line 2\r\nLine 3\r\n" is the search term, shouldn't Line 2 completely goes way in the new fine, since it it replaced?

agenthub/codeact_agent/codeact_agent.py Outdated Show resolved Hide resolved
@tobitege tobitege marked this pull request as ready for review September 17, 2024 17:15
@tobitege
Copy link
Collaborator Author

@xingyaoww - this should be ready for you eval, if you like

Copy link
Contributor

@xingyaoww xingyaoww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot -- this looks much cleaner! Just had a few questions before i can start kick off eval

f'[File: {temp_file_path} (4 lines total after edit)]\n'
'(this is the beginning of the file)\n'
'1|Line 1\\n\n'
'2|Line 2\n'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, since "Line 2\r\nLine 3\r\n" is the search term, shouldn't Line 2 completely goes way in the new fine, since it it replaced?

@xingyaoww
Copy link
Contributor

Kicked off eval on the latest commit!

@tobitege
Copy link
Collaborator Author

Kicked off eval on the latest commit!

Thank you! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent quality Problems with specific agents eval-this severity:critical Affecting all users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Editing does not work on lines that contain \n
4 participants