Skip to content

Commit 149c5fe

Browse files
xuanyang15copybara-github
authored andcommitted
chore: update triage agent to assign the issue to owner after labeling it
PiperOrigin-RevId: 781604031
1 parent 10197db commit 149c5fe

File tree

2 files changed

+52
-20
lines changed
  • contributing/samples

2 files changed

+52
-20
lines changed

contributing/samples/adk_issue_formatting_agent/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
headers = {
2121
"Authorization": f"token {GITHUB_TOKEN}",
2222
"Accept": "application/vnd.github.v3+json",
23+
"X-GitHub-Api-Version": "2022-11-28",
2324
}
2425

2526

contributing/samples/adk_triaging_agent/agent.py

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@
2525
from google.adk import Agent
2626
import requests
2727

28-
ALLOWED_LABELS = [
29-
"documentation",
30-
"services",
31-
"question",
32-
"tools",
33-
"eval",
34-
"live",
35-
"models",
36-
"tracing",
37-
"core",
38-
"web",
39-
]
28+
LABEL_TO_OWNER = {
29+
"documentation": "polong",
30+
"services": "DeanChensj",
31+
"question": "",
32+
"tools": "seanzhou1023",
33+
"eval": "ankursharmas",
34+
"live": "hangfei",
35+
"models": "selcukgun",
36+
"tracing": "Jacksunwei",
37+
"core": "Jacksunwei",
38+
"web": "wyf7107",
39+
}
4040

4141
APPROVAL_INSTRUCTION = (
4242
"Do not ask for user approval for labeling! If you can't find appropriate"
@@ -78,33 +78,61 @@ def list_unlabeled_issues(issue_count: int) -> dict[str, Any]:
7878
return {"status": "success", "issues": unlabeled_issues}
7979

8080

81-
def add_label_to_issue(issue_number: int, label: str) -> dict[str, Any]:
82-
"""Add the specified label to the given issue number.
81+
def add_label_and_owner_to_issue(
82+
issue_number: int, label: str
83+
) -> dict[str, Any]:
84+
"""Add the specified label and owner to the given issue number.
8385
8486
Args:
8587
issue_number: issue number of the Github issue.
8688
label: label to assign
8789
8890
Returns:
89-
The the status of this request, with the applied label when successful.
91+
The the status of this request, with the applied label and assigned owner
92+
when successful.
9093
"""
9194
print(f"Attempting to add label '{label}' to issue #{issue_number}")
92-
if label not in ALLOWED_LABELS:
95+
if label not in LABEL_TO_OWNER:
9396
return error_response(
9497
f"Error: Label '{label}' is not an allowed label. Will not apply."
9598
)
9699

97-
url = f"{GITHUB_BASE_URL}/repos/{OWNER}/{REPO}/issues/{issue_number}/labels"
98-
payload = [label, BOT_LABEL]
100+
label_url = (
101+
f"{GITHUB_BASE_URL}/repos/{OWNER}/{REPO}/issues/{issue_number}/labels"
102+
)
103+
label_payload = [label, BOT_LABEL]
99104

100105
try:
101-
response = post_request(url, payload)
106+
response = post_request(label_url, label_payload)
102107
except requests.exceptions.RequestException as e:
103108
return error_response(f"Error: {e}")
109+
110+
owner = LABEL_TO_OWNER.get(label, None)
111+
if not owner:
112+
return {
113+
"status": "warning",
114+
"message": (
115+
f"{response}\n\nLabel '{label}' does not have an owner. Will not"
116+
" assign."
117+
),
118+
"applied_label": label,
119+
}
120+
121+
assignee_url = (
122+
f"{GITHUB_BASE_URL}/repos/{OWNER}/{REPO}/issues/{issue_number}/assignees"
123+
)
124+
assignee_payload = {"assignees": [owner]}
125+
126+
try:
127+
response = post_request(assignee_url, assignee_payload)
128+
except requests.exceptions.RequestException as e:
129+
return error_response(f"Error: {e}")
130+
104131
return {
105132
"status": "success",
106133
"message": response,
107134
"applied_label": label,
135+
"assigned_owner": owner,
108136
}
109137

110138

@@ -128,9 +156,12 @@ def add_label_to_issue(issue_number: int, label: str) -> dict[str, Any]:
128156
- If it's agent orchestration, agent definition, label it with "core".
129157
- If you can't find a appropriate labels for the issue, follow the previous instruction that starts with "IMPORTANT:".
130158
159+
Call the `add_label_and_owner_to_issue` tool to label the issue, which will also assign the issue to the owner of the label.
160+
131161
Present the followings in an easy to read format highlighting issue number and your label.
132162
- the issue summary in a few sentence
133163
- your label recommendation and justification
164+
- the owner of the label if you assign the issue to an owner
134165
""",
135-
tools=[list_unlabeled_issues, add_label_to_issue],
166+
tools=[list_unlabeled_issues, add_label_and_owner_to_issue],
136167
)

0 commit comments

Comments
 (0)