|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import random |
| 16 | +import os |
| 17 | +import requests |
| 18 | +import time |
| 19 | +from google.adk import Agent |
| 20 | +from google.adk.tools.tool_context import ToolContext |
| 21 | +from google.genai import types |
| 22 | + |
| 23 | + |
| 24 | +# Read the PAT from the environment variable |
| 25 | +GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") # Ensure you've set this in your shell |
| 26 | +if not GITHUB_TOKEN: |
| 27 | + raise ValueError("GITHUB_TOKEN environment variable not set") |
| 28 | + |
| 29 | +# Repository information |
| 30 | +OWNER = "google" |
| 31 | +REPO = "adk-python" |
| 32 | + |
| 33 | +# Base URL for the GitHub API |
| 34 | +BASE_URL = "https://api.github.com" |
| 35 | + |
| 36 | +# Headers including the Authorization header |
| 37 | +headers = { |
| 38 | + "Authorization": f"token {GITHUB_TOKEN}", |
| 39 | + "Accept": "application/vnd.github.v3+json" |
| 40 | +} |
| 41 | + |
| 42 | + |
| 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. |
| 49 | +
|
| 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 |
| 73 | + |
| 74 | +def add_label_to_issue(issue_number:str, label:str): |
| 75 | + """ |
| 76 | + Add the specified label to the given issue number. |
| 77 | +
|
| 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() |
| 87 | + |
| 88 | +root_agent = Agent( |
| 89 | + model='gemini-2.5-pro-preview-05-06', |
| 90 | + name='adk_triaging_assistant', |
| 91 | + description=( |
| 92 | + 'Triage ADK issues.' |
| 93 | + ), |
| 94 | + instruction=""" |
| 95 | + You are a Github adk-python repo triaging bot. You will help get issues, and label them. |
| 96 | + Here are the rules for labeling: |
| 97 | + 1. If it's about session, memory services, label it with "services" |
| 98 | + 2. If it's about UI/web, label it with "question" |
| 99 | + 3. If it's related to tools, label it with "tools" |
| 100 | + 4. In other cases, label it with "core". |
| 101 | + """, |
| 102 | + tools=[ |
| 103 | + list_issues, |
| 104 | + add_label_to_issue, |
| 105 | + ], |
| 106 | + generate_content_config=types.GenerateContentConfig( |
| 107 | + safety_settings=[ |
| 108 | + types.SafetySetting( # avoid false alarm about rolling dice. |
| 109 | + category=types.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, |
| 110 | + threshold=types.HarmBlockThreshold.OFF, |
| 111 | + ), |
| 112 | + ] |
| 113 | + ), |
| 114 | +) |
0 commit comments