Skip to content

Commit 1d8d1e0

Browse files
authored
Update agent.py
1 parent 0d23258 commit 1d8d1e0

File tree

1 file changed

+48
-50
lines changed
  • contributing/samples/adk_triaging_agent

1 file changed

+48
-50
lines changed

contributing/samples/adk_triaging_agent/agent.py

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import random
1615
import os
17-
import requests
16+
import random
1817
import time
18+
1919
from google.adk import Agent
2020
from google.adk.tools.tool_context import ToolContext
2121
from google.genai import types
22-
22+
import requests
2323

2424
# Read the PAT from the environment variable
2525
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") # Ensure you've set this in your shell
2626
if not GITHUB_TOKEN:
27-
raise ValueError("GITHUB_TOKEN environment variable not set")
27+
raise ValueError("GITHUB_TOKEN environment variable not set")
2828

2929
# Repository information
3030
OWNER = "google"
@@ -36,61 +36,59 @@
3636
# Headers including the Authorization header
3737
headers = {
3838
"Authorization": f"token {GITHUB_TOKEN}",
39-
"Accept": "application/vnd.github.v3+json"
39+
"Accept": "application/vnd.github.v3+json",
4040
}
4141

4242

43-
def list_issues(per_page:int):
44-
"""
45-
Generator to list all issues for the repository by handling pagination.
43+
def list_issues(per_page: int):
44+
"""
45+
Generator to list all issues for the repository by handling pagination.
46+
47+
Args:
48+
per_page: number of pages to return per page.
4649
47-
Args:
48-
per_page: number of pages to return per page.
50+
"""
51+
state = "open"
52+
# only process the 1st page for testing for now
53+
page = 1
54+
results = []
55+
url = ( # :contentReference[oaicite:16]{index=16}
56+
f"{BASE_URL}/repos/{OWNER}/{REPO}/issues"
57+
)
58+
# Warning: let's only handle max 10 issues at a time to avoid bad results
59+
params = {"state": state, "per_page": per_page, "page": page}
60+
response = requests.get(url, headers=headers, params=params)
61+
response.raise_for_status() # :contentReference[oaicite:17]{index=17}
62+
issues = response.json()
63+
if not issues:
64+
return []
65+
for issue in issues:
66+
# Skip pull requests (issues API returns PRs as well)
67+
if "pull_request" in issue:
68+
continue
69+
results.append(issue)
70+
return results
4971

50-
"""
51-
state="open"
52-
# only process the 1st page for testing for now
53-
page = 1
54-
results = []
55-
url = f"{BASE_URL}/repos/{OWNER}/{REPO}/issues" # :contentReference[oaicite:16]{index=16}
56-
# Warning: let's only handle max 10 issues at a time to avoid bad results
57-
params = {
58-
"state": state,
59-
"per_page": per_page,
60-
"page": page
61-
}
62-
response = requests.get(url, headers=headers, params=params)
63-
response.raise_for_status() # :contentReference[oaicite:17]{index=17}
64-
issues = response.json()
65-
if not issues:
66-
return []
67-
for issue in issues:
68-
# Skip pull requests (issues API returns PRs as well)
69-
if "pull_request" in issue:
70-
continue
71-
results.append(issue)
72-
return results
7372

74-
def add_label_to_issue(issue_number:str, label:str):
75-
"""
76-
Add the specified label to the given issue number.
73+
def add_label_to_issue(issue_number: str, label: str):
74+
"""
75+
Add the specified label to the given issue number.
76+
77+
Args:
78+
issue_number: issue number of the Github issue, in string foramt.
79+
label: label to assign
80+
"""
81+
url = f"{BASE_URL}/repos/{OWNER}/{REPO}/issues/{issue_number}/labels"
82+
payload = [label]
83+
response = requests.post(url, headers=headers, json=payload)
84+
response.raise_for_status()
85+
return response.json()
7786

78-
Args:
79-
issue_number: issue number of the Github issue, in string foramt.
80-
label: label to assign
81-
"""
82-
url = f"{BASE_URL}/repos/{OWNER}/{REPO}/issues/{issue_number}/labels"
83-
payload = [label]
84-
response = requests.post(url, headers=headers, json=payload)
85-
response.raise_for_status()
86-
return response.json()
8787

8888
root_agent = Agent(
89-
model='gemini-2.5-pro-preview-05-06',
90-
name='adk_triaging_assistant',
91-
description=(
92-
'Triage ADK issues.'
93-
),
89+
model="gemini-2.5-pro-preview-05-06",
90+
name="adk_triaging_assistant",
91+
description="Triage ADK issues.",
9492
instruction="""
9593
You are a Github adk-python repo triaging bot. You will help get issues, and label them.
9694
Here are the rules for labeling:

0 commit comments

Comments
 (0)