-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: specialize CodeAct into micro agents by providing markdown files (
#3511) * update microagent name and update template.toml * substitute actual micro_agent_name for prompt manager * add python-frontmatter * support micro agent in codeact * add test cases * add instruction from require env var * add draft gh micro agent * update poetry lock * update poetry lock
- Loading branch information
Showing
11 changed files
with
273 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
name: github | ||
agent: CodeActAgent | ||
require_env_var: | ||
SANDBOX_ENV_GITHUB_TOKEN: "Create a GitHub Personal Access Token (https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) and set it as SANDBOX_GITHUB_TOKEN in your environment variables." | ||
--- | ||
|
||
# How to Interact with Github | ||
|
||
## Environment Variable Available | ||
|
||
1. `GITHUB_TOKEN`: A read-only token for Github. | ||
|
||
## Using GitHub's RESTful API | ||
|
||
Use `curl` with the `GITHUB_TOKEN` to interact with GitHub's API. Here are some common operations: | ||
|
||
1. View an issue: | ||
``` | ||
curl -H "Authorization: token $GITHUB_TOKEN" \ | ||
https://api.github.com/repos/{owner}/{repo}/issues/{issue_number} | ||
``` | ||
|
||
2. List repository issues: | ||
``` | ||
curl -H "Authorization: token $GITHUB_TOKEN" \ | ||
https://api.github.com/repos/{owner}/{repo}/issues | ||
``` | ||
|
||
3. Get repository details: | ||
``` | ||
curl -H "Authorization: token $GITHUB_TOKEN" \ | ||
https://api.github.com/repos/{owner}/{repo} | ||
``` | ||
|
||
4. List pull requests: | ||
``` | ||
curl -H "Authorization: token $GITHUB_TOKEN" \ | ||
https://api.github.com/repos/{owner}/{repo}/pulls | ||
``` | ||
|
||
5. Get user information: | ||
``` | ||
curl -H "Authorization: token $GITHUB_TOKEN" \ | ||
https://api.github.com/user | ||
``` | ||
|
||
Replace `{owner}`, `{repo}`, and `{issue_number}` with appropriate values. | ||
|
||
## Important Notes | ||
|
||
1. Always use the GitHub API for operations instead of a web browser. | ||
2. The `GITHUB_TOKEN` is read-only. Avoid operations that require write access. | ||
3. Git config (username and email) is pre-set. Do not modify. | ||
4. Edit and test code locally. Never push directly to remote. | ||
5. Verify correct branch before committing. | ||
6. Commit changes frequently. | ||
7. If the issue or task is ambiguous or lacks sufficient detail, always request clarification from the user before proceeding. | ||
8. You should avoid using command line tools like `sed` for file editing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
|
||
import frontmatter | ||
import pydantic | ||
|
||
from openhands.controller.agent import Agent | ||
from openhands.core.exceptions import MicroAgentValidationError | ||
from openhands.core.logger import openhands_logger as logger | ||
|
||
|
||
class MicroAgentMetadata(pydantic.BaseModel): | ||
name: str | ||
agent: str | ||
require_env_var: dict[str, str] | ||
|
||
|
||
class MicroAgent: | ||
def __init__(self, path: str): | ||
self.path = path | ||
if not os.path.exists(path): | ||
raise FileNotFoundError(f'Micro agent file {path} is not found') | ||
with open(path, 'r') as file: | ||
self._loaded = frontmatter.load(file) | ||
self._content = self._loaded.content | ||
self._metadata = MicroAgentMetadata(**self._loaded.metadata) | ||
self._validate_micro_agent() | ||
|
||
@property | ||
def content(self) -> str: | ||
return self._content | ||
|
||
def _validate_micro_agent(self): | ||
logger.info( | ||
f'Loading and validating micro agent [{self._metadata.name}] based on [{self._metadata.agent}]' | ||
) | ||
# Make sure the agent is registered | ||
agent_cls = Agent.get_cls(self._metadata.agent) | ||
assert agent_cls is not None | ||
# Make sure the environment variables are set | ||
for env_var, instruction in self._metadata.require_env_var.items(): | ||
if env_var not in os.environ: | ||
raise MicroAgentValidationError( | ||
f'Environment variable [{env_var}] is required by micro agent [{self._metadata.name}] but not set. {instruction}' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.