|
24 | 24 | from adk_documentation.settings import DOC_REPO |
25 | 25 | from adk_documentation.tools import get_issue |
26 | 26 | from adk_documentation.utils import call_agent_async |
| 27 | +from adk_documentation.utils import parse_suggestions |
27 | 28 | from google.adk.cli.utils import logs |
28 | 29 | from google.adk.runners import InMemoryRunner |
29 | 30 |
|
30 | 31 | APP_NAME = "adk_docs_updater" |
31 | 32 | USER_ID = "adk_docs_updater_user" |
32 | 33 |
|
33 | | -logs.setup_adk_logger(level=logging.DEBUG) |
| 34 | +logs.setup_adk_logger(level=logging.INFO) |
34 | 35 |
|
35 | 36 |
|
36 | 37 | def process_arguments(): |
@@ -68,23 +69,84 @@ async def main(): |
68 | 69 | print(f"Failed to get issue {issue_number}: {get_issue_response}\n") |
69 | 70 | return |
70 | 71 | issue = get_issue_response["issue"] |
| 72 | + issue_title = issue.get("title", "") |
| 73 | + issue_body = issue.get("body", "") |
| 74 | + |
| 75 | + # Parse numbered suggestions from issue body |
| 76 | + suggestions = parse_suggestions(issue_body) |
| 77 | + |
| 78 | + if not suggestions: |
| 79 | + print(f"No numbered suggestions found in issue #{issue_number}.") |
| 80 | + print("Falling back to processing the entire issue as a single task.") |
| 81 | + suggestions = [(1, issue_body)] |
| 82 | + |
| 83 | + print(f"Found {len(suggestions)} suggestion(s) in issue #{issue_number}.") |
| 84 | + print("=" * 80) |
71 | 85 |
|
72 | 86 | runner = InMemoryRunner( |
73 | 87 | agent=agent.root_agent, |
74 | 88 | app_name=APP_NAME, |
75 | 89 | ) |
76 | | - session = await runner.session_service.create_session( |
77 | | - app_name=APP_NAME, |
78 | | - user_id=USER_ID, |
79 | | - ) |
80 | 90 |
|
81 | | - response = await call_agent_async( |
82 | | - runner, |
83 | | - USER_ID, |
84 | | - session.id, |
85 | | - f"Please update the ADK docs according to the following issue:\n{issue}", |
| 91 | + results = [] |
| 92 | + for suggestion_num, suggestion_text in suggestions: |
| 93 | + print(f"\n>>> Processing suggestion #{suggestion_num}...") |
| 94 | + print("-" * 80) |
| 95 | + |
| 96 | + # Create a new session for each suggestion to avoid context interference |
| 97 | + session = await runner.session_service.create_session( |
| 98 | + app_name=APP_NAME, |
| 99 | + user_id=USER_ID, |
| 100 | + ) |
| 101 | + |
| 102 | + prompt = f""" |
| 103 | + Please update the ADK docs according to suggestion #{suggestion_num} from issue #{issue_number}. |
| 104 | +
|
| 105 | + Issue title: {issue_title} |
| 106 | +
|
| 107 | + Suggestion to process: |
| 108 | + {suggestion_text} |
| 109 | +
|
| 110 | + Note: Focus only on this specific suggestion. Create exactly one pull request for this suggestion. |
| 111 | + """ |
| 112 | + |
| 113 | + try: |
| 114 | + response = await call_agent_async( |
| 115 | + runner, |
| 116 | + USER_ID, |
| 117 | + session.id, |
| 118 | + prompt, |
| 119 | + ) |
| 120 | + results.append({ |
| 121 | + "suggestion_num": suggestion_num, |
| 122 | + "status": "success", |
| 123 | + "response": response, |
| 124 | + }) |
| 125 | + print(f"<<<< Suggestion #{suggestion_num} completed.") |
| 126 | + except Exception as e: |
| 127 | + results.append({ |
| 128 | + "suggestion_num": suggestion_num, |
| 129 | + "status": "error", |
| 130 | + "error": str(e), |
| 131 | + }) |
| 132 | + print(f"<<<< Suggestion #{suggestion_num} failed: {e}") |
| 133 | + |
| 134 | + print("-" * 80) |
| 135 | + |
| 136 | + # Print summary |
| 137 | + print("\n" + "=" * 80) |
| 138 | + print("SUMMARY") |
| 139 | + print("=" * 80) |
| 140 | + successful = [r for r in results if r["status"] == "success"] |
| 141 | + failed = [r for r in results if r["status"] == "error"] |
| 142 | + print( |
| 143 | + f"Total: {len(results)}, Success: {len(successful)}, Failed:" |
| 144 | + f" {len(failed)}" |
86 | 145 | ) |
87 | | - print(f"<<<< Agent Final Output: {response}\n") |
| 146 | + if failed: |
| 147 | + print("\nFailed suggestions:") |
| 148 | + for r in failed: |
| 149 | + print(f" - Suggestion #{r['suggestion_num']}: {r['error']}") |
88 | 150 |
|
89 | 151 |
|
90 | 152 | if __name__ == "__main__": |
|
0 commit comments