Skip to content

Commit f7aaf86

Browse files
committed
Fixed MAF version update
1 parent 206cd48 commit f7aaf86

File tree

16 files changed

+147
-284
lines changed

16 files changed

+147
-284
lines changed

KaleidoCode/src/AgentStack/AgentStack.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<ItemGroup>
4-
<PackageReference Include="Microsoft.Agents.AI.Declarative" Version="1.0.0-preview.260128.1" />
5-
<PackageReference Include="Microsoft.Agents.AI.Hosting.A2A.AspNetCore" Version="1.0.0-preview.260128.1" />
6-
<PackageReference Include="Microsoft.Agents.AI.Hosting.AGUI.AspNetCore" Version="1.0.0-preview.260128.1" />
7-
<PackageReference Include="Microsoft.Agents.AI.Hosting.OpenAI" Version="1.0.0-alpha.260128.1" />
8-
<PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="1.0.0-preview.260128.1" />
9-
<PackageReference Include="Microsoft.Agents.AI.DevUI" Version="1.0.0-preview.260128.1" />
10-
<PackageReference Include="Microsoft.SemanticKernel.Connectors.PgVector" Version="1.70.0-preview" />
11-
<PackageReference Include="OpenAI" Version="2.8.0" />
4+
<PackageReference Include="Microsoft.Agents.AI.Declarative" Version="1.0.0-rc4" />
5+
<PackageReference Include="Microsoft.Agents.AI.Hosting.A2A.AspNetCore" Version="1.0.0-preview.260311.1" />
6+
<PackageReference Include="Microsoft.Agents.AI.Hosting.AGUI.AspNetCore" Version="1.0.0-preview.260311.1" />
7+
<PackageReference Include="Microsoft.Agents.AI.Hosting.OpenAI" Version="1.0.0-alpha.260311.1" />
8+
<PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="1.0.0-rc4" />
9+
<PackageReference Include="Microsoft.Agents.AI.DevUI" Version="1.0.0-preview.260311.1" />
10+
<PackageReference Include="Microsoft.SemanticKernel.Connectors.PgVector" Version="1.73.0-preview" />
11+
<PackageReference Include="OpenAI" Version="2.9.1" />
1212
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.1.0" />
1313
</ItemGroup>
1414

KaleidoCode/src/AgentStack/Agents/StateStreamingAgent.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ protected override async IAsyncEnumerable<AgentResponseUpdate> RunCoreStreamingA
5252
}
5353
// Deserialize state snapshot from response
5454
var response = allUpdates.ToAgentResponse();
55-
if (response.TryDeserialize(_jsonSerializerOptions, out JsonElement stateSnapshot))
55+
var stateSnapshot = JsonSerializer.Deserialize<JsonElement>(response.Text, JsonSerializerOptions.Web);
56+
57+
if (stateSnapshot.ValueKind != JsonValueKind.Undefined)
5658
{
5759
byte[] stateBytes = JsonSerializer.SerializeToUtf8Bytes(
5860
stateSnapshot,

KaleidoCode/src/AgentStack/Api/Agent.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public static void UseAgentEndpoints(this IEndpointRouteBuilder app)
1919
agentGroup.MapPost("/session", Session).WithName("session");
2020
agentGroup.MapPost("/function", Function).WithName("function");
2121
agentGroup.MapPost("/approval", Approval).WithName("approval");
22-
agentGroup.MapPost("/approval2", Approval2).WithName("approval2");
2322
agentGroup.MapPost("/structured", Structured).WithName("structured");
2423
agentGroup.MapPost("/agent-tool", AgentToTool).WithName("agent-tool");
2524
agentGroup.MapPost("/history-storage", HistoryStorage).WithName("history-storage");
@@ -62,11 +61,6 @@ static IAsyncEnumerable<string> Approval([FromServices] AgentService agentServic
6261
return agentService.Approval(message, allowChangeState);
6362
}
6463

65-
static IAsyncEnumerable<string> Approval2([FromServices] AgentService agentService, string? conversation = null, bool allowChangeState = false)
66-
{
67-
return agentService.Approval2(conversation, allowChangeState);
68-
}
69-
7064
/// <summary>
7165
/// This example will not run successfully, regardless of whether an object or a list is used in CreateJsonSchema.
7266
/// The reason is that the stupid OpenAI requires JsonSchema to be an object, meaning GetLightsAsync cannot directly return a list;

KaleidoCode/src/AgentStack/ChatHistory/VectorChatHistoryProvider.cs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,65 @@ public enum ChatReducerTriggerEvent
88
BeforeMessageAdded, AfterMessagesRetrieval
99
}
1010

11+
public sealed class State
12+
{
13+
public State(string sessionDbKey)
14+
{
15+
this.SessionDbKey = sessionDbKey ?? throw new ArgumentNullException(nameof(sessionDbKey));
16+
}
17+
18+
public string SessionDbKey { get; }
19+
}
20+
1121
public sealed class VectorChatHistoryProvider : ChatHistoryProvider
1222
{
23+
private readonly ProviderSessionState<State> _sessionState;
24+
private IReadOnlyList<string>? _stateKeys;
1325
private readonly VectorStore _vectorStore;
1426
private readonly IChatReducer? _chatReducer;
1527
private readonly ChatReducerTriggerEvent _reducerTriggerEvent;
1628

1729
public VectorChatHistoryProvider(
1830
VectorStore vectorStore,
19-
JsonElement serializedStoreState,
20-
JsonSerializerOptions? jsonSerializerOptions = null)
21-
: this(vectorStore, serializedStoreState, jsonSerializerOptions, null, ChatReducerTriggerEvent.AfterMessagesRetrieval)
31+
Func<AgentSession?, State>? stateInitializer = null,
32+
string? stateKey = null)
33+
: this(vectorStore, stateInitializer, stateKey, null, ChatReducerTriggerEvent.AfterMessagesRetrieval)
2234
{
2335

2436
}
2537

2638
public VectorChatHistoryProvider(
2739
VectorStore vectorStore,
28-
JsonElement serializedStoreState,
29-
JsonSerializerOptions? jsonSerializerOptions = null,
40+
Func<AgentSession?, State>? stateInitializer = null,
41+
string? stateKey = null,
3042
IChatReducer? chatReducer = null,
3143
ChatReducerTriggerEvent reducerTriggerEvent = ChatReducerTriggerEvent.AfterMessagesRetrieval)
3244
{
3345
Console.WriteLine($"VectorStore: {vectorStore.GetType()}");
3446
_vectorStore = vectorStore ?? throw new ArgumentNullException(nameof(vectorStore));
3547
_chatReducer = chatReducer;
3648
_reducerTriggerEvent = reducerTriggerEvent;
37-
if (serializedStoreState.ValueKind is JsonValueKind.String)
38-
{
39-
SessionDbKey = serializedStoreState.Deserialize<string>();
40-
Console.WriteLine($"SessionDbKey: {SessionDbKey}");
41-
}
49+
this._sessionState = new ProviderSessionState<State>(
50+
stateInitializer ?? (_ => new State(Guid.NewGuid().ToString("N"))),
51+
stateKey ?? this.GetType().Name);
4252
}
4353

44-
public string? SessionDbKey { get; private set; }
54+
public string? SessionDbKey => _sessionState.StateKey;
4555

46-
public override async ValueTask InvokedAsync(InvokedContext context, CancellationToken cancellationToken = default)
56+
57+
protected override async ValueTask StoreChatHistoryAsync(InvokedContext context, CancellationToken cancellationToken = default)
4758
{
4859
if (context.InvokeException is not null)
4960
{
5061
return;
5162
}
5263

53-
var messages = context.RequestMessages.Concat(context.AIContextProviderMessages ?? []).Concat(context.ResponseMessages ?? []);
64+
var messages = context.RequestMessages.Concat(context.RequestMessages ?? []).Concat(context.ResponseMessages ?? []);
5465
if (_reducerTriggerEvent is ChatReducerTriggerEvent.BeforeMessageAdded && _chatReducer is not null)
5566
{
5667
messages = await _chatReducer.ReduceAsync(messages, cancellationToken).ConfigureAwait(false);
5768
}
5869

59-
SessionDbKey ??= Guid.NewGuid().ToString("N");
6070
var collection = _vectorStore.GetCollection<string, ChatHistoryItem>("agent_chat_history");
6171
await collection.EnsureCollectionExistsAsync(cancellationToken);
6272
await collection.UpsertAsync(messages.Select(x => new ChatHistoryItem()
@@ -69,7 +79,7 @@ public override async ValueTask InvokedAsync(InvokedContext context, Cancellatio
6979
}), cancellationToken);
7080
}
7181

72-
public override async ValueTask<IEnumerable<ChatMessage>> InvokingAsync(InvokingContext context, CancellationToken cancellationToken = default)
82+
protected override async ValueTask<IEnumerable<ChatMessage>> ProvideChatHistoryAsync(InvokingContext context, CancellationToken cancellationToken = default)
7383
{
7484
var collection = _vectorStore.GetCollection<string, ChatHistoryItem>("agent_chat_history");
7585
await collection.EnsureCollectionExistsAsync(cancellationToken);
@@ -94,10 +104,6 @@ public override async ValueTask<IEnumerable<ChatMessage>> InvokingAsync(Invoking
94104
return messages;
95105
}
96106

97-
public override JsonElement Serialize(JsonSerializerOptions? jsonSerializerOptions = null) =>
98-
// We have to serialize the session id, so that on deserialization you can retrieve the messages using the same session id.
99-
JsonSerializer.SerializeToElement(SessionDbKey);
100-
101107
private sealed class ChatHistoryItem
102108
{
103109
[VectorStoreKey]

KaleidoCode/src/AgentStack/ContextProvider/AIContextProviderFactory.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,23 @@ public AIContextProviderFactory(IHttpContextAccessor httpContextAccessor,
1515
_vectorStore = vectorStore;
1616
}
1717

18-
public ValueTask<AIContextProvider> Create(ChatClientAgentOptions.AIContextProviderFactoryContext ctx, CancellationToken ct)
18+
public AIContextProvider Create(CancellationToken ct)
1919
{
2020
var httpContext = _httpContextAccessor.HttpContext;
2121
var request = httpContext?.Request;
2222
var SessionId = request?.Headers != null ? request?.Headers["SessionId"].FirstOrDefault() : "";
2323
var userId = request?.Headers != null ? request?.Headers["UserId"].FirstOrDefault() : "";
2424

2525
Console.WriteLine($"userId: {userId}, sessionId: {SessionId}");
26-
return ValueTask.FromResult<AIContextProvider>(new ChatHistoryMemoryProvider(
26+
27+
return new ChatHistoryMemoryProvider(
2728
_vectorStore,
2829
collectionName: "chathistory_memory",
2930
vectorDimensions: 1536,
30-
storageScope: new() { UserId = userId, SessionId = SessionId },
31-
searchScope: new() { UserId = userId }));
31+
stateInitializer: (session) =>
32+
new ChatHistoryMemoryProvider.State(
33+
storageScope: new() { UserId = userId, SessionId = SessionId },
34+
searchScope: new() { UserId = userId })
35+
);
3236
}
3337
}

KaleidoCode/src/AgentStack/ContextProvider/AggregatingAIContextProvider.cs

Lines changed: 0 additions & 67 deletions
This file was deleted.

KaleidoCode/src/AgentStack/Executor/CriticExecutor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public override async ValueTask<CriticDecision> HandleAsync(
4343

4444
// Convert the stream to a response and deserialize the structured output
4545
AgentResponse response = await updates.ToAgentResponseAsync(cancellationToken);
46-
CriticDecision decision = response.Deserialize<CriticDecision>(JsonSerializerOptions.Web);
46+
CriticDecision decision = JsonSerializer.Deserialize<CriticDecision>(response.Text, JsonSerializerOptions.Web)
47+
?? throw new JsonException("Failed to deserialize CriticDecision from response text.");
4748

4849
// Safety: approve if max iterations reached
4950
if (!decision.Approved && state.Iteration >= _maxIterations)

KaleidoCode/src/AgentStack/Executor/WriterExecutor.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ Maintain the same topic and length requirements.
2020
);
2121
}
2222

23-
protected override Workflows.RouteBuilder ConfigureRoutes(Workflows.RouteBuilder routeBuilder) =>
24-
routeBuilder
25-
.AddHandler<string, ChatMessage>(HandleInitialRequestAsync)
26-
.AddHandler<CriticDecision, ChatMessage>(HandleRevisionRequestAsync);
2723

2824
/// <summary>
2925
/// Handles the initial writing request from the user.
@@ -76,6 +72,17 @@ private async Task<ChatMessage> HandleAsyncCoreAsync(
7672

7773
return new ChatMessage(ChatRole.User, text);
7874
}
75+
76+
protected override ProtocolBuilder ConfigureProtocol(ProtocolBuilder protocolBuilder)
77+
{
78+
return protocolBuilder.ConfigureRoutes(ConfigureRoutes);
79+
80+
void ConfigureRoutes(Workflows.RouteBuilder routeBuilder)
81+
{
82+
routeBuilder.AddHandler<string, ChatMessage>(HandleInitialRequestAsync)
83+
.AddHandler<CriticDecision, ChatMessage>(HandleRevisionRequestAsync);
84+
}
85+
}
7986
}
8087

8188
[Description("Critic's review decision including approval status and feedback")]

0 commit comments

Comments
 (0)