Skip to content

Commit dd0cb02

Browse files
committed
fix: enforce using only existing repository labels
- Add list_repository_labels tool to fetch available labels - Update system prompt to require fetching labels first - Enforce NEVER creating new labels, only using existing ones - Import new tool in agent_runner.py This prevents the agent from creating non-existent labels.
1 parent 8f19f87 commit dd0cb02

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

.github/actions/strands-task-labeller/action.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ runs:
108108
109109
## Process
110110
1. First, search for similar issues using search_similar_issues tool to understand context
111-
2. Get available repository labels using GitHub API
111+
2. Get available repository labels using list_repository_labels tool
112112
3. Read the automation configuration from .github/config/automation-config.json for area experts
113113
4. Analyze the issue title, description, and any provided context
114-
5. Apply appropriate labels using GitHub tools
114+
5. Apply ONLY existing labels from step 2 using add_labels_to_issue tool
115115
6. Tag relevant area experts with @mentions in a comment
116116
117117
## Similar Issues Analysis
@@ -121,8 +121,10 @@ runs:
121121
- Reference similar issues in your summary if relevant
122122
123123
## Label Assignment
124-
- Use list_issues or GitHub API to get available repository labels dynamically
125-
- Apply labels that match the issue content (bug, enhancement, documentation, etc.)
124+
- CRITICAL: Use list_repository_labels tool FIRST to get available labels
125+
- ONLY apply labels that exist in the repository - NEVER create new labels
126+
- Match issue content to existing labels (bug, enhancement, documentation, etc.)
127+
- If no perfect match exists, choose the closest existing label
126128
- Focus on categorization labels that help with organization
127129
128130
## Area Expert Assignment Rules

.github/scripts/python/agent_runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
get_pr_review_and_comments,
3030
list_issues,
3131
list_pull_requests,
32+
list_repository_labels,
3233
reply_to_review_comment,
3334
search_similar_issues,
3435
update_issue,
@@ -67,6 +68,7 @@ def _get_all_tools() -> list[Any]:
6768
add_labels_to_issue,
6869
get_issue_comments,
6970
search_similar_issues,
71+
list_repository_labels,
7072

7173
# GitHub PR tools
7274
create_pull_request,

.github/scripts/python/github_tools.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,4 +930,33 @@ def search_similar_issues(query: str, state: str = "all", limit: int = 5, repo:
930930
return error_msg
931931

932932

933+
@tool
934+
@log_inputs
935+
def list_repository_labels(repo: str | None = None) -> str:
936+
"""Lists all available labels in the repository.
937+
938+
Args:
939+
repo: GitHub repository in the format "owner/repo" (optional; falls back to env var)
940+
941+
Returns:
942+
List of available label names
943+
"""
944+
result = _github_request("GET", "labels", repo)
945+
if isinstance(result, str):
946+
console.print(Panel(escape(result), title="[bold red]Error", border_style="red"))
947+
return result
948+
949+
if not result:
950+
message = f"No labels found in {repo or os.environ.get('GITHUB_REPOSITORY')}"
951+
console.print(Panel(escape(message), title="[bold yellow]Info", border_style="yellow"))
952+
return message
953+
954+
label_names = [label["name"] for label in result]
955+
output = f"Available labels in {repo or os.environ.get('GITHUB_REPOSITORY')}:\n"
956+
output += ", ".join(label_names)
957+
958+
console.print(Panel(escape(output), title="[bold green]🏷️ Repository Labels", border_style="blue"))
959+
return output
960+
961+
933962

0 commit comments

Comments
 (0)