mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
Update agent.py
This commit is contained in:
@@ -12,19 +12,19 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import random
|
|
||||||
import os
|
import os
|
||||||
import requests
|
import random
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from google.adk import Agent
|
from google.adk import Agent
|
||||||
from google.adk.tools.tool_context import ToolContext
|
from google.adk.tools.tool_context import ToolContext
|
||||||
from google.genai import types
|
from google.genai import types
|
||||||
|
import requests
|
||||||
|
|
||||||
# Read the PAT from the environment variable
|
# Read the PAT from the environment variable
|
||||||
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") # Ensure you've set this in your shell
|
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") # Ensure you've set this in your shell
|
||||||
if not GITHUB_TOKEN:
|
if not GITHUB_TOKEN:
|
||||||
raise ValueError("GITHUB_TOKEN environment variable not set")
|
raise ValueError("GITHUB_TOKEN environment variable not set")
|
||||||
|
|
||||||
# Repository information
|
# Repository information
|
||||||
OWNER = "google"
|
OWNER = "google"
|
||||||
@@ -36,61 +36,59 @@ BASE_URL = "https://api.github.com"
|
|||||||
# Headers including the Authorization header
|
# Headers including the Authorization header
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"token {GITHUB_TOKEN}",
|
"Authorization": f"token {GITHUB_TOKEN}",
|
||||||
"Accept": "application/vnd.github.v3+json"
|
"Accept": "application/vnd.github.v3+json",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def list_issues(per_page:int):
|
def list_issues(per_page: int):
|
||||||
"""
|
"""
|
||||||
Generator to list all issues for the repository by handling pagination.
|
Generator to list all issues for the repository by handling pagination.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
per_page: number of pages to return per page.
|
per_page: number of pages to return per page.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
state="open"
|
state = "open"
|
||||||
# only process the 1st page for testing for now
|
# only process the 1st page for testing for now
|
||||||
page = 1
|
page = 1
|
||||||
results = []
|
results = []
|
||||||
url = f"{BASE_URL}/repos/{OWNER}/{REPO}/issues" # :contentReference[oaicite:16]{index=16}
|
url = ( # :contentReference[oaicite:16]{index=16}
|
||||||
# Warning: let's only handle max 10 issues at a time to avoid bad results
|
f"{BASE_URL}/repos/{OWNER}/{REPO}/issues"
|
||||||
params = {
|
)
|
||||||
"state": state,
|
# Warning: let's only handle max 10 issues at a time to avoid bad results
|
||||||
"per_page": per_page,
|
params = {"state": state, "per_page": per_page, "page": page}
|
||||||
"page": page
|
response = requests.get(url, headers=headers, params=params)
|
||||||
}
|
response.raise_for_status() # :contentReference[oaicite:17]{index=17}
|
||||||
response = requests.get(url, headers=headers, params=params)
|
issues = response.json()
|
||||||
response.raise_for_status() # :contentReference[oaicite:17]{index=17}
|
if not issues:
|
||||||
issues = response.json()
|
return []
|
||||||
if not issues:
|
for issue in issues:
|
||||||
return []
|
# Skip pull requests (issues API returns PRs as well)
|
||||||
for issue in issues:
|
if "pull_request" in issue:
|
||||||
# Skip pull requests (issues API returns PRs as well)
|
continue
|
||||||
if "pull_request" in issue:
|
results.append(issue)
|
||||||
continue
|
return results
|
||||||
results.append(issue)
|
|
||||||
return results
|
|
||||||
|
|
||||||
def add_label_to_issue(issue_number:str, label:str):
|
|
||||||
"""
|
|
||||||
Add the specified label to the given issue number.
|
|
||||||
|
|
||||||
Args:
|
def add_label_to_issue(issue_number: str, label: str):
|
||||||
issue_number: issue number of the Github issue, in string foramt.
|
"""
|
||||||
label: label to assign
|
Add the specified label to the given issue number.
|
||||||
"""
|
|
||||||
url = f"{BASE_URL}/repos/{OWNER}/{REPO}/issues/{issue_number}/labels"
|
Args:
|
||||||
payload = [label]
|
issue_number: issue number of the Github issue, in string foramt.
|
||||||
response = requests.post(url, headers=headers, json=payload)
|
label: label to assign
|
||||||
response.raise_for_status()
|
"""
|
||||||
return response.json()
|
url = f"{BASE_URL}/repos/{OWNER}/{REPO}/issues/{issue_number}/labels"
|
||||||
|
payload = [label]
|
||||||
|
response = requests.post(url, headers=headers, json=payload)
|
||||||
|
response.raise_for_status()
|
||||||
|
return response.json()
|
||||||
|
|
||||||
|
|
||||||
root_agent = Agent(
|
root_agent = Agent(
|
||||||
model='gemini-2.5-pro-preview-05-06',
|
model="gemini-2.5-pro-preview-05-06",
|
||||||
name='adk_triaging_assistant',
|
name="adk_triaging_assistant",
|
||||||
description=(
|
description="Triage ADK issues.",
|
||||||
'Triage ADK issues.'
|
|
||||||
),
|
|
||||||
instruction="""
|
instruction="""
|
||||||
You are a Github adk-python repo triaging bot. You will help get issues, and label them.
|
You are a Github adk-python repo triaging bot. You will help get issues, and label them.
|
||||||
Here are the rules for labeling:
|
Here are the rules for labeling:
|
||||||
|
|||||||
Reference in New Issue
Block a user