Skip to content

A programming framework for agentic AI

rewrite event based orchestration

Kosta Petan5f67942126f8
diff --git a/src/apps/gh-flow/Program.cs b/src/apps/gh-flow/Program.cs
index 5118598e7..ea154c051 100644
--- a/src/apps/gh-flow/Program.cs
+++ b/src/apps/gh-flow/Program.cs
@@ -67,6 +67,7 @@ builder.Host.UseOrleans(siloBuilder =>
if (builder.Environment.IsDevelopment())
{
var connectionString = builder.Configuration.GetValue<string>("AzureOptions:CosmosConnectionString");
+ siloBuilder.AddMemoryStreams("StreamProvider");
siloBuilder.UseCosmosReminderService( o =>
{
o.ConfigureCosmosClient(connectionString);
@@ -126,6 +127,8 @@ builder.Host.UseOrleans(siloBuilder =>
o.DatabaseName = "persistence";
o.IsResourceCreationEnabled = true;
});
+
+ //TODO: Add streaming here
}
});
diff --git a/src/apps/gh-flow/Services/GithubWebHookProcessor.cs b/src/apps/gh-flow/Services/GithubWebHookProcessor.cs
index d223dc380..cdd757df0 100644
--- a/src/apps/gh-flow/Services/GithubWebHookProcessor.cs
+++ b/src/apps/gh-flow/Services/GithubWebHookProcessor.cs
@@ -6,18 +6,22 @@ using Octokit.Webhooks.Events.CommitComment;
using Octokit.Webhooks.Events.IssueComment;
using Octokit.Webhooks.Events.Issues;
using Octokit.Webhooks.Models;
+using Orleans.Runtime;
public sealed class GithubWebHookProcessor : WebhookEventProcessor
{
private readonly ILogger<GithubWebHookProcessor> _logger;
private readonly IGrainFactory _grains;
+ private readonly IClusterClient client;
private readonly IManageGithub _ghService;
private readonly IManageAzure _azService;
- public GithubWebHookProcessor(ILogger<GithubWebHookProcessor> logger, IGrainFactory grains, IManageGithub ghService, IManageAzure azService)
+ public GithubWebHookProcessor(ILogger<GithubWebHookProcessor> logger, IGrainFactory grains,
+ IClusterClient client, IManageGithub ghService, IManageAzure azService)
{
_logger = logger;
_grains = grains;
+ this.client = client;
_ghService = ghService;
_azService = azService;
}
@@ -196,6 +200,17 @@ public sealed class GithubWebHookProcessor : WebhookEventProcessor
{
var conductor = _grains.GetGrain<IOrchestrateWorkflows>(issueNumber, suffix);
await conductor.InitialFlow(input, org, repo, issueNumber);
+ var streamProvider = client.GetStreamProvider("StreamProvider");
+
+ var streamId = StreamId.Create(suffix, issueNumber.ToString());
+ var stream = streamProvider.GetStream<Event>(streamId);
+ await stream.OnNextAsync(new Event{
+ Type = EventType.NewAsk,
+ Message = input,
+ Org = org,
+ Repo = repo,
+ IssueNumber = issueNumber
+ });
}
else if (skillName == "Repo" && functionName == "Ingest")
{
@@ -241,4 +256,5 @@ public sealed class GithubWebHookProcessor : WebhookEventProcessor
}
else { }// something went wrong
}
-}
\ No newline at end of file
+}
+
diff --git a/src/libs/Microsoft.AI.DevTeam/Actors/Architect/Architect.cs b/src/libs/Microsoft.AI.DevTeam/Actors/Architect/Architect.cs
index 24a421e90..94c06195e 100644
--- a/src/libs/Microsoft.AI.DevTeam/Actors/Architect/Architect.cs
+++ b/src/libs/Microsoft.AI.DevTeam/Actors/Architect/Architect.cs
@@ -1,4 +1,5 @@
using Orleans.Runtime;
+using Orleans.Streams;
namespace Microsoft.AI.DevTeam;
@@ -17,6 +18,16 @@ public class Architect : SemanticPersona, IArchitectSolutions
{
throw new NotImplementedException();
}
+ public async override Task HandleEvent(Event item, StreamSequenceToken? token)
+ {
+ switch (item.Type)
+ {
+ case EventType.NewAsk:
+ break;
+ default:
+ break;
+ }
+ }
}
public interface IArchitectSolutions : IGrainWithIntegerCompoundKey
diff --git a/src/libs/Microsoft.AI.DevTeam/Actors/Conductor/Conductor.cs b/src/libs/Microsoft.AI.DevTeam/Actors/Conductor/Conductor.cs
index 51c05b88d..19851a4f7 100644
--- a/src/libs/Microsoft.AI.DevTeam/Actors/Conductor/Conductor.cs
+++ b/src/libs/Microsoft.AI.DevTeam/Actors/Conductor/Conductor.cs
@@ -1,16 +1,18 @@
using Microsoft.AI.DevTeam.Skills;
-using Orleans.Concurrency;
using Orleans.Runtime;
+using Orleans.Streams;
namespace Microsoft.AI.DevTeam;
public class Conductor : Grain, IOrchestrateWorkflows
{
private readonly IManageGithub _ghService;
+
public Conductor( IManageGithub ghService)
{
_ghService = ghService;
}
+
public async Task InitialFlow(string input, string org, string repo, long parentNumber)
{
await _ghService.CreateBranch(new CreateBranchRequest
@@ -80,3 +82,38 @@ public class Conductor : Grain, IOrchestrateWorkflows
await lookup.StoreMetadata(metadataList);
}
}
+
+/*
+Events:
+
+NewAsk - Org, Repo, IssueNumber
+
+-> PM subscribes -> check label,
+ if Do It, create an issue, mark it as PM.Readme
+ if PM.Readme send the prompt and create a comment
+-> DevLead subscribes -> check label,
+ if Do It, create an issue, mark it as Devlead.Plan
+ if DevLead.Plan, send the prompt and create a comment
+-> Developer subscribes -> check label,
+ if Developer.Implement, send the prompt and create a comment
+
+ChainClosed - Org, Repo, IssueNumber
+
+-> PM subscribes -> check label,
+ if PM.Readme send ReadmeCreated event
+-> DevLead subscribes -> check label,
+ if DevLead.Plan, send PlanSubstepCreated event
+
+-> Developer subscribes -> check label,
+ if Developer.Implement, send ImplementSubstepCreated event
+
+PlanSubstepCreated - Org, Repo, IssueNumber, Substep
+
+-> Developer subscribes -> create an issue, mark it as Developer.Implement
+
+
+ReadmeCreated - store readme, commit to PR branch
+
+ImplementSubstepCreated - store code, run in sandbox, commit to PR branch
+
+*/
\ No newline at end of file
diff --git a/src/libs/Microsoft.AI.DevTeam/Actors/DevLead/DeveloperLead.cs b/src/libs/Microsoft.AI.DevTeam/Actors/DevLead/DeveloperLead.cs
index bad46c0bb..978268c2f 100644
--- a/src/libs/Microsoft.AI.DevTeam/Actors/DevLead/DeveloperLead.cs
+++ b/src/libs/Microsoft.AI.DevTeam/Actors/DevLead/DeveloperLead.cs
@@ -5,6 +5,7 @@ using Microsoft.SemanticKernel.Connectors.AI.OpenAI;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Orchestration;
using Orleans.Runtime;
+using Orleans.Streams;
using System.Text.Json;
namespace Microsoft.AI.DevTeam;
@@ -64,6 +65,17 @@ public class DeveloperLead : SemanticPersona, ILeadDevelopment
var response = JsonSerializer.Deserialize<DevLeadPlanResponse>(plan);
return Task.FromResult(response);
}
+
+ public async override Task HandleEvent(Event item, StreamSequenceToken? token)
+ {
+ switch (item.Type)
+ {
+ case EventType.NewAsk:
+ break;
+ default:
+ break;
+ }
+ }
}
[GenerateSerializer]
diff --git a/src/libs/Microsoft.AI.DevTeam/Actors/Developer/Developer.cs b/src/libs/Microsoft.AI.DevTeam/Actors/Developer/Developer.cs
index b54a60476..0287f92f7 100644
--- a/src/libs/Microsoft.AI.DevTeam/Actors/Developer/Developer.cs
+++ b/src/libs/Microsoft.AI.DevTeam/Actors/Developer/Developer.cs
@@ -5,6 +5,7 @@ using Microsoft.SemanticKernel.Connectors.AI.OpenAI;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Orchestration;
using Orleans.Runtime;
+using Orleans.Streams;
namespace Microsoft.AI.DevTeam;
@@ -58,6 +59,16 @@ public class Dev : SemanticPersona, IDevelopCode
}
}
+ public async override Task HandleEvent(Event item, StreamSequenceToken? token)
+ {
+ switch (item.Type)
+ {
+ case EventType.NewAsk:
+ break;
+ default:
+ break;
+ }
+ }
public Task<string> ReviewPlan(string plan)
diff --git a/src/libs/Microsoft.AI.DevTeam/Actors/Ingester/Ingester.cs b/src/libs/Microsoft.AI.DevTeam/Actors/Ingester/Ingester.cs
index 74faa6be4..3537eaf42 100644
--- a/src/libs/Microsoft.AI.DevTeam/Actors/Ingester/Ingester.cs
+++ b/src/libs/Microsoft.AI.DevTeam/Actors/Ingester/Ingester.cs
@@ -2,6 +2,7 @@ using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Memory;
using Octokit;
using Orleans.Runtime;
+using Orleans.Streams;
namespace Microsoft.AI.DevTeam;
@@ -38,6 +39,11 @@ public class Ingester : SemanticPersona, IIngestRepo
await dev.BuildUnderstanding(file.Content);
}
}
+
+ public override Task HandleEvent(Event item, StreamSequenceToken? token)
+ {
+ throw new NotImplementedException();
+ }
}
public static class Language
diff --git a/src/libs/Microsoft.AI.DevTeam/Actors/ProductManager/ProductManager.cs b/src/libs/Microsoft.AI.DevTeam/Actors/ProductManager/ProductManager.cs
index 231f24351..497a7385e 100644
--- a/src/libs/Microsoft.AI.DevTeam/Actors/ProductManager/ProductManager.cs
+++ b/src/libs/Microsoft.AI.DevTeam/Actors/ProductManager/ProductManager.cs
@@ -5,6 +5,7 @@ using Microsoft.SemanticKernel.Connectors.AI.OpenAI;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Orchestration;
using Orleans.Runtime;
+using Orleans.Streams;
namespace Microsoft.AI.DevTeam;
public class ProductManager : SemanticPersona, IManageProduct
@@ -55,4 +56,15 @@ public class ProductManager : SemanticPersona, IManageProduct
return default;
}
}
+
+ public async override Task HandleEvent(Event item, StreamSequenceToken? token)
+ {
+ switch (item.Type)
+ {
+ case EventType.NewAsk:
+ break;
+ default:
+ break;
+ }
+ }
}
diff --git a/src/libs/Microsoft.AI.DevTeam/Actors/SemanticPersona.cs b/src/libs/Microsoft.AI.DevTeam/Actors/SemanticPersona.cs
index 340e06798..cf82c526f 100644
--- a/src/libs/Microsoft.AI.DevTeam/Actors/SemanticPersona.cs
+++ b/src/libs/Microsoft.AI.DevTeam/Actors/SemanticPersona.cs
@@ -2,6 +2,7 @@ using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Orchestration;
using Orleans.Runtime;
+using Orleans.Streams;
namespace Microsoft.AI.DevTeam;
@@ -16,6 +17,8 @@ public abstract class SemanticPersona : Grain, IChatHistory
protected List<ChatHistoryItem> History { get; set; }
protected readonly IPersistentState<SemanticPersonaState> _state;
+ public abstract Task HandleEvent(Event item, StreamSequenceToken? token);
+
public async Task<string> GetLastMessage()
{
return _state.State.History.Last().Message;
@@ -32,6 +35,24 @@ public abstract class SemanticPersona : Grain, IChatHistory
context.Set("wafContext", wafContext);
}
+
+ public async override Task OnActivateAsync(CancellationToken cancellationToken)
+ {
+ var streamProvider = this.GetStreamProvider("");
+ var streamId = StreamId.Create("MyStreamNamespace", this.GetPrimaryKey());
+ var stream = streamProvider.GetStream<Event>(streamId);
+
+ var subscriptionHandles = await stream.GetAllSubscriptionHandles();
+ if ( subscriptionHandles != null && subscriptionHandles.Count > 0)
+ {
+ subscriptionHandles.ToList().ForEach(
+ async x => await x.ResumeAsync(HandleEvent));
+ }
+ else
+ {
+ await stream.SubscribeAsync(HandleEvent);
+ }
+ }
}
public interface IChatHistory
diff --git a/src/libs/Microsoft.AI.DevTeam/Actors/Tester/Tester.cs b/src/libs/Microsoft.AI.DevTeam/Actors/Tester/Tester.cs
index cb9fcad2a..bf89f3a2a 100644
--- a/src/libs/Microsoft.AI.DevTeam/Actors/Tester/Tester.cs
+++ b/src/libs/Microsoft.AI.DevTeam/Actors/Tester/Tester.cs
@@ -1,4 +1,5 @@
using Orleans.Runtime;
+using Orleans.Streams;
namespace Microsoft.AI.DevTeam;
@@ -9,6 +10,12 @@ public class Tester : SemanticPersona, ITestCode
{
}
+
+ public override Task HandleEvent(Event item, StreamSequenceToken? token)
+ {
+ throw new NotImplementedException();
+ }
+
public Task<string> ReviewPlan(string plan)
{
throw new NotImplementedException();
diff --git a/src/libs/Microsoft.AI.DevTeam/Events/Event.cs b/src/libs/Microsoft.AI.DevTeam/Events/Event.cs
new file mode 100644
index 000000000..3e6bcbcd9
--- /dev/null
+++ b/src/libs/Microsoft.AI.DevTeam/Events/Event.cs
@@ -0,0 +1,17 @@
+public class Event
+{
+ public EventType Type { get; set; }
+ public string Message { get; set; }
+ public string Org { get; set; }
+ public string Repo { get; set; }
+ public long IssueNumber { get; set; }
+}
+
+public enum EventType
+{
+ NewAsk,
+ ChainClosed,
+ ReadmeCreated,
+ PlanSubstemCreated,
+ CodeCreated
+}
\ No newline at end of file
diff --git a/src/libs/Microsoft.AI.DevTeam/Microsoft.AI.DevTeam.csproj b/src/libs/Microsoft.AI.DevTeam/Microsoft.AI.DevTeam.csproj
index 4e767065d..be95cfbdb 100644
--- a/src/libs/Microsoft.AI.DevTeam/Microsoft.AI.DevTeam.csproj
+++ b/src/libs/Microsoft.AI.DevTeam/Microsoft.AI.DevTeam.csproj
@@ -18,6 +18,7 @@
<PackageReference Include="Azure.Data.Tables" Version="12.8.1" />
<PackageReference Include="Azure.Identity" Version="1.10.0-beta.1" />
<PackageReference Include="Microsoft.Orleans.Reminders" Version="7.2.1" />
+ <PackageReference Include="Microsoft.Orleans.Streaming" Version="7.2.1" />
</ItemGroup>
<ItemGroup>