-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
658d9d2
commit 9597c6a
Showing
23 changed files
with
453 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
samples/marketing/src/backend/Agents/ManufacturingManager/ManufacturingManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Marketing.Controller; | ||
using Marketing.Events; | ||
using Marketing.Options; | ||
using Microsoft.AI.Agents.Abstractions; | ||
using Microsoft.AI.Agents.Orleans; | ||
using Microsoft.Identity.Client; | ||
using Microsoft.SemanticKernel; | ||
using Microsoft.SemanticKernel.Memory; | ||
using Orleans.Runtime; | ||
using static System.Net.Mime.MediaTypeNames; | ||
|
||
namespace Marketing.Agents; | ||
|
||
[ImplicitStreamSubscription(Consts.OrleansNamespace)] | ||
public class ManufacturingManager : AiAgent<ManufacturingManagerState> | ||
{ | ||
protected override string Namespace => Consts.OrleansNamespace; | ||
|
||
private readonly ILogger<ManufacturingManager> _logger; | ||
|
||
public ManufacturingManager([PersistentState("state", "messages")] IPersistentState<AgentState<ManufacturingManagerState>> state, Kernel kernel, ISemanticTextMemory memory, ILogger<ManufacturingManager> logger) | ||
: base(state, memory, kernel) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public async override Task HandleEvent(Event item) | ||
{ | ||
switch (item.Type) | ||
{ | ||
case nameof(EventTypes.SalesForecast): | ||
string salesExpectations = item.Data["salesForecastMessage"]; | ||
_logger.LogInformation($"[{nameof(ManufacturingManager)}] Event {nameof(EventTypes.SalesForecast)}. Text: {salesExpectations}"); | ||
|
||
var context = new KernelArguments { ["input"] = AppendChatHistory(salesExpectations) }; | ||
string manufactureManagerAnswer = await CallFunction(ManufacturingManagerPrompt.ManufacturingCreateProductionForecast, context); | ||
|
||
SendManufactureForecastEvent(manufactureManagerAnswer, item.Data["SessionId"]); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
private async Task SendManufactureForecastEvent(string manufactureForecastMessage, string sessionId) | ||
{ | ||
await PublishEvent(Consts.OrleansNamespace, this.GetPrimaryKeyString(), new Event | ||
{ | ||
Type = nameof(EventTypes.ManufacturingForecast), | ||
Data = new Dictionary<string, string> { | ||
{ "SessionId", sessionId }, | ||
{ nameof(manufactureForecastMessage), manufactureForecastMessage}, | ||
} | ||
}); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
samples/marketing/src/backend/Agents/ManufacturingManager/ManufacturingManagerPrompt.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Marketing.Agents; | ||
|
||
public static class ManufacturingManagerPrompt | ||
{ | ||
public static string ManufacturingCreateProductionForecast = """ | ||
You manage a factory. A person from marketing is trying to build a marketing campain. | ||
The sales analyst have made a prediction on how many items are going to be sold due to a new marketing campaign | ||
You need to answer to the user if it is possible or not to produce what the analyst have estimated. | ||
Currently, we can increase production by 5000 only, so if the prediction is higher, please answer that it is not possible | ||
that they should contact the manufacturing lead for an exceptional plan. | ||
THE ANSWER IS TO THE END USER DIRECTLY | ||
--- | ||
SAles Forecast: {{$input}} | ||
--- | ||
"""; | ||
} |
8 changes: 8 additions & 0 deletions
8
samples/marketing/src/backend/Agents/ManufacturingManager/ManufacturingManagerState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Marketing.Agents; | ||
|
||
[GenerateSerializer] | ||
public class ManufacturingManagerState | ||
{ | ||
[Id(0)] | ||
public string Article { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Microsoft.AI.Agents.Abstractions; | ||
|
||
namespace Marketing.Agents | ||
{ | ||
public interface INotary : IGrainWithStringKey | ||
{ | ||
public Task<List<Event>> GetAllEvents(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Marketing.Agents; | ||
using Marketing.Events; | ||
using Marketing.Options; | ||
using Microsoft.AI.Agents.Abstractions; | ||
using Microsoft.AI.Agents.Orleans; | ||
using Microsoft.SemanticKernel; | ||
using Microsoft.SemanticKernel.Memory; | ||
using Microsoft.SemanticKernel.TextToImage; | ||
using Orleans.Runtime; | ||
|
||
namespace Marketing.Agents; | ||
|
||
[ImplicitStreamSubscription(Consts.OrleansNamespace)] | ||
public class Notary : AiAgent<NotaryState>, INotary | ||
{ | ||
protected override string Namespace => Consts.OrleansNamespace; | ||
|
||
private readonly ILogger<Notary> _logger; | ||
private readonly IConfiguration _configuration; | ||
|
||
public Notary([PersistentState("state", "messages")] IPersistentState<AgentState<NotaryState>> state, Kernel kernel, ISemanticTextMemory memory, ILogger<Notary> logger, IConfiguration configuration) | ||
: base(state, memory, kernel) | ||
{ | ||
_logger = logger; | ||
_configuration = configuration; | ||
} | ||
|
||
public async override Task HandleEvent(Event item) | ||
{ | ||
string lastMessage; | ||
|
||
if(_state.State.Data.AllEvents == null) | ||
{ | ||
_state.State.Data.AllEvents = new List<Event>(); | ||
} | ||
_state.State.Data.AllEvents.Add(item); | ||
} | ||
|
||
public Task<List<Event>> GetAllEvents() | ||
{ | ||
return Task.FromResult(_state.State.Data.AllEvents); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Microsoft.AI.Agents.Abstractions; | ||
|
||
namespace Marketing.Agents | ||
{ | ||
public class NotaryState | ||
{ | ||
public List<Event> AllEvents { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
samples/marketing/src/backend/Controller/EventsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Marketing.Agents; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Text.Json; | ||
|
||
namespace Marketing.Controller | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class EventsController : ControllerBase | ||
{ | ||
private readonly IClusterClient _client; | ||
|
||
public EventsController(IClusterClient client) | ||
{ | ||
_client = client; | ||
} | ||
|
||
[HttpGet("{id}")] | ||
// GET: EventsController | ||
public async Task<string> Get(string id) | ||
{ | ||
var grain = _client.GetGrain<INotary>(id); | ||
var allEvents = await grain.GetAllEvents(); | ||
return JsonSerializer.Serialize(allEvents); | ||
} | ||
} | ||
} |
Oops, something went wrong.