Implement AI moderator workflow with spam detection and comment minimization - #5907
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot use minimize-comment safe output type instead of custom job |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Updated to use the built-in safe-outputs:
minimize-comment:
max: 5This eliminates ~80 lines of custom GraphQL code and provides a cleaner API for the AI agent. Commit: dd4b0e1 |
There was a problem hiding this comment.
@copilot move readme as xml comment in ai-moderator.md
There was a problem hiding this comment.
Moved README content as an XML comment at the end of ai-moderator.md and deleted the separate README-ai-moderator.md file.
Commit: 04e8339
| ## How to fetch the Node ID | ||
|
|
||
| If you need to minimize a comment, you'll need its GraphQL node ID. You can fetch this using the GitHub MCP server tools: | ||
|
|
||
| **For issue comments**, use the GitHub REST API to get the comment: | ||
| ``` | ||
| GET /repos/<owner>/<repo>/issues/comments/<comment_id> | ||
| ``` | ||
| Replace `<owner>`, `<repo>`, and `<comment_id>` with actual values from your workflow context. | ||
| The response will include a `node_id` field. | ||
|
|
||
| **For PR review comments**, use: | ||
| ``` | ||
| GET /repos/<owner>/<repo>/pulls/comments/<comment_id> | ||
| ``` | ||
| Replace `<owner>`, `<repo>`, and `<comment_id>` with actual values. | ||
| The response will include a `node_id` field. | ||
|
|
||
| The node ID is a base64-like encoded string used by GitHub's GraphQL API (e.g., `IC_kwDOABcD1M5ZJfGH`). | ||
|
|
||
| Once you have the node ID, call the minimize_comment tool: | ||
| ``` | ||
| minimize_comment(comment_id="IC_kwDOABcD1M5ZJfGH") | ||
| ``` | ||
|
|
There was a problem hiding this comment.
@copilot this section is automatically handled by the minimize-comment tool, remove
There was a problem hiding this comment.
Removed the "How to fetch the Node ID" section. The minimize-comment tool handles GraphQL node ID fetching automatically.
Commit: 16bc26d
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot Add a custom step in the pre-activation job that skips the workflow is the actor is owner/maintainer/write access since we don't need to scan team member messages. |
|
@copilot add an optional import in the prompt body to include custom moderation prompt. Use the same file location as in the original actions/ai-moderator action. |
- Remove "How to fetch the Node ID" section (handled automatically by minimize-comment tool) - Add roles: all to allow all users to trigger the workflow - Add custom check_external_user job to skip workflow for team members (admin/maintain/write) - Add if condition to agent job to only run for external users Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Added custom
This optimizes resources by not scanning content from trusted team members. Commit: 16bc26d |
- Add optional custom prompt file support at .github/prompts/custom-moderation.prompt.yml - Follows same YAML format as original github/ai-moderator action - AI agent checks if file exists and applies additional rules if present - Updated documentation with example custom prompt configuration Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Added support for optional custom moderation prompts. The workflow now:
Updated documentation includes an example custom prompt showing the format. Commit: 45dd92d |
| allowed: [spam, ai-generated, link-spam] | ||
| minimize-comment: | ||
| max: 5 | ||
| roles: all |
There was a problem hiding this comment.
- remove roles: all line
There was a problem hiding this comment.
Removed roles: all line.
Commit: ba802a6
| engine: copilot | ||
| if: needs.check_external_user.outputs.is_external == 'true' | ||
| tools: | ||
| github: |
There was a problem hiding this comment.
Removed GitHub tools configuration.
Commit: ba802a6
|
|
||
| For issues, the issue title is: ${{ github.event.issue.title }} | ||
|
|
||
| The content body to analyze is available through the GitHub context. Use the GitHub tools to fetch the full context of the issue, comment, or pull request review comment that triggered this workflow. |
There was a problem hiding this comment.
@copilot use the needs.activation.outputs.text value
There was a problem hiding this comment.
Updated to use needs.activation.outputs.text for content. The activation job auto-fetches content from the appropriate event context.
Commit: ba802a6
|
|
||
| **Content to analyze**: | ||
|
|
||
| For issues, the issue title is: ${{ github.event.issue.title }} |
There was a problem hiding this comment.
Removed the issue title line.
Commit: ba802a6
|
|
||
| Analyze the following content that was just posted in repository ${{ github.repository }}: | ||
|
|
||
| **Issue Number** (if applicable): #${{ github.event.issue.number }} |
There was a problem hiding this comment.
Simplified context display to show all fields directly (Issue Number, PR Number, Comment ID, Author, Manual URL). Content now comes from needs.activation.outputs.text.
Commit: ba802a6
|
@copilot simplify custom prompt to just markdown |
|
@copilot do not use import to read the custom rules, tell the agent to read these instruction as system prompt. |
- Remove roles: all line (comment 2600564134) - Add workflow_dispatch support with issue_url input (comment 2600564504) - Remove GitHub tools (comment 2600565242) - Remove models: read permission (comment 2600565644) - Use needs.activation.outputs.text for content (comment 2600568773) - Remove issue title line (comment 2600569278) - Simplify context info display (comment 2600569830) - Workflow_dispatch always runs (no team member check for manual triggers) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
|
||
| **Content to analyze**: | ||
|
|
||
| ${{ needs.activation.outputs.text }} |
| **Pull Request Number** (if applicable): #${{ github.event.pull_request.number }} | ||
| **Comment ID** (if applicable): ${{ github.event.comment.id }} | ||
| **Author**: ${{ github.actor }} | ||
| **Manual URL** (if workflow_dispatch): ${{ github.event.inputs.issue_url }} |
- Change custom prompt file from .yml to .md (comment 3629579123) - Instruct agent to read file as system prompt instead of importing (comment 3629581953) - Use simple markdown format instead of complex YAML structure - Updated documentation with markdown example Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Updated to instruct the agent to read the custom moderation file as additional system prompt instructions, rather than using import logic. The agent now simply reads Commit: 5777d9b
Simplified custom prompt to markdown format. Changed from Commit: 5777d9b |
- Enclose needs.activation.outputs.text in unsafe_user_input XML tags (comment 2600594358) - Update Manual URL description to be more descriptive (comment 2600595146) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
| description: 'Issue or discussion URL to moderate (e.g., https://github.com/owner/repo/issues/123)' | ||
| required: true | ||
| type: string | ||
| permissions: |
- Remove all permissions (comment 2600673054) - Workflow will use default permissions Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Implementation Plan: AI Moderator Workflow ✅
Creating an agentic workflow that replicates the github/ai-moderator features:
ai-moderator.md).github/prompts/custom-moderation.mdgh aw compile ai-moderatorwith strict modeKey Features
Built-in Safe Outputs
Uses gh-aw's built-in
minimize-commentsafe output for comment moderation, eliminating the need for custom GraphQL code.Team Member Optimization
The workflow automatically skips spam detection for repository team members (users with admin, maintainer, or write access) to optimize resource usage:
check_external_userjob that checks user permissions via GitHub APICustom Moderation Prompts
Supports optional custom moderation rules via
.github/prompts/custom-moderation.md:Example custom moderation file:
Manual Moderation via workflow_dispatch
Allows manual triggering to moderate specific content:
issue_urlinput parameterSecurity
<unsafe_user_input>XML tags for clarityChanges Summary
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.