A reusable GitHub Action that runs AI agents using opencode + oh-my-opencode.
name: AI Agent
on:
workflow_dispatch:
inputs:
prompt:
description: Custom prompt to run
required: false
issue_number:
description: Issue/PR number to comment on
required: false
issue_comment:
types: [created]
pull_request:
types: [review_requested]
pull_request_review:
types: [submitted]
pull_request_review_comment:
types: [created]
jobs:
agent:
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'issue_comment' &&
contains(github.event.comment.body, '@ai-agent') &&
github.event.comment.user.login != 'github-actions[bot]' &&
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association)) ||
(github.event_name == 'pull_request' &&
github.event.requested_reviewer.login == 'github-actions[bot]') ||
(github.event_name == 'pull_request_review' &&
github.event.review.user.login != 'github-actions[bot]' &&
contains(github.event.review.body, '@ai-agent')) ||
(github.event_name == 'pull_request_review_comment' &&
contains(github.event.comment.body, '@ai-agent') &&
github.event.comment.user.login != 'github-actions[bot]' &&
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association))
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.head_ref || github.ref }}
fetch-depth: 0
- uses: dobbyphus/action@main
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
bot_name: ai-agentSee examples/agent.yaml for a complete workflow with mode detection and GitHub App token comments.
| Input | Default | Description |
|---|---|---|
bot_name |
ai-agent |
Bot name for labels and mentions |
mention_users |
false |
Whether to @mention users in comments (reduces notification noise when false) |
anthropic_api_key |
- | Anthropic API key |
openai_api_key |
- | OpenAI API key |
gemini_api_key |
- | Google Gemini API key |
provider_anthropic |
max20 |
Anthropic provider setting (no/yes/max20) |
provider_openai |
no |
OpenAI provider setting (no/yes) |
provider_google |
no |
Google provider setting (no/yes) |
provider_copilot |
no |
GitHub Copilot provider setting (no/yes) |
anthropic_base_url |
- | Custom Anthropic API base URL (for proxies) |
openai_base_url |
- | Custom OpenAI API base URL (for proxies) |
primary_model |
- | Override opencode.json model |
mode |
agent |
Prompt mode (maps to {prompt_path}/{mode}.md) |
prompt |
- | Direct prompt text (alternative to mode) |
prompt_path |
.github/prompts |
Path to prompts directory |
prompt_vars |
- | JSON object for template substitution |
github_token |
github.token |
GitHub token for API access |
opencode_version |
latest |
OpenCode version to install |
oh_my_opencode_version |
latest |
oh-my-opencode version to install |
config_json |
- | Full opencode.json content (advanced) |
enabled_providers |
- | JSON array of provider IDs to enable |
disabled_providers |
- | JSON array of provider IDs to disable |
omo_config_json |
- | Full oh-my-opencode.json content (advanced) |
auth_json |
- | Full auth.json content (advanced) |
agent_keywords |
ultrawork |
Keywords to prepend for agent mode (triggers oh-my-opencode modes) |
review_keywords |
analyze |
Keywords to prepend for review mode (triggers oh-my-opencode modes) |
skill_enable_git_master |
false |
Enable git-master builtin skill (true/false) |
skill_enable_playwright |
false |
Enable playwright builtin skill (true/false) |
skill_enable_frontend_ui_ux |
false |
Enable frontend-ui-ux builtin skill (true/false) |
format_output |
true |
Format output with collapsible sections for GitHub Actions logs |
The action handles everything in a single step:
- Setup: Collects context from the trigger event, configures git, adds π reaction
- Run: Executes the AI agent with the configured prompt
- Teardown: Replays commits as signed, creates PRs, updates reaction to π or π
The action supports two modes via the mode input:
| Mode | Use Case | Prompt |
|---|---|---|
agent |
Issue comments, PR comments, workflow dispatch | Work on requests, make changes |
review |
PR opened, review requested | Review code, provide feedback |
Use job-level if to control when the agent runs. The example covers:
workflow_dispatch: Always run on manual triggerissue_comment: @mention by authorized userpull_request: Non-draft PR opened or ready for reviewpull_request_review: @mention in review bodypull_request_review_comment: @mention in inline diff comment
The agent must create a branch for any changes. Direct commits to the default branch are blocked.
- Agent creates a branch:
git checkout -b fix/issue-42 - Agent makes commits with meaningful messages
- Action automatically:
- Replays commits as signed via GitHub API
- Creates the branch on remote if new
- Opens a pull request to the default branch
All commits are signed and verified by GitHub. The agent commits normally using git commit, and the action replays each commit through the GitHub API, which signs them automatically.
| Trigger | Mode | Agent Should | Action Does |
|---|---|---|---|
| Issue comment | agent |
Create branch, commit | Push branch, create PR |
| PR comment | agent |
Commit to PR branch | Push to PR branch |
| PR inline comment | review |
Review code, respond | Commit to PR branch |
| Workflow dispatch | agent |
Create branch, commit | Push branch, create PR |
| PR opened | review |
Review code | Post review comment |
| Review request | review |
Review code | Post review comment |
Set these in Settings β Secrets and variables β Variables:
| Variable | Default | Description |
|---|---|---|
BOT_NAME |
ai-agent |
Bot mention trigger and label prefix |
BOT_LOGIN |
github-actions[bot] |
Bot login to prevent self-triggering |
The action accepts a github_token input. Choose the right token for your use case:
The simplest option. Uses the automatic GITHUB_TOKEN:
- uses: dobbyphus/action@main
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}Limitations: Cannot trigger other workflows, limited API rate, commits attributed to github-actions[bot].
For production use. Provides higher API limits, can trigger workflows, and commits are attributed to your app:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v6
with:
ref: ${{ github.head_ref || github.ref }}
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- uses: dobbyphus/action@main
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
github_token: ${{ steps.app-token.outputs.token }}Setup: Create a GitHub App with contents: write, issues: write, pull-requests: write permissions. Store the App ID in a variable and the private key as a secret.
See the commented section in examples/agent.yaml for the complete pattern.
For individual use or cross-repository access:
- uses: dobbyphus/action@main
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
github_token: ${{ secrets.PAT_TOKEN }}Templates use {{ variable }} syntax with multi-pass resolution:
# {{ title }}
{{ base_github_env }}
Hello @{{ author }}, working on {{ task }}...Place .md files in prompts/base/ to create reusable snippets:
.github/prompts/
βββ base/
β βββ my_rules.md β {{ base_my_rules }}
βββ agent.md
βββ review.md
For project conventions, use AGENTS.md in the repository root instead. The agent checks for AGENTS.md, CLAUDE.md, and COPILOT.md automatically.
Variables are merged with later sources overriding earlier ones:
- Action's
prompts/base/*.md(lowest priority) - Consumer's
prompt_path/base/*.md - User-provided
prompt_vars(highest priority)
python -m pytest tests/ -vMIT