forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStep04_AzureAIAgent_CodeInterpreter.cs
More file actions
50 lines (44 loc) · 1.77 KB
/
Step04_AzureAIAgent_CodeInterpreter.cs
File metadata and controls
50 lines (44 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) Microsoft. All rights reserved.
using Azure.AI.Agents.Persistent;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.AzureAI;
using Microsoft.SemanticKernel.ChatCompletion;
namespace GettingStarted.AzureAgents;
/// <summary>
/// Demonstrate using code-interpreter on <see cref="AzureAIAgent"/> .
/// </summary>
public class Step04_AzureAIAgent_CodeInterpreter(ITestOutputHelper output) : BaseAzureAgentTest(output)
{
[Fact]
public async Task UseCodeInterpreterToolWithAgent()
{
// Define the agent
PersistentAgent definition = await this.Client.Administration.CreateAgentAsync(
TestConfiguration.AzureAI.ChatModelId,
tools: [new CodeInterpreterToolDefinition()]);
AzureAIAgent agent = new(definition, this.Client);
// Create a thread for the agent conversation.
AgentThread thread = new AzureAIAgentThread(this.Client, metadata: SampleMetadata);
// Respond to user input
try
{
await InvokeAgentAsync("Use code to determine the values in the Fibonacci sequence that are less than the value of 101?");
}
finally
{
await thread.DeleteAsync();
await this.Client.Administration.DeleteAgentAsync(agent.Id);
}
// Local function to invoke agent and display the conversation messages.
async Task InvokeAgentAsync(string input)
{
ChatMessageContent message = new(AuthorRole.User, input);
this.WriteAgentChatMessage(message);
await foreach (ChatMessageContent response in agent.InvokeAsync(message, thread))
{
this.WriteAgentChatMessage(response);
}
}
}
}