1
1
import asyncio
2
2
import time
3
+ from typing import Dict , List , Optional , Any , Union
4
+
3
5
from azure .ai .agents .aio import AgentsClient
4
6
from azure .core .credentials import AzureKeyCredential
7
+
5
8
from ..config import AZURE_AI_PROJECT_CONNECTION_STRING , AZURE_AI_AGENTS_API_KEY
9
+ from ..constants import (
10
+ AGENT_ID_GITHUB_COPILOT_COMPLETIONS ,
11
+ AGENT_ID_GITHUB_COPILOT_AGENT ,
12
+ AGENT_ID_DEVIN ,
13
+ AGENT_ID_CODEX_CLI ,
14
+ AGENT_ID_SREAGENT ,
15
+ LEGACY_AGENT_ID_MAP ,
16
+ DEPENDENCY_FILES ,
17
+ LANGUAGE_MAP ,
18
+ )
19
+
6
20
7
21
class AzureAgentService :
8
- def __init__ (self ):
22
+ """Service for interacting with Azure AI Agents."""
23
+
24
+ def __init__ (self ) -> None :
25
+ """Initialize the Azure Agent Service with credentials."""
9
26
self .endpoint = AZURE_AI_PROJECT_CONNECTION_STRING
10
27
self .credential = None if not AZURE_AI_AGENTS_API_KEY or AZURE_AI_AGENTS_API_KEY == "your_api_key" else AzureKeyCredential (AZURE_AI_AGENTS_API_KEY )
11
28
12
- async def analyze_repository (self , agent_id : str , repo_name : str , readme_content : str , dependencies : dict ) :
29
+ async def analyze_repository (self , agent_id : str , repo_name : str , readme_content : str , dependencies : Dict [ str , str ]) -> str :
13
30
"""
14
31
Analyze a repository using Azure AI Agents.
15
32
@@ -82,21 +99,28 @@ async def analyze_repository(self, agent_id: str, repo_name: str, readme_content
82
99
except Exception as e :
83
100
return f"Error connecting to Azure AI Agents: { str (e )} \n \n Using mock data instead:\n \n { self ._generate_mock_analysis (agent_id , repo_name , readme_content , dependencies )} "
84
101
85
- def _generate_mock_analysis (self , agent_id : str , repo_name : str , readme_content : str , dependencies : dict ):
86
- """Generate mock analysis data for testing purposes."""
102
+ def _generate_mock_analysis (self , agent_id : str , repo_name : str , readme_content : str , dependencies : Dict [str , str ]) -> str :
103
+ """
104
+ Generate mock analysis data for testing purposes.
105
+
106
+ Args:
107
+ agent_id: The type of AI agent
108
+ repo_name: The repository name in owner/repo format
109
+ readme_content: The README content of the repository
110
+ dependencies: Dictionary of dependency files and their contents
111
+
112
+ Returns:
113
+ Mock analysis as a string
114
+ """
87
115
language = "JavaScript"
88
116
if dependencies :
89
- if "requirements.txt" in dependencies :
90
- language = "Python"
91
- elif "package.json" in dependencies :
92
- language = "JavaScript/TypeScript"
93
- elif "pom.xml" in dependencies :
94
- language = "Java"
95
- elif "build.gradle" in dependencies :
96
- language = "Java/Kotlin"
117
+ for dep_file , lang in LANGUAGE_MAP .items ():
118
+ if dep_file in dependencies :
119
+ language = lang
120
+ break
97
121
98
122
analyses = {
99
- 'github-copilot-completions' : f"""## GitHub Copilot (Code Completions) Analysis for { repo_name }
123
+ AGENT_ID_GITHUB_COPILOT_COMPLETIONS : f"""## GitHub Copilot (Code Completions) Analysis for { repo_name }
100
124
101
125
This repository is well-suited for GitHub Copilot code completions. Based on the codebase structure and { language } language, here's how to set up:
102
126
@@ -122,7 +146,7 @@ def _generate_mock_analysis(self, agent_id: str, repo_name: str, readme_content:
122
146
```
123
147
124
148
Enable GitHub Copilot in your editor settings and start coding with AI assistance!""" ,
125
- 'github-copilot-agent' : f"""## GitHub Copilot Coding Agent Analysis for { repo_name }
149
+ AGENT_ID_GITHUB_COPILOT_AGENT : f"""## GitHub Copilot Coding Agent Analysis for { repo_name }
126
150
127
151
This repository can benefit from GitHub Copilot Coding Agent for asynchronous, issue-driven automation. Here's how to set up:
128
152
@@ -142,7 +166,7 @@ def _generate_mock_analysis(self, agent_id: str, repo_name: str, readme_content:
142
166
```
143
167
144
168
Copilot Coding Agent works best with clear, well-scoped issues and access to your repository's context.""" ,
145
- 'devin' : f"""## Devin Configuration for { repo_name }
169
+ AGENT_ID_DEVIN : f"""## Devin Configuration for { repo_name }
146
170
147
171
This { language } repository can be effectively worked on using Devin. Here's the setup:
148
172
@@ -169,7 +193,7 @@ def _generate_mock_analysis(self, agent_id: str, repo_name: str, readme_content:
169
193
```
170
194
171
195
Devin works best with this repository by understanding the full context of files and dependencies.""" ,
172
- 'codex-cli' : f"""## Codex CLI Setup for { repo_name }
196
+ AGENT_ID_CODEX_CLI : f"""## Codex CLI Setup for { repo_name }
173
197
174
198
This guide will help you set up Codex CLI to work with this { language } repository.
175
199
@@ -206,7 +230,7 @@ def _generate_mock_analysis(self, agent_id: str, repo_name: str, readme_content:
206
230
- Use for documentation generation
207
231
208
232
This repository's structure is compatible with Codex CLI's code generation capabilities.""" ,
209
- 'sreagent' : f"""## SREAgent Configuration for { repo_name }
233
+ AGENT_ID_SREAGENT : f"""## SREAgent Configuration for { repo_name }
210
234
211
235
This guide will help you set up SREAgent for this { language } repository.
212
236
@@ -243,54 +267,59 @@ def _generate_mock_analysis(self, agent_id: str, repo_name: str, readme_content:
243
267
244
268
SREAgent can help maintain reliability for services deployed from this repository."""
245
269
}
270
+
246
271
# Support legacy IDs for backward compatibility
247
- legacy_map = {
248
- 'github-copilot' : 'github-copilot-completions' ,
249
- }
250
- lookup_id = legacy_map .get (agent_id , agent_id )
272
+ lookup_id = LEGACY_AGENT_ID_MAP .get (agent_id , agent_id )
251
273
return analyses .get (lookup_id , f"No specific analysis available for { agent_id } and { repo_name } . Please try another agent." )
252
274
253
- def _get_agent_instructions (self , agent_id : str ):
275
+ def _get_agent_instructions (self , agent_id : str ) -> str :
276
+ """
277
+ Get agent-specific instructions for analysis.
278
+
279
+ Args:
280
+ agent_id: The type of AI agent
281
+
282
+ Returns:
283
+ Instructions string for the agent
284
+ """
254
285
base_instructions = (
255
286
"You are an AI assistant that analyzes GitHub repositories and provides detailed setup "
256
287
"instructions for different AI agents. Your job is to analyze the repository README and "
257
288
"dependency files to understand the project structure and requirements."
258
289
)
259
290
agent_specific_instructions = {
260
- "github-copilot-completions" : (
291
+ AGENT_ID_GITHUB_COPILOT_COMPLETIONS : (
261
292
"Focus on how to set up GitHub Copilot (Code Completions) for this repository. Explain how to "
262
293
"install GitHub Copilot in VS Code, JetBrains, or other supported IDEs, how to "
263
294
"configure it for this specific project, and provide tips for getting the best "
264
295
"code suggestions based on this repository's structure and languages."
265
296
),
266
- "github-copilot-agent" : (
297
+ AGENT_ID_GITHUB_COPILOT_AGENT : (
267
298
"Focus on how to set up GitHub Copilot Coding Agent for this repository. Explain how to "
268
299
"assign issues to the agent, how it creates pull requests and runs CI/CD, and provide tips for "
269
300
"effective use based on this repository's structure and requirements."
270
301
),
271
- "devin" : (
302
+ AGENT_ID_DEVIN : (
272
303
"Focus on how to set up Devin for this repository. Explain how to access Devin "
273
304
"through Azure Marketplace, how to clone and configure this repository for Devin, "
274
305
"and provide tips for effective collaboration with Devin based on this repository's "
275
306
"structure and requirements."
276
307
),
277
- "codex-cli" : (
308
+ AGENT_ID_CODEX_CLI : (
278
309
"Focus on how to set up Codex CLI for this repository. Explain how to install "
279
310
"and configure Codex CLI with Azure OpenAI or OpenAI, how to use it effectively with this "
280
311
"repository, and provide example commands tailored to this repository's structure."
281
312
),
282
- "sreagent" : (
313
+ AGENT_ID_SREAGENT : (
283
314
"Focus on how to set up SREAgent for this repository. Explain how to configure "
284
315
"SREAgent in an Azure environment, how to connect it with this repository, "
285
316
"and recommend monitoring metrics and alert policies based on this repository's "
286
317
"structure and purpose."
287
318
)
288
319
}
320
+
289
321
# Support legacy IDs for backward compatibility
290
- legacy_map = {
291
- 'github-copilot' : 'github-copilot-completions' ,
292
- }
293
- lookup_id = legacy_map .get (agent_id , agent_id )
322
+ lookup_id = LEGACY_AGENT_ID_MAP .get (agent_id , agent_id )
294
323
if lookup_id in agent_specific_instructions :
295
324
return base_instructions + "\n \n " + agent_specific_instructions [lookup_id ]
296
325
return base_instructions
0 commit comments