mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Add ChatClientAgent constructor overload (#188)
* Add ChatClientAgent constructor overload * Add unit tests for new constructor * Up code coverage with extra tests * Address PR comments. * Address PR comment * Add additional test to increase code coverage.
This commit is contained in:
committed by
GitHub
Unverified
parent
e6d611abe4
commit
95a3264c8b
@@ -33,11 +33,7 @@ public sealed class Step01_ChatClientAgent_Running(ITestOutputHelper output) : A
|
||||
IChatClient chatClient = base.GetChatClient(provider);
|
||||
|
||||
// Define the agent
|
||||
Agent agent = new ChatClientAgent(chatClient, options: new()
|
||||
{
|
||||
Name = ParrotName,
|
||||
Instructions = ParrotInstructions,
|
||||
});
|
||||
Agent agent = new ChatClientAgent(chatClient, ParrotInstructions, ParrotName);
|
||||
|
||||
// Invoke the agent and output the text result.
|
||||
Console.WriteLine(await agent.RunAsync("Fortune favors the bold."));
|
||||
|
||||
@@ -12,12 +12,33 @@ namespace Steps;
|
||||
/// </summary>
|
||||
public sealed class Step02_ChatClientAgent_UsingFunctionTools(ITestOutputHelper output) : AgentSample(output)
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(ChatClientProviders.AzureOpenAI)]
|
||||
[InlineData(ChatClientProviders.OpenAIChatCompletion)]
|
||||
public async Task RunningWithToolsBasic(ChatClientProviders provider)
|
||||
{
|
||||
// Creating a MenuTools instance to be used by the agent.
|
||||
var menuTools = new MenuTools();
|
||||
|
||||
// Get the chat client to use for the agent.
|
||||
var chatClient = base.GetChatClient(provider);
|
||||
|
||||
// Define the agent and add the GetSpecials tool.
|
||||
var agent = new ChatClientAgent(
|
||||
chatClient,
|
||||
instructions: "Answer questions about the menu.",
|
||||
tools: [AIFunctionFactory.Create(menuTools.GetSpecials)]);
|
||||
|
||||
// Respond to user input, invoking functions where appropriate.
|
||||
Console.WriteLine(await agent.RunAsync("What is the special soup and its price?"));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(ChatClientProviders.AzureOpenAI)]
|
||||
[InlineData(ChatClientProviders.OpenAIChatCompletion)]
|
||||
public async Task RunningWithTools(ChatClientProviders provider)
|
||||
{
|
||||
// Creating a Menu Tools to be used by the agent.
|
||||
// Creating a MenuTools instance to be used by the agent.
|
||||
var menuTools = new MenuTools();
|
||||
|
||||
// Define the options for the chat client agent.
|
||||
@@ -65,7 +86,7 @@ public sealed class Step02_ChatClientAgent_UsingFunctionTools(ITestOutputHelper
|
||||
[InlineData(ChatClientProviders.OpenAIChatCompletion)]
|
||||
public async Task StreamingRunWithTools(ChatClientProviders provider)
|
||||
{
|
||||
// Creating a Menu Tools to be used by the agent.
|
||||
// Creating a MenuTools instance to be used by the agent.
|
||||
var menuTools = new MenuTools();
|
||||
|
||||
// Define the options for the chat client agent.
|
||||
|
||||
-2
@@ -105,7 +105,6 @@ public sealed class Step03_ChatClientAgent_UsingCodeInterpreterTools(ITestOutput
|
||||
/// <returns>The code interpreter output as a string.</returns>
|
||||
private static string? GetCodeInterpreterOutput(object rawRepresentation, ChatClientProviders provider)
|
||||
{
|
||||
#pragma warning disable OPENAI001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
|
||||
switch (provider)
|
||||
{
|
||||
case ChatClientProviders.OpenAIAssistant
|
||||
@@ -114,7 +113,6 @@ public sealed class Step03_ChatClientAgent_UsingCodeInterpreterTools(ITestOutput
|
||||
string.Empty,
|
||||
stepDetails.CodeInterpreterOutputs.SelectMany(l => l.Logs)
|
||||
)}";
|
||||
#pragma warning restore OPENAI001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
|
||||
|
||||
case ChatClientProviders.AzureAIAgentsPersistent
|
||||
when rawRepresentation is Azure.AI.Agents.Persistent.RunStepDetailsUpdate stepDetails:
|
||||
|
||||
Reference in New Issue
Block a user