AI On-Demand Assistant
GitHub Actions workflow for AI-powered assistance triggered by comments
AI On-Demand Assistant Workflow
A GitHub Actions workflow that provides AI-powered assistance triggered by mentioning a bot in issues, pull requests, and comments. This workflow integrates Claude Code with GitHub to provide contextual help to development teams.
Overview
The AI On-Demand Assistant workflow responds to mentions of @efp-dev-ops in:
- Issue comments
- Pull request review comments
- Pull request reviews
- New issues
When triggered, it extracts the user's request, processes it through Claude Code, and responds with helpful assistance.
Features
- Multi-trigger Support: Responds to various GitHub events
- User Authorization: Only processes requests from authorized users
- Input Validation: Validates and sanitizes user input
- Error Handling: Continues execution even if individual steps fail
- Timeout Protection: Prevents long-running executions
Configuration
Required Secrets
APP_ID: GitHub App ID for token generationPRIVATE_KEY: GitHub App private keyCLAUDE_CODE_OAUTH_TOKEN: OAuth token for Claude Code integration
Required Variables
ALLOWED_USER_LIST: JSON array of authorized GitHub usernames
Permissions
The workflow requires the following permissions:
contents: read- Read repository contentissues: write- Comment on issuespull-requests: write- Comment on pull requests
Usage
- Setup: Configure the required secrets and variables in your repository
- Authorization: Add authorized users to the
ALLOWED_USER_LISTvariable - Trigger: Mention
@efp-dev-opsin an issue or pull request with your request
Example Usage
@efp-dev-ops Can you help me understand this code structure?@efp-dev-ops Review this pull request and suggest improvementsWorkflow Steps
1. Event Filtering
The workflow only runs when:
- The mention
@efp-dev-opsis present in the content - The triggering user is in the authorized user list
- The request comes from a supported event type
2. Code Checkout
Checks out the repository code to provide context for AI responses.
3. Token Generation
Generates a GitHub App token for authenticated API operations.
4. Instruction Extraction
Extracts and processes the user's instruction:
- Removes the @mention from the content
- Validates input length (max 4000 characters)
- Sanitizes the input for safe processing
5. AI Response
Sends the processed request to Claude Code with:
- Repository context
- User instruction
- Formatting guidelines for GitHub comments
Implementation Details
Event Triggers
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
pull_request_review:
types: [submitted]
issues:
types: [opened]Conditional Execution
if: |
(
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@efp-dev-ops')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@efp-dev-ops')) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@efp-dev-ops')) ||
(github.event_name == 'issues' && contains(github.event.issue.body, '@efp-dev-ops'))
) && contains(fromJSON(vars.ALLOWED_USER_LIST), github.actor)Security Considerations
- User Authorization: Only authorized users can trigger the workflow
- Input Validation: User input is validated and truncated to prevent abuse
- Token Scope: Uses minimal required permissions
- Error Handling: Continues execution to prevent denial of service
Customization
Changing the Mention Trigger
Update the conditional logic and extraction steps to use a different mention pattern:
# Replace @efp-dev-ops with your desired mention
sed 's/@efp-dev-ops/@your-bot-name/g' .github/workflows/ai-on-demand.yamlAdjusting Input Limits
Modify the input validation step to change the character limit:
# Change the 4000 character limit
INSTRUCTION=$(echo "$INSTRUCTION" | head -c YOUR_LIMIT)Custom Prompts
Modify the direct_prompt section to customize how the AI responds:
direct_prompt: |
Your custom system prompt here.
**User Request:** ${{ steps.extract-instruction.outputs.instruction }}
Your custom instructions for response format.Troubleshooting
Common Issues
-
Workflow not triggering
- Verify the user is in
ALLOWED_USER_LIST - Check that the mention format is correct
- Ensure the workflow file is in
.github/workflows/
- Verify the user is in
-
Authentication errors
- Verify GitHub App credentials
- Check Claude Code OAuth token
- Ensure proper permissions are set
-
Response errors
- Check timeout settings
- Verify network connectivity
- Review Claude Code service status
Debug Steps
- Check the Actions tab for workflow execution logs
- Verify environment variables and secrets
- Test with a simple request first
- Review the extracted instruction output
This workflow provides a powerful way to integrate AI assistance directly into your GitHub development process, making it easy for team members to get contextual help when needed.