Skip to content

Commit a9b99d4

Browse files
alliscodeBen Thomas
andauthored
.Net: Fixing some issues with streaming invoke, obsoleting old invoke metho… (#11218)
Fixing some issues with streaming invoke, obsoleting old invoke methods, and updating samples ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄 --------- Co-authored-by: Ben Thomas <bentho@microsoft.com>
1 parent e1c4879 commit a9b99d4

11 files changed

Lines changed: 477 additions & 129 deletions

File tree

dotnet/samples/GettingStartedWithAgents/BedrockAgent/Step04_BedrockAgent_Trace.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
using System.ComponentModel;
44
using Amazon.BedrockAgentRuntime.Model;
55
using Microsoft.SemanticKernel;
6+
using Microsoft.SemanticKernel.Agents;
67
using Microsoft.SemanticKernel.Agents.Bedrock;
8+
using Microsoft.SemanticKernel.ChatCompletion;
79

810
namespace GettingStarted.BedrockAgents;
911

@@ -27,19 +29,14 @@ public async Task UseAgentWithTraceAsync()
2729
var userQuery = "What is the current weather in Seattle and what is the weather forecast in Seattle?";
2830
try
2931
{
30-
// Customize the request for advanced scenarios
31-
InvokeAgentRequest invokeAgentRequest = new()
32+
AgentThread agentThread = new BedrockAgentThread(this.RuntimeClient);
33+
BedrockAgentInvokeOptions options = new()
3234
{
33-
AgentAliasId = BedrockAgent.WorkingDraftAgentAlias,
34-
AgentId = bedrockAgent.Id,
35-
SessionId = BedrockAgent.CreateSessionId(),
36-
InputText = userQuery,
37-
// Enable trace to inspect the agent's thought process
3835
EnableTrace = true,
3936
};
4037

41-
var responses = bedrockAgent.InvokeAsync(invokeAgentRequest, null);
42-
await foreach (var response in responses)
38+
var responses = bedrockAgent.InvokeAsync([new ChatMessageContent(AuthorRole.User, userQuery)], agentThread, options);
39+
await foreach (ChatMessageContent response in responses)
4340
{
4441
if (response.Content != null)
4542
{

dotnet/samples/GettingStartedWithAgents/BedrockAgent/Step05_BedrockAgent_FileSearch.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

3-
using Amazon.BedrockAgentRuntime.Model;
3+
using Microsoft.SemanticKernel;
4+
using Microsoft.SemanticKernel.Agents;
45
using Microsoft.SemanticKernel.Agents.Bedrock;
6+
using Microsoft.SemanticKernel.ChatCompletion;
57

68
namespace GettingStarted.BedrockAgents;
79

@@ -48,17 +50,9 @@ public async Task UseAgentWithFileSearchAsync()
4850
var userQuery = "What is Semantic Kernel?";
4951
try
5052
{
51-
// Customize the request for advanced scenarios
52-
InvokeAgentRequest invokeAgentRequest = new()
53-
{
54-
AgentAliasId = BedrockAgent.WorkingDraftAgentAlias,
55-
AgentId = bedrockAgent.Id,
56-
SessionId = BedrockAgent.CreateSessionId(),
57-
InputText = userQuery,
58-
};
59-
60-
var responses = bedrockAgent.InvokeAsync(invokeAgentRequest, null, CancellationToken.None);
61-
await foreach (var response in responses)
53+
AgentThread bedrockThread = new BedrockAgentThread(this.RuntimeClient);
54+
var responses = bedrockAgent.InvokeAsync(new ChatMessageContent(AuthorRole.User, userQuery), bedrockThread, null, CancellationToken.None);
55+
await foreach (ChatMessageContent response in responses)
6256
{
6357
if (response.Content != null)
6458
{
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,54 @@
11
{
2-
"$type": "Process",
32
"stepsState": {
43
"FriedFishWithStatefulStepsProcess": {
54
"$type": "Process",
65
"stepsState": {
76
"GatherFriedFishIngredientsWithStockStep": {
87
"$type": "Step",
9-
"id": "2908f8c88cf0476a8e0075c3a8020d5d",
8+
"id": "7d4c02d000a744f490f2b5f9bad721fb",
109
"name": "GatherFriedFishIngredientsWithStockStep",
1110
"versionInfo": "GatherFishIngredient.V2",
1211
"state": {
13-
"IngredientsStock": 3
12+
"IngredientsStock": 2
1413
}
1514
},
1615
"CutFoodStep": {
1716
"$type": "Step",
18-
"id": "014388cf0bbd41119b8730dfc4b0b459",
17+
"id": "f147010a57d34587a3dc1ed4677e5163",
1918
"name": "CutFoodStep",
2019
"versionInfo": "CutFoodStep.V1"
2120
},
2221
"FryFoodStep": {
2322
"$type": "Step",
24-
"id": "c55af0425d864c4e97b6ae67bd715480",
23+
"id": "78cc5af4106549afb74d7a6813016f87",
2524
"name": "FryFoodStep",
2625
"versionInfo": "FryFoodStep.V1"
2726
}
2827
},
29-
"id": "cab89a17aeae4b9a97568967dbf1ea47",
28+
"id": "282717158b9f49e5b1acce81429610e0",
3029
"name": "FriedFishWithStatefulStepsProcess",
3130
"versionInfo": "FriedFishProcess.v1"
3231
},
3332
"AddBunsStep": {
3433
"$type": "Step",
35-
"id": "35d09b83dea24ddf8e0c24fbe6a3746c",
34+
"id": "31e953154e574470911d168a39588ed8",
3635
"name": "AddBunsStep",
3736
"versionInfo": "v1"
3837
},
3938
"AddSpecialSauceStep": {
4039
"$type": "Step",
41-
"id": "aa0d408976574afea94387e3da7ca111",
40+
"id": "67ee29ff28e4446d8046417675ec21e8",
4241
"name": "AddSpecialSauceStep",
4342
"versionInfo": "v1"
4443
},
4544
"ExternalFriedFishStep": {
4645
"$type": "Step",
47-
"id": "2eda38b8ee8745a4ab8b21f4fa01d173",
46+
"id": "873b1c8dee45412e975a5e8db2ed0b43",
4847
"name": "ExternalFriedFishStep",
4948
"versionInfo": "v1"
5049
}
5150
},
52-
"id": "973b06f1-a522-4d2d-9e1c-ec45a07e275c",
51+
"id": "af40089f-e57b-46d1-a15b-40c0d7f3800f",
5352
"name": "FishSandwichWithStatefulStepsProcess",
5453
"versionInfo": "FishSandwich.V1"
5554
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
{
2-
"$type": "Process",
32
"stepsState": {
43
"GatherFriedFishIngredientsWithStockStep": {
54
"$type": "Step",
6-
"id": "92a4cda38c7248648b0aa7ffaaa57f21",
5+
"id": "77c2f967cd354e66a51828e9755d2f07",
76
"name": "GatherFriedFishIngredientsWithStockStep",
87
"versionInfo": "GatherFishIngredient.V2",
98
"state": {
10-
"IngredientsStock": 3
9+
"IngredientsStock": 4
1110
}
1211
},
1312
"CutFoodStep": {
1413
"$type": "Step",
15-
"id": "7ace89e38e1c48b0b3a700b40d160c68",
14+
"id": "9276d03e64c44a6792d5fd81bd0dc143",
1615
"name": "CutFoodStep",
1716
"versionInfo": "CutFoodStep.V1"
1817
},
1918
"FryFoodStep": {
2019
"$type": "Step",
21-
"id": "09bc39ba6d9745439c7c792b8dac0af7",
20+
"id": "af2a00be4fe2408181ab5654318ed56b",
2221
"name": "FryFoodStep",
2322
"versionInfo": "FryFoodStep.V1"
2423
}
2524
},
26-
"id": "669c5850-9efc-4585-b3f0-9291a4471887",
25+
"id": "2050a24b-3e9d-418a-8413-74cadf4f6b4c",
2726
"name": "FriedFishWithStatefulStepsProcess",
2827
"versionInfo": "FriedFishProcess.v1"
2928
}

dotnet/src/Agents/Abstractions/AgentInvokeOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Microsoft.SemanticKernel.Agents;
55
/// <summary>
66
/// Optional parameters for agent invocation.
77
/// </summary>
8-
public sealed class AgentInvokeOptions
8+
public class AgentInvokeOptions
99
{
1010
/// <summary>
1111
/// Gets or sets optional arguments to pass to the agent's invocation, including any <see cref="PromptExecutionSettings"/>

0 commit comments

Comments
 (0)