Skip to content

Commit

Permalink
Prompt updates for resolver accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
Domiii committed Dec 9, 2024
1 parent ca9beb9 commit 30b7eab
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
1 change: 0 additions & 1 deletion openhands/agenthub/codeact_agent/prompts/system_prompt.j2
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
You are OpenHands agent, a helpful AI assistant that can interact with a computer to solve tasks.
<IMPORTANT></IMPORTANT>
9 changes: 4 additions & 5 deletions openhands/events/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ def replay_enhance_action(state: State, is_workspace_repo: bool) -> Action | Non
logger.info(f'[REPLAY] latest_user_message id is {latest_user_message.id}')
# 2. Check if it has a recordingId.
recording_id = scan_recording_id(latest_user_message.content)
logger.debug(
f'DDBG Scanned for recording id: {latest_user_message.content}...'
)
if recording_id:
# 3. Analyze recording and start the enhancement action.
logger.info(
Expand Down Expand Up @@ -122,10 +119,12 @@ def handle_replay_enhance_observation(
# start_location = result.get('startLocation', '')
start_name = result.get('startName', '')

enhancement = f'There is a bug in {annotated_repo_path}:\n\n<BUG_REPORT>{comment_text}</BUG_REPORT>\n\nReproduction information from a recording of the problem is available in source comments.\nThe bug was reported at {start_name}. Start your investigation there. Then keep searching for related `reproduction step` comments and pay special attention to their contents, as they provide important data flow and type information.\n\nOnce done, propose necessary changes without implementing them.'
# TODO: Move this to a prompt template file.
enhancement = f'There is a bug in {annotated_repo_path}:\n\n{comment_text}\n\nReproduction information from a recording of the problem is available in source comments.\nThe bug was reported at {start_name}. Start your investigation there. Then keep searching for related `reproduction step` comments and pay special attention to their contents.\nOnce done, propose necessary changes, without implementing them.'

# Enhance:
user_message.content = f'{original_prompt}\n\n{enhancement}'
user_message.content = f'{enhancement}\n\n{original_prompt}'
# user_message.content = enhancement
logger.info(f'[REPLAY] Enhanced user prompt:\n{user_message.content}')
return True
else:
Expand Down
14 changes: 5 additions & 9 deletions openhands/resolver/prompts/resolve/basic.jinja
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
Please fix the following issue for the repository in /workspace.
An environment has been set up for you to start working. You may assume all necessary tools are installed.
Please fix this issue in `/workspace`.

# Problem Statement
<ISSUE_INFORMATION>
{{ body }}
</ISSUE_INFORMATION>

IMPORTANT: You should ONLY interact with the environment provided to you AND NEVER ASK FOR HUMAN HELP.
You SHOULD INCLUDE PROPER INDENTATION in your edit commands.{% if repo_instruction %}
You do NOT need to write new tests for code changes.

{% if repo_instruction %}
Some basic information about this repository:
{{ repo_instruction }}{% endif %}

You do NOT need to write new tests for code changes.

When you think you have fixed the issue through code changes, please finish the interaction.
19 changes: 19 additions & 0 deletions openhands/resolver/resolve_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
import shutil
import subprocess
import traceback
from typing import Any
from uuid import uuid4

Expand Down Expand Up @@ -445,6 +446,24 @@ async def resolve_issue(
target_branch: Optional target branch to create PR against (for PRs).
reset_logger: Whether to reset the logger for multiprocessing.
"""

def exception_handler(_loop, context):
exception = context.get('exception')
if exception is not None:
# We have an actual exception
print(f'ERROR: {exception}')
traceback.print_exception(
type(exception), exception, exception.__traceback__
)
else:
# No exception object; print the message and current stack
message = context.get('message', 'Unknown error')
print(f'ERROR: {message}')
traceback.print_stack()

loop = asyncio.get_running_loop()
loop.set_exception_handler(exception_handler)

issue_handler = issue_handler_factory(issue_type, owner, repo, token)

# Load dataset
Expand Down

0 comments on commit 30b7eab

Please sign in to comment.