Skip to content

Commit

Permalink
Fix issue #5830: Test openhands instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
openhands-agent committed Dec 26, 2024
1 parent e2a25f1 commit 4979baa
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
24 changes: 23 additions & 1 deletion openhands/resolver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,29 @@ python -m openhands.resolver.send_pull_request --issue-number ISSUE_NUMBER --git

## Providing Custom Instructions

You can customize how the AI agent approaches issue resolution by adding a `.openhands_instructions` file to the root of your repository. If present, this file's contents will be injected into the prompt for openhands edits.
You can customize how the AI agent approaches issue resolution by adding repository instructions in `.openhands/microagents/repo.md` file. This file should contain repository-specific information and guidelines that will be injected into the prompt for OpenHands edits.

Example structure for `.openhands/microagents/repo.md`:
```markdown
---
name: repo
agent: CodeActAgent
---
# Repository Instructions

This repository contains [brief description of your project].

## Directory Structure
- src/: [description]
- tests/: [description]
...

## Development Guidelines
[Your specific coding standards and practices]

## Testing Requirements
[How to run tests and what types of tests are required]
```

## Troubleshooting

Expand Down
8 changes: 4 additions & 4 deletions openhands/resolver/resolve_all_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ async def resolve_issues(
logger.info(f'Base commit: {base_commit}')

if repo_instruction is None:
# Check for .openhands_instructions file in the workspace directory
openhands_instructions_path = os.path.join(repo_dir, '.openhands_instructions')
if os.path.exists(openhands_instructions_path):
with open(openhands_instructions_path, 'r') as f:
# Check for repository instructions in .openhands/microagents/repo.md
repo_instructions_path = os.path.join(repo_dir, '.openhands/microagents/repo.md')
if os.path.exists(repo_instructions_path):
with open(repo_instructions_path, 'r') as f:
repo_instruction = f.read()

# OUTPUT FILE
Expand Down
8 changes: 4 additions & 4 deletions openhands/resolver/resolve_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,10 @@ async def resolve_issue(
logger.info(f'Base commit: {base_commit}')

if repo_instruction is None:
# Check for .openhands_instructions file in the workspace directory
openhands_instructions_path = os.path.join(repo_dir, '.openhands_instructions')
if os.path.exists(openhands_instructions_path):
with open(openhands_instructions_path, 'r') as f:
# Check for repository instructions in .openhands/microagents/repo.md
repo_instructions_path = os.path.join(repo_dir, '.openhands/microagents/repo.md')
if os.path.exists(repo_instructions_path):
with open(repo_instructions_path, 'r') as f:
repo_instruction = f.read()

# OUTPUT FILE
Expand Down
8 changes: 5 additions & 3 deletions openhands/runtime/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,15 @@ def get_custom_microagents(self, selected_repository: str | None) -> list[str]:
dir_name = str(
Path(selected_repository.split('/')[1]) / custom_microagents_dir
)
# Legacy support for .openhands_instructions
obs = self.read(FileReadAction(path='.openhands_instructions'))
if isinstance(obs, ErrorObservation):
self.log('debug', 'openhands_instructions not present')
else:
if not isinstance(obs, ErrorObservation):
self.log('info', 'Found legacy .openhands_instructions file')
openhands_instructions = obs.content
self.log('info', f'openhands_instructions: {openhands_instructions}')
custom_microagents_content.append(openhands_instructions)
else:
self.log('debug', '.openhands_instructions not present')

files = self.list_files(dir_name)

Expand Down

0 comments on commit 4979baa

Please sign in to comment.