Skip to content

Commit d284d96

Browse files
authored
fix: 04_MultiModelService sample (#5074)
- Change Bedrock to Google GenAI provider - Fix use of OpenAI ("gpt-4o-mini" requires Responses API to use HostedWebSearchTool) - Clean up output
1 parent e94cfc6 commit d284d96

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

dotnet/samples/03-workflows/_StartHere/04_MultiModelService/04_MultiModelService.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="Anthropic" />
13-
<PackageReference Include="AWSSDK.Extensions.Bedrock.MEAI" />
13+
<PackageReference Include="Google.GenAI" />
1414
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
1515
</ItemGroup>
1616

dotnet/samples/03-workflows/_StartHere/04_MultiModelService/Program.cs

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

3-
using Amazon.BedrockRuntime;
3+
using Google.GenAI;
44
using Microsoft.Agents.AI;
55
using Microsoft.Agents.AI.Workflows;
66
using Microsoft.Extensions.AI;
@@ -9,22 +9,20 @@
99
const string Topic = "Goldendoodles make the best pets.";
1010

1111
// Create the IChatClients to talk to different services.
12-
IChatClient aws = new AmazonBedrockRuntimeClient(
13-
Environment.GetEnvironmentVariable("BEDROCK_ACCESS_KEY"!),
14-
Environment.GetEnvironmentVariable("BEDROCK_SECRET_KEY")!,
15-
Amazon.RegionEndpoint.USEast1)
16-
.AsIChatClient("amazon.nova-pro-v1:0");
12+
IChatClient google = new Client(vertexAI: false, apiKey: Environment.GetEnvironmentVariable("GOOGLE_GENAI_API_KEY"))
13+
.AsIChatClient("gemini-2.5-flash");
1714

1815
IChatClient anthropic = new Anthropic.AnthropicClient(
1916
new() { ApiKey = Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY") })
2017
.AsIChatClient("claude-sonnet-4-20250514");
2118

2219
IChatClient openai = new OpenAI.OpenAIClient(
23-
Environment.GetEnvironmentVariable("OPENAI_API_KEY")!).GetChatClient("gpt-4o-mini")
24-
.AsIChatClient();
20+
Environment.GetEnvironmentVariable("OPENAI_API_KEY"))
21+
.GetResponsesClient()
22+
.AsIChatClient("gpt-4o-mini");
2523

2624
// Define our agents.
27-
AIAgent researcher = new ChatClientAgent(aws,
25+
AIAgent researcher = new ChatClientAgent(google,
2826
instructions: """
2927
Write a short essay on topic specified by the user. The essay should be three to five paragraphs, written at a
3028
high school reading level, and include relevant background information, key claims, and notable perspectives.
@@ -60,6 +58,12 @@ You MUST NOT provide any commentary on what you're doing. Simply output the fina
6058
string? lastAuthor = null;
6159
await foreach (var update in workflowAgent.RunStreamingAsync(Topic))
6260
{
61+
// Skip WorkflowEvent-only updates
62+
if ((update.Contents == null || update.Contents.Count == 0) && update.RawRepresentation is WorkflowEvent)
63+
{
64+
continue;
65+
}
66+
6367
if (lastAuthor != update.AuthorName)
6468
{
6569
lastAuthor = update.AuthorName;

0 commit comments

Comments
 (0)