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

refactor: restructure microagents system #5886

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

Conversation

xingyaoww
Copy link
Collaborator

@xingyaoww xingyaoww commented Dec 28, 2024

This PR restructures the microagents system to provide a clearer separation between repository-specific instructions and shareable microagents.

Key Changes

  1. Two Sources for Instructions

    • Repository Instructions: .openhands/microagents/repo.md in each repository
      • Private to each repository
      • Repository-specific guidelines
      • Team practices and conventions
    • Shareable Microagents: OpenHands/microagents/
      • Available to all users
      • Reusable knowledge and workflows
      • Maintained in OpenHands repository
  2. Simplified Hub Structure

    OpenHands/microagents/
    ├── knowledge/  # Keyword-triggered expertise
    └── tasks/     # Interactive workflows
    
  3. Documentation

    • Clear separation between private and shareable content
    • Better examples and guidelines
    • Clearer contribution process
    • Loading order explanation
  4. Code Changes

    • New microagent models with validation
    • Support for both knowledge and task agents
    • Improved loading and matching system
    • Comprehensive test coverage

Migration Notes

  • Move repository-specific instructions to .openhands/microagents/repo.md in each repository
  • Convert shareable agents to new YAML format
  • Keep private content in repositories, share reusable knowledge in OpenHands

Part of #5538 and #5826


To run this PR locally, use the following command:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:66f4430-nikolaik   --name openhands-app-66f4430   docker.all-hands.dev/all-hands-ai/openhands:66f4430

- Move microagents to root level directory
- Convert existing agents to YAML format
- Add support for repository and keyword triggers
- Add template-based workflow support
- Remove old micro directory
- Add MicroAgentHub for centralized agent management
- Support repository and keyword triggers
- Add template-based agent support
- Update base.py to use new system
- Add tests for knowledge agent validation
- Add tests for template agent validation
- Add tests for agent loading and matching
- Add tests for template processing
- Keep legacy microagent test
- Add environment variable testing to new agents
- Add comprehensive tests for new microagent system
- Move all tests to tests/unit
- Remove repo/ directory (should be in individual repos)
- Move keyword agents to knowledge/ directly
- Update documentation to reflect new structure
- Remove official/community split
- Rename templates to tasks
- Move all agents to top-level categories
- Update documentation
- Convert all YAML files to markdown with frontmatter
- Improve readability with better formatting
- Keep YAML metadata in frontmatter
- Add better examples and documentation
- Update format guidelines to show markdown with frontmatter
- Add better examples for both agent types
- Show recommended structure for content
- Add markdown parsing with YAML frontmatter
- Update models to handle markdown content
- Rename template to task for clarity
- Add better input validation
- Update tests for new format
@neubig neubig self-assigned this Dec 30, 2024
neubig and others added 2 commits December 31, 2024 09:07
- Use os.walk() to recursively find microagent files in subdirectories
- Update CodeActAgent to use correct microagents path
- Fix prompt caching tests to work with new structure
microagents/README.md Outdated Show resolved Hide resolved
└── repo.md # Repository-specific instructions
```

## 2. Shareable Microagents (Public)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that these should be mentioned first, since they are common to all users.

microagents/README.md Outdated Show resolved Hide resolved
tests/unit/test_codeact_agent.py Outdated Show resolved Hide resolved
openhands-agent and others added 2 commits December 31, 2024 01:02
- Remove config.use_microagents = False from test fixture
- Tests now run with microagents enabled, matching real-world usage
- Add brief intro explaining what microagents are
- Reorder sections to mention shareable microagents first
- Remove vague testing section
@neubig neubig force-pushed the microagents-restructure branch from f3fa573 to d633578 Compare December 31, 2024 01:06
microagents/README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@neubig neubig left a comment

Choose a reason for hiding this comment

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

LGTM, @xingyaoww could you double-check for final approval and merge if everything looks good?

@neubig neubig marked this pull request as ready for review December 31, 2024 01:08
neubig
neubig previously approved these changes Dec 31, 2024
Copy link
Collaborator Author

@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.

I'll do some tweak! Will ping you when I'm done!

microagents/knowledge/github.md Outdated Show resolved Hide resolved
microagents/knowledge/npm.md Outdated Show resolved Hide resolved
microagents/knowledge/npm.md Outdated Show resolved Hide resolved
microagents/knowledge/github.md Outdated Show resolved Hide resolved
microagents/knowledge/github.md Outdated Show resolved Hide resolved
@xingyaoww
Copy link
Collaborator Author

xingyaoww commented Dec 31, 2024

It is still WIP (I need to test it in the UI) --- but I have tried to simplify the architecture a lot.

The backend has grown so complicated that I think maybe we should move micro-agent-related backend logic to frontend entirely:

  1. The backend is solely responsible for loading these .md files into a JSON representation
  2. Frontend grabs these JSON and:
  • Knowledge MicroAgent: We detected keywords trigger in the front even stream, and when it got triggered, we augmented the user message in FE (maybe with a collapsable icon -- so user will see what exactly are sent to the agent).
  • Repo MicroAgent: We always show what repo instruction is available now and offer the user the ability to modify it in FE (and make changes by sending File*Action and CmdRunAction to the backend via event stream OR using the specialized API for micro-agent). Though if we actually want to change the repo instruction, we'll likely need to do it in backend (unless we change it to a system message)
  • Task MicroAgent: we don't have a way to trigger them automatically, so we need to display them in FE, and the user can choose to run one of those by rendering the template into a user message

The biggest problem we have now is:

  1. We don't show the user in UI what micro-agents (keyword-based OR repo) are activated
  2. AND (I just realized that) having it in the backend might hurt our evaluation since micro-agent is enabled by default!!

@neubig
Copy link
Contributor

neubig commented Dec 31, 2024

I think the UI related stuff can be handled in a future PR FWIW. And microagents being enabled by default is true in main now right?

@neubig neubig assigned xingyaoww and unassigned neubig Dec 31, 2024
@neubig neubig dismissed their stale review December 31, 2024 20:54

Large code changes since last review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants