Skip to content

A programming framework for agentic AI

deploy to azure with azd (#49)

Kosta Petan9168d115fd4c
diff --git a/samples/gh-flow/azure.yaml b/samples/gh-flow/azure.yaml
index b95e9a6e7..8553ba154 100644
--- a/samples/gh-flow/azure.yaml
+++ b/samples/gh-flow/azure.yaml
@@ -3,8 +3,8 @@
name: ai-dev-team
services:
gh-flow:
- project: "src/Microsoft.AI.DevTeam/Microsoft.AI.DevTeam.csproj"
+ project: "src/Microsoft.AI.DevTeam"
language: csharp
host: containerapp
docker:
- context: ../../../
+ context: ../../../../
diff --git a/samples/gh-flow/infra/app/gh-flow.bicep b/samples/gh-flow/infra/app/gh-flow.bicep
index ee5ca3265..a56274f08 100644
--- a/samples/gh-flow/infra/app/gh-flow.bicep
+++ b/samples/gh-flow/infra/app/gh-flow.bicep
@@ -46,6 +46,7 @@ resource cosmos 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' existing = {
}
var contributorRole = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')
+var wehbookSecret = uniqueString(resourceGroup().id)
resource rgContributor 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(subscription().id, resourceGroup().id, contributorRole)
@@ -89,6 +90,10 @@ module app '../core/host/container-app.bicep' = {
name: 'GithubOptions__InstallationId'
value: githubAppInstallationId
}
+ {
+ name: 'GithubOptions__WebhookSecret'
+ value: wehbookSecret
+ }
{
name: 'AzureOptions__SubscriptionId'
value: subscription().subscriptionId
@@ -162,3 +167,4 @@ module app '../core/host/container-app.bicep' = {
output SERVICE_TRANSLATE_API_IDENTITY_PRINCIPAL_ID string = app.outputs.identityPrincipalId
output SERVICE_TRANSLATE_API_NAME string = app.outputs.name
output SERVICE_TRANSLATE_API_URI string = app.outputs.uri
+output WEBHOOK_SECRET string = wehbookSecret
diff --git a/samples/gh-flow/infra/app/sk-func.bicep b/samples/gh-flow/infra/app/sk-func.bicep
deleted file mode 100644
index 54a374f60..000000000
--- a/samples/gh-flow/infra/app/sk-func.bicep
+++ /dev/null
@@ -1,45 +0,0 @@
-param name string
-param location string = resourceGroup().location
-param tags object = {}
-
-param allowedOrigins array = []
-param applicationInsightsName string = ''
-param appServicePlanId string
-@secure()
-param appSettings object = {}
-param serviceName string = 'sk-func'
-param storageAccountName string
-
-module api '../core/host/functions.bicep' = {
- name: '${serviceName}-functions-dotnet-isolated-module'
- params: {
- name: name
- location: location
- tags: union(tags, { 'azd-service-name': serviceName })
- allowedOrigins: allowedOrigins
- alwaysOn: false
- appSettings: appSettings
- applicationInsightsName: applicationInsightsName
- appServicePlanId: appServicePlanId
- runtimeName: 'dotnet-isolated'
- runtimeVersion: '7.0'
- storageAccountName: storageAccountName
- scmDoBuildDuringDeployment: false
- managedIdentity: true
- }
-}
-
-var contributorRole = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')
-
-resource rgContributor 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
- name: guid(subscription().id, resourceGroup().id, contributorRole)
- properties: {
- roleDefinitionId: contributorRole
- principalType: 'ServicePrincipal'
- principalId: api.outputs.identityPrincipalId
- }
-}
-
-output SERVICE_API_IDENTITY_PRINCIPAL_ID string = api.outputs.identityPrincipalId
-output SERVICE_API_NAME string = api.outputs.name
-output SERVICE_API_URI string = api.outputs.uri
diff --git a/samples/gh-flow/infra/main.bicep b/samples/gh-flow/infra/main.bicep
index 9dfbdac6c..331ac6595 100644
--- a/samples/gh-flow/infra/main.bicep
+++ b/samples/gh-flow/infra/main.bicep
@@ -9,6 +9,18 @@ param environmentName string
@description('Primary location for all resources')
param location string
+@secure()
+param githubAppKey string
+param githubAppId string
+param githubAppInstallationId string
+param openAIServiceType string
+param openAIServiceId string
+param openAIDeploymentId string
+param openAIEmbeddingId string
+param openAIEndpoint string
+@secure()
+param openAIKey string
+
param applicationInsightsDashboardName string = ''
param applicationInsightsName string = ''
param logAnalyticsName string = ''
@@ -16,6 +28,8 @@ param resourceGroupName string = ''
param storageAccountName string = ''
param containerAppsEnvironmentName string = ''
param containerRegistryName string = ''
+param ghFlowServiceName string = ''
+param cosmosAccountName string = ''
var aciShare = 'acishare'
@@ -85,6 +99,46 @@ module qdrant './core/database/qdrant/qdrant-aca.bicep' = {
}
}
+// The application database
+module cosmos './app/db.bicep' = {
+ name: 'cosmos'
+ scope: rg
+ params: {
+ accountName: !empty(cosmosAccountName) ? cosmosAccountName : '${abbrs.documentDBDatabaseAccounts}${resourceToken}'
+ databaseName: 'devteam'
+ location: location
+ tags: tags
+ }
+}
+
+module ghFlow './app/gh-flow.bicep' = {
+ name: 'gh-flow'
+ scope: rg
+ params: {
+ name: !empty(ghFlowServiceName) ? ghFlowServiceName : '${abbrs.appContainerApps}ghflow-${resourceToken}'
+ location: location
+ tags: tags
+ identityName: '${abbrs.managedIdentityUserAssignedIdentities}ghflow-${resourceToken}'
+ applicationInsightsName: monitoring.outputs.applicationInsightsName
+ containerAppsEnvironmentName: containerApps.outputs.environmentName
+ containerRegistryName:containerApps.outputs.registryName
+ storageAccountName: storage.outputs.name
+ aciShare: aciShare
+ githubAppId: githubAppId
+ githubAppInstallationId: githubAppInstallationId
+ githubAppKey: githubAppKey
+ openAIDeploymentId: openAIDeploymentId
+ openAIEmbeddingId: openAIEmbeddingId
+ openAIEndpoint: openAIEndpoint
+ openAIKey: openAIKey
+ openAIServiceId: openAIServiceId
+ openAIServiceType: openAIServiceType
+ qdrantEndpoint: 'https://${qdrant.outputs.fqdn}'
+ rgName: rg.name
+ cosmosAccountName: cosmos.outputs.accountName
+ }
+}
+
// App outputs
output APPLICATIONINSIGHTS_CONNECTION_STRING string = monitoring.outputs.applicationInsightsConnectionString
@@ -98,3 +152,9 @@ output AZURE_RESOURCE_GROUP_NAME string = rg.name
output AZURE_FILESHARE_NAME string = aciShare
output AZURE_FILESHARE_ACCOUNT_NAME string = storage.outputs.name
output QDRANT_ENDPOINT string = 'https://${qdrant.outputs.fqdn}'
+output WEBHOOK_SECRET string = ghFlow.outputs.WEBHOOK_SECRET
+
+// Data outputs
+output AZURE_COSMOS_ENDPOINT string = cosmos.outputs.endpoint
+output AZURE_COSMOS_CONNECTION_STRING_KEY string = cosmos.outputs.connectionStringKey
+output AZURE_COSMOS_DATABASE_NAME string = cosmos.outputs.databaseName
diff --git a/samples/gh-flow/infra/main.parameters.json b/samples/gh-flow/infra/main.parameters.json
index 67ad8524c..05edbfaae 100644
--- a/samples/gh-flow/infra/main.parameters.json
+++ b/samples/gh-flow/infra/main.parameters.json
@@ -8,6 +8,33 @@
"location": {
"value": "${AZURE_LOCATION}"
},
+ "githubAppKey": {
+ "value": "${GH_APP_KEY}"
+ },
+ "githubAppId": {
+ "value": "${GH_APP_ID}"
+ },
+ "githubAppInstallationId": {
+ "value": "${GH_APP_INST_ID}"
+ },
+ "openAIServiceType": {
+ "value": "${OAI_SERVICE_TYPE}"
+ },
+ "openAIServiceId": {
+ "value": "${OAI_SERVICE_ID}"
+ },
+ "openAIDeploymentId": {
+ "value": "${OAI_DEPLOYMENT_ID}"
+ },
+ "openAIEmbeddingId": {
+ "value": "${OAI_EMBEDDING_ID}"
+ },
+ "openAIEndpoint": {
+ "value": "${OAI_ENDPOINT}"
+ },
+ "openAIKey": {
+ "value": "${OAI_KEY}"
+ },
"principalId": {
"value": "${AZURE_PRINCIPAL_ID}"
}
diff --git a/samples/gh-flow/src/Microsoft.AI.DevTeam/Dockerfile b/samples/gh-flow/src/Microsoft.AI.DevTeam/Dockerfile
index 94041c3fa..094d15016 100644
--- a/samples/gh-flow/src/Microsoft.AI.DevTeam/Dockerfile
+++ b/samples/gh-flow/src/Microsoft.AI.DevTeam/Dockerfile
@@ -1,4 +1,4 @@
-FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
+FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 5274
EXPOSE 11111
@@ -6,18 +6,18 @@ EXPOSE 30000
ENV ASPNETCORE_URLS=http://+:5274
-FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
+FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG configuration=Release
COPY . .
-RUN dotnet restore "src/apps/gh-flow/gh-flow.csproj"
-WORKDIR "/src/apps/gh-flow"
-RUN dotnet build "gh-flow.csproj" -c $configuration -o /app/build
+RUN dotnet restore "samples/gh-flow/src/Microsoft.AI.DevTeam/Microsoft.AI.DevTeam.csproj"
+WORKDIR "samples/gh-flow/src/Microsoft.AI.DevTeam"
+RUN dotnet build "Microsoft.AI.DevTeam.csproj" -c $configuration -o /app/build
FROM build AS publish
ARG configuration=Release
-RUN dotnet publish "gh-flow.csproj" -c $configuration -o /app/publish
+RUN dotnet publish "Microsoft.AI.DevTeam.csproj" -c $configuration -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
-ENTRYPOINT ["dotnet", "gh-flow.dll"]
\ No newline at end of file
+ENTRYPOINT ["dotnet", "Microsoft.AI.DevTeam.dll"]
\ No newline at end of file
diff --git a/samples/gh-flow/src/Microsoft.AI.DevTeam/Microsoft.AI.DevTeam.csproj b/samples/gh-flow/src/Microsoft.AI.DevTeam/Microsoft.AI.DevTeam.csproj
index 221e828c1..ad621f5ad 100644
--- a/samples/gh-flow/src/Microsoft.AI.DevTeam/Microsoft.AI.DevTeam.csproj
+++ b/samples/gh-flow/src/Microsoft.AI.DevTeam/Microsoft.AI.DevTeam.csproj
@@ -44,6 +44,7 @@
<PackageReference Include="Azure.Identity" Version="1.11.0-beta.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.4.1" />
+ <PackageReference Include="Microsoft.Orleans.Serialization.NewtonsoftJson" Version="8.0.0" />
</ItemGroup>
diff --git a/samples/gh-flow/src/Microsoft.AI.DevTeam/Program.cs b/samples/gh-flow/src/Microsoft.AI.DevTeam/Program.cs
index 636fd316d..48becfcfe 100644
--- a/samples/gh-flow/src/Microsoft.AI.DevTeam/Program.cs
+++ b/samples/gh-flow/src/Microsoft.AI.DevTeam/Program.cs
@@ -12,7 +12,8 @@ using Microsoft.Extensions.Http.Resilience;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Connectors.Qdrant;
using Microsoft.SemanticKernel.Connectors.OpenAI;
-using System.Configuration;
+using Orleans.Configuration;
+using Orleans.Serialization;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<WebhookEventProcessor, GithubWebHookProcessor>();
@@ -85,13 +86,64 @@ builder.Services.AddSingleton<IAnalyzeCode, CodeAnalyzer>();
builder.Host.UseOrleans(siloBuilder =>
{
-
- siloBuilder.UseLocalhostClustering()
+ siloBuilder.UseDashboard(x => x.HostSelf = true);
+ siloBuilder.Services.AddSerializer( sb => {
+ sb.AddNewtonsoftJsonSerializer(isSupported: t => true);
+ });
+ if (builder.Environment.IsDevelopment())
+ {
+ siloBuilder.UseLocalhostClustering()
.AddMemoryStreams("StreamProvider")
.AddMemoryGrainStorage("PubSubStore")
.AddMemoryGrainStorage("messages");
- siloBuilder.UseInMemoryReminderService();
- siloBuilder.UseDashboard(x => x.HostSelf = true);
+ siloBuilder.UseInMemoryReminderService();
+ }
+ else
+ {
+ var cosmosDbconnectionString = builder.Configuration.GetValue<string>("AzureOptions:CosmosConnectionString");
+ siloBuilder.Configure<ClusterOptions>(options =>
+ {
+ options.ClusterId = "ai-dev-cluster";
+ options.ServiceId = "ai-dev-cluster";
+ });
+ siloBuilder.Configure<SiloMessagingOptions>(options =>
+ {
+ options.ResponseTimeout = TimeSpan.FromMinutes(3);
+ options.SystemResponseTimeout = TimeSpan.FromMinutes(3);
+ });
+ siloBuilder.Configure<ClientMessagingOptions>(options =>
+ {
+ options.ResponseTimeout = TimeSpan.FromMinutes(3);
+ });
+ siloBuilder.UseCosmosClustering( o =>
+ {
+ o.ConfigureCosmosClient(cosmosDbconnectionString);
+ o.ContainerName = "devteam";
+ o.DatabaseName = "clustering";
+ o.IsResourceCreationEnabled = true;
+ });
+
+ siloBuilder.UseCosmosReminderService( o =>
+ {
+ o.ConfigureCosmosClient(cosmosDbconnectionString);
+ o.ContainerName = "devteam";
+ o.DatabaseName = "reminders";
+ o.IsResourceCreationEnabled = true;
+ });
+ siloBuilder.AddCosmosGrainStorage(
+ name: "messages",
+ configureOptions: o =>
+ {
+ o.ConfigureCosmosClient(cosmosDbconnectionString);
+ o.ContainerName = "devteam";
+ o.DatabaseName = "persistence";
+ o.IsResourceCreationEnabled = true;
+ });
+ //TODO: replace with EventHub
+ siloBuilder
+ .AddMemoryStreams("StreamProvider")
+ .AddMemoryGrainStorage("PubSubStore");
+ }
});
diff --git a/samples/gh-flow/src/Microsoft.AI.DevTeam/Services/GithubService.cs b/samples/gh-flow/src/Microsoft.AI.DevTeam/Services/GithubService.cs
index d04af3b22..f8516075b 100644
--- a/samples/gh-flow/src/Microsoft.AI.DevTeam/Services/GithubService.cs
+++ b/samples/gh-flow/src/Microsoft.AI.DevTeam/Services/GithubService.cs
@@ -80,7 +80,8 @@ public class GithubService : IManageGithub
try
{
var ghRepo = await _ghClient.Repository.Get(org, repo);
- if (ghRepo.Size == 0)
+ var contents = await _ghClient.Repository.Content.GetAllContents(org, repo);
+ if (!contents.Any())
{
// Create a new file and commit it to the repository
var createChangeSet = await _ghClient.Repository.Content.CreateFile(
@@ -90,7 +91,6 @@ public class GithubService : IManageGithub
new CreateFileRequest("Initial commit", "# Readme")
);
}
-
await _ghClient.Git.Reference.CreateBranch(org, repo, branch, ghRepo.DefaultBranch);
}
catch (Exception ex)
diff --git a/samples/gh-flow/src/Microsoft.AI.DevTeam/appsettings.azure.template.json b/samples/gh-flow/src/Microsoft.AI.DevTeam/appsettings.azure.template.json
index 2fc698845..b0dd8a805 100644
--- a/samples/gh-flow/src/Microsoft.AI.DevTeam/appsettings.azure.template.json
+++ b/samples/gh-flow/src/Microsoft.AI.DevTeam/appsettings.azure.template.json
@@ -25,7 +25,8 @@
"FilesAccountName":"",
"FilesAccountKey":"",
"SandboxImage" : "mcr.microsoft.com/dotnet/sdk:7.0",
- "ManagedIdentity": ""
+ "ManagedIdentity": "",
+ "CosmosConnectionString":""
},
"OpenAIOptions" : {
"ServiceType":"AzureOpenAI",
diff --git a/src/Microsoft.AI.Agents/Abstractions/Event.cs b/src/Microsoft.AI.Agents/Abstractions/Event.cs
index 2e61b3689..467582e65 100644
--- a/src/Microsoft.AI.Agents/Abstractions/Event.cs
+++ b/src/Microsoft.AI.Agents/Abstractions/Event.cs
@@ -1,9 +1,13 @@
namespace Microsoft.AI.Agents.Abstractions
{
+ [GenerateSerializer]
public class Event
{
+ [Id(0)]
public string Message { get; set; }
+ [Id(1)]
public Dictionary<string, string> Data { get; set; }
+ [Id(2)]
public string Type { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AI.Agents/Microsoft.AI.Agents.csproj b/src/Microsoft.AI.Agents/Microsoft.AI.Agents.csproj
index 75b3ea7a4..80d7f3086 100644
--- a/src/Microsoft.AI.Agents/Microsoft.AI.Agents.csproj
+++ b/src/Microsoft.AI.Agents/Microsoft.AI.Agents.csproj
@@ -7,8 +7,8 @@
</PropertyGroup>
<ItemGroup>
-
<PackageReference Include="Microsoft.SemanticKernel" Version="1.6.2" />
+ <PackageReference Include="Microsoft.Orleans.Sdk" Version="8.0.0" />
</ItemGroup>
</Project>
\ No newline at end of file