forked from autogenhub/autogen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor abstractions (autogenhub#46)
- Loading branch information
1 parent
2bece0d
commit 65a262b
Showing
21 changed files
with
150 additions
and
74 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
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
2 changes: 1 addition & 1 deletion
2
samples/gh-flow/src/Microsoft.AI.DevTeam/Microsoft.AI.DevTeam.csproj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Microsoft.AI.Agents.Dapr; | ||
|
||
public class Agent | ||
{ | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
src/Microsoft.AI.Agents.Dapr/Microsoft.AI.Agents.Dapr.csproj
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,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Dapr.Actors" Version="1.13.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Microsoft.AI.Agents\Microsoft.AI.Agents.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
56 changes: 30 additions & 26 deletions
56
...Microsoft.AI.Agents/Abstractions/Agent.cs → src/Microsoft.AI.Agents.Orleans/Agent.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 |
---|---|---|
@@ -1,26 +1,30 @@ | ||
using Orleans.Runtime; | ||
using Orleans.Streams; | ||
|
||
namespace Microsoft.AI.Agents.Abstractions; | ||
|
||
public abstract class Agent : Grain, IGrainWithStringKey | ||
{ | ||
protected virtual string Namespace { get;set;} | ||
public abstract Task HandleEvent(Event item, StreamSequenceToken? token); | ||
protected async Task PublishEvent(string ns, string id, Event item) | ||
{ | ||
var streamProvider = this.GetStreamProvider("StreamProvider"); | ||
var streamId = StreamId.Create(ns, id); | ||
var stream = streamProvider.GetStream<Event>(streamId); | ||
await stream.OnNextAsync(item); | ||
} | ||
|
||
public async override Task OnActivateAsync(CancellationToken cancellationToken) | ||
{ | ||
var streamProvider = this.GetStreamProvider("StreamProvider"); | ||
var streamId = StreamId.Create(Namespace, this.GetPrimaryKeyString()); | ||
var stream = streamProvider.GetStream<Event>(streamId); | ||
|
||
await stream.SubscribeAsync(HandleEvent); | ||
} | ||
} | ||
using Microsoft.AI.Agents.Abstractions; | ||
using Orleans.Runtime; | ||
using Orleans.Streams; | ||
|
||
namespace Microsoft.AI.Agents.Orleans; | ||
|
||
public abstract class Agent : Grain, IGrainWithStringKey, IAgent | ||
{ | ||
protected virtual string Namespace { get;set;} | ||
public abstract Task HandleEvent(Event item); | ||
private async Task HandleEvent(Event item, StreamSequenceToken? token) | ||
{ | ||
await HandleEvent(item); | ||
} | ||
public async Task PublishEvent(string ns, string id, Event item) | ||
{ | ||
var streamProvider = this.GetStreamProvider("StreamProvider"); | ||
var streamId = StreamId.Create(ns, id); | ||
var stream = streamProvider.GetStream<Event>(streamId); | ||
await stream.OnNextAsync(item); | ||
} | ||
|
||
public async override Task OnActivateAsync(CancellationToken cancellationToken) | ||
{ | ||
var streamProvider = this.GetStreamProvider("StreamProvider"); | ||
var streamId = StreamId.Create(Namespace, this.GetPrimaryKeyString()); | ||
var stream = streamProvider.GetStream<Event>(streamId); | ||
await stream.SubscribeAsync(HandleEvent); | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/Microsoft.AI.Agents.Orleans/Microsoft.AI.Agents.Orleans.csproj
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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Orleans.Sdk" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Orleans.Streaming" Version="8.0.0" /> | ||
<ProjectReference Include="..\Microsoft.AI.Agents\Microsoft.AI.Agents.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,7 @@ | ||
namespace Microsoft.AI.Agents.Abstractions; | ||
|
||
public class AgentState<T> | ||
{ | ||
public List<ChatHistoryItem> History { get; set; } | ||
public T Data { 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,10 @@ | ||
namespace Microsoft.AI.Agents.Abstractions; | ||
|
||
[Serializable] | ||
public class ChatHistoryItem | ||
{ | ||
public string Message { get; set; } | ||
public ChatUserType UserType { get; set; } | ||
public int Order { 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,8 @@ | ||
namespace Microsoft.AI.Agents.Abstractions; | ||
|
||
public enum ChatUserType | ||
{ | ||
System, | ||
User, | ||
Agent | ||
} |
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 |
---|---|---|
@@ -1,13 +1,9 @@ | ||
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; } | ||
} | ||
} |
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,7 @@ | ||
namespace Microsoft.AI.Agents.Abstractions; | ||
|
||
public interface IAgent | ||
{ | ||
Task HandleEvent(Event item); | ||
Task PublishEvent(string ns, string id, Event item); | ||
} |
Oops, something went wrong.