|
| 1 | +from google.adk.agents.llm_agent import Agent |
| 2 | +from google.adk.tools.mcp_tool import McpToolset, StreamableHTTPConnectionParams |
| 3 | +from google.adk.tools.agent_tool import AgentTool |
| 4 | +from google.adk.agents.sequential_agent import SequentialAgent |
| 5 | +from issue_to_jules_agent.subagents.spam_agent.agent import spam_agent |
| 6 | +from issue_to_jules_agent.subagents.label_agent.agent import label_agent |
| 7 | +from issue_to_jules_agent.subagents.complexity_scoping_agent.agent import complexity_scoping_agent |
| 8 | +from issue_to_jules_agent.subagents.issue_type_agent.agent import issue_type_agent |
| 9 | + |
| 10 | +import requests |
| 11 | +import json |
| 12 | + |
| 13 | +import os |
| 14 | + |
| 15 | +JULES_KEY = os.environ.get("JULES_KEY") |
| 16 | +GITHUB_PAT = os.environ.get("GITHUB_PAT") |
| 17 | + |
| 18 | +IS_SPAM = AgentTool( |
| 19 | + agent=spam_agent, |
| 20 | +) |
| 21 | + |
| 22 | +LABELER = AgentTool( |
| 23 | + agent=label_agent |
| 24 | +) |
| 25 | + |
| 26 | +COMPLEXITY_SCORE = AgentTool( |
| 27 | + agent=complexity_scoping_agent, |
| 28 | +) |
| 29 | + |
| 30 | +ISSUE_TYPE = AgentTool( |
| 31 | + agent=issue_type_agent, |
| 32 | +) |
| 33 | + |
| 34 | +github_toolset = McpToolset( |
| 35 | + connection_params=StreamableHTTPConnectionParams( |
| 36 | + url="https://api.githubcopilot.com/mcp", |
| 37 | + headers={"Authorization": "Bearer " + GITHUB_PAT}, |
| 38 | + ), |
| 39 | + tool_filter=[ |
| 40 | + "get_file_contents", |
| 41 | + "get_commit", |
| 42 | + "search_repositories", |
| 43 | + "search_issues", |
| 44 | + "search_code", |
| 45 | + "list_issues", |
| 46 | + "list_issue_types", |
| 47 | + "list_commits", |
| 48 | + "issue_read", |
| 49 | + "issue_write", |
| 50 | + ], |
| 51 | +) |
| 52 | + |
| 53 | + |
| 54 | +def jules_create_session(prompt: str, title: str) -> dict: |
| 55 | + """ |
| 56 | + Creates a new Jules session to address a specific prompt within a GitHub repository. |
| 57 | +
|
| 58 | + Args: |
| 59 | + prompt (str): The detailed prompt or description of the task for Jules. |
| 60 | + title (str): The title for the Jules session. |
| 61 | +
|
| 62 | + Returns: |
| 63 | + dict: A dictionary with 'status' ('success' or 'failure') and 'report' keys. |
| 64 | + If successful, 'report' contains the JSON response from the API. |
| 65 | + If failed, 'report' contains an error message. |
| 66 | + """ |
| 67 | + url = "https://jules.googleapis.com/v1alpha/sessions" |
| 68 | + headers = {"Content-Type": "application/json", "X-Goog-Api-Key": JULES_KEY} |
| 69 | + payload = { |
| 70 | + "prompt": prompt, |
| 71 | + "sourceContext": { |
| 72 | + "source": "sources/github/firebase/firebase-tools", |
| 73 | + "githubRepoContext": {"startingBranch": "main"}, |
| 74 | + }, |
| 75 | + "title": title, |
| 76 | + } |
| 77 | + |
| 78 | + response = None |
| 79 | + try: |
| 80 | + response = requests.post(url, headers=headers, data=json.dumps(payload)) |
| 81 | + response.raise_for_status() # Raise an exception for bad status codes |
| 82 | + response_json = response.json() |
| 83 | + print("Jules Session Created Successfully:") |
| 84 | + print(json.dumps(response_json, indent=2)) |
| 85 | + return {"status": "success", "report": response_json} |
| 86 | + except requests.exceptions.RequestException as e: |
| 87 | + error_message = f"Error creating Jules session: {e}" |
| 88 | + print(error_message) |
| 89 | + if response is not None: |
| 90 | + error_message += f"\nResponse status code: {response.status_code}" |
| 91 | + error_message += f"\nResponse body: {response.text}" |
| 92 | + print(f"Response status code: {response.status_code}") |
| 93 | + print(f"Response body: {response.text}") |
| 94 | + return {"status": "failure", "report": error_message} |
| 95 | + |
| 96 | + |
| 97 | +jules_agent = Agent( |
| 98 | + model="gemini-3-pro-preview", |
| 99 | + name="jules_agent", |
| 100 | + description="Formats a task for jules, a code agent to help solve a GitHub issue based on the information provided", |
| 101 | + instruction=""" |
| 102 | + ### System Instructions |
| 103 | +You are an expert assistant for a software development team. Your role is to process bug reports and feature requests, and then create a clear, structured, and actionable task for an AI developer named Jules. |
| 104 | +
|
| 105 | +### Task |
| 106 | +Based on the provided issue details, generate a complete, markdown-formatted task description for Jules. |
| 107 | +
|
| 108 | +### Instructions |
| 109 | +1. Read the `issue_body` and any `discussion_body` provided. |
| 110 | +2. **Summarize the Issue:** Create a concise summary of the problem and include a link to the original issue. |
| 111 | +3. **Define the Task:** Write a clear and direct task for Jules to solve the problem. |
| 112 | +4. **Handle Reproduction Steps:** |
| 113 | + * If `reproduction_steps` are provided in the input, include them under the "Reproduction" heading. |
| 114 | + * If `reproduction_steps` are empty or not provided, add the following instruction for Jules: "Please attempt to reproduce the issue first so that you can verify the fix." |
| 115 | +5. **Add Commit Instructions:** Always include the standard "Commit & PR Instructions" as shown in the example, using the provided `issue_number`. |
| 116 | +
|
| 117 | +### Input Placeholders |
| 118 | +- `{{issue_body}}`: The raw text of the issue report. |
| 119 | +- `{{discussion_body}}`: (Optional) The raw text of the discussion. |
| 120 | +- `{{original_link}}`: The URL to the original issue. |
| 121 | +- `{{issue_number}}`: The numerical ID of the issue. |
| 122 | +- `{{reproduction_steps}}`: (Optional) Pre-written steps to reproduce the issue. |
| 123 | +
|
| 124 | +### Output Template & Example |
| 125 | +
|
| 126 | +--- |
| 127 | +
|
| 128 | +#### Example Input: |
| 129 | +```json |
| 130 | +{ |
| 131 | + "issue_body": "The login button looks weird on my phone. It's all the way on the right and hard to click. I'm using Safari.", |
| 132 | + "discussion_body": "User @dev1 confirmed this on iOS 15. It looks like a flexbox alignment problem in `container.css`. Should be a quick fix.", |
| 133 | + "original_link": "https://github.com/example/project/issues/123", |
| 134 | + "issue_number": "123", |
| 135 | + "reproduction_steps": "" |
| 136 | +} |
| 137 | +``` |
| 138 | +
|
| 139 | +#### Corresponding Desired Output: |
| 140 | +```markdown |
| 141 | +### Issue Summary |
| 142 | +The login button is misaligned on mobile browsers, specifically Safari on iOS, likely due to a flexbox alignment problem. |
| 143 | +
|
| 144 | +Original Issue: https://github.com/example/project/issues/123 |
| 145 | +
|
| 146 | +### Task for Jules |
| 147 | +Please fix the CSS for the login page to ensure the login button is correctly aligned within its container on mobile browsers, especially Safari. |
| 148 | +
|
| 149 | +### Reproduction |
| 150 | +Please attempt to reproduce the issue first so that you can verify the fix. |
| 151 | +
|
| 152 | +### Commit & PR Instructions |
| 153 | +- Revert any changes to `npm-shrinkwrap.json` before committing. |
| 154 | +- If this change is user-facing, please write a `CHANGELOG.md` entry. |
| 155 | +- Ensure your PR description includes the line: `fixes #123` |
| 156 | +``` |
| 157 | +
|
| 158 | +--- |
| 159 | +
|
| 160 | +Now, generate the task description for the user's input. |
| 161 | + """, |
| 162 | + tools=[jules_create_session], |
| 163 | +) |
| 164 | + |
| 165 | +root_agent = Agent( |
| 166 | + model="gemini-3-pro-preview", |
| 167 | + name="root_agent", |
| 168 | + description="An agent designed to help with GitHub issues", |
| 169 | + instruction=""" |
| 170 | + Your job is to triage a GitHub issue. The tasks you should perform are: |
| 171 | + 1. Determine if an issue is spam using the is_spam agent. If it is spam, use the issue_write tool to update the issue state to "closed" and then you are done. |
| 172 | + 2. If it is not spam, hand off the issue to the LABELER tool (labeler_agent). When the LABELER tool is done, use the issue_write tool to update the issue with the suggested labels and add a label called 'Triaged by JulesBot'. |
| 173 | + 3. Use the issue_type_agent to determine the type of issue. If it is a support request or feature request, report back and you are done. |
| 174 | + 4. If you have not done so yet, use the issue_read tool to get the comments on the issue, to help inform the next steps |
| 175 | + 5. If it is a bug, use the complexity_scoping_agent to determine the complexity of the issue. |
| 176 | + 6. If it is a bug with complexity of less than 30, use the jules_agent to submit it to Jules. |
| 177 | + """, |
| 178 | + tools=[github_toolset, IS_SPAM, ISSUE_TYPE, COMPLEXITY_SCORE, LABELER], |
| 179 | + sub_agents=[jules_agent], |
| 180 | +) |
0 commit comments