Skip to content

Commit b7ebb69

Browse files
Merge pull request #1171 from google:hangfei-patch-3
PiperOrigin-RevId: 767701441
2 parents 4269cac + 19dbe24 commit b7ebb69

File tree

1 file changed

+118
-0
lines changed
  • contributing/samples/adk_triaging_agent

1 file changed

+118
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 os
16+
import random
17+
import time
18+
19+
from google.adk import Agent
20+
from google.adk.tools.tool_context import ToolContext
21+
from google.genai import types
22+
import requests
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 = ( # :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
71+
72+
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()
86+
87+
88+
root_agent = Agent(
89+
model="gemini-2.5-pro-preview-05-06",
90+
name="adk_triaging_assistant",
91+
description="Triage ADK issues.",
92+
instruction="""
93+
You are a Github adk-python repo triaging bot. You will help get issues, and label them.
94+
Here are the rules for labeling:
95+
- If the user is asking about documentation-related questions, label it with "documentation".
96+
- If it's about session, memory services, label it with "services"
97+
- If it's about UI/web, label it with "question"
98+
- If it's related to tools, label it with "tools"
99+
- If it's about agent evalaution, then label it with "eval".
100+
- If it's about streaming/live, label it with "live".
101+
- If it's about model support(non-Gemini, like Litellm, Ollama, OpenAI models), label it with "models".
102+
- If it's about tracing, label it with "tracing".
103+
- If it's agent orchestration, agent definition, label it with "core".
104+
- If you can't find a appropriate labels for the issue, return the issues to user to decide.
105+
""",
106+
tools=[
107+
list_issues,
108+
add_label_to_issue,
109+
],
110+
generate_content_config=types.GenerateContentConfig(
111+
safety_settings=[
112+
types.SafetySetting( # avoid false alarm about rolling dice.
113+
category=types.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
114+
threshold=types.HarmBlockThreshold.OFF,
115+
),
116+
]
117+
),
118+
)

0 commit comments

Comments
 (0)