mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Merge branch 'main' into feature-so
This commit is contained in:
@@ -22,7 +22,7 @@ public abstract class ChatClientAgentRunStreamingTests<TAgentFixture>(Func<TAgen
|
||||
{
|
||||
// Arrange
|
||||
var agent = await this.Fixture.CreateChatClientAgentAsync(instructions: "Always respond with 'Computer says no', even if there was no user input.");
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await using var agentCleanup = new AgentCleanup(agent, this.Fixture);
|
||||
await using var sessionCleanup = new SessionCleanup(session, this.Fixture);
|
||||
|
||||
@@ -53,7 +53,7 @@ public abstract class ChatClientAgentRunStreamingTests<TAgentFixture>(Func<TAgen
|
||||
AIFunctionFactory.Create(MenuPlugin.GetSpecials),
|
||||
AIFunctionFactory.Create(MenuPlugin.GetItemPrice)
|
||||
]);
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
|
||||
foreach (var questionAndAnswer in questionsAndAnswers)
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ public abstract class ChatClientAgentRunTests<TAgentFixture>(Func<TAgentFixture>
|
||||
{
|
||||
// Arrange
|
||||
var agent = await this.Fixture.CreateChatClientAgentAsync(instructions: "ALWAYS RESPOND WITH 'Computer says no', even if there was no user input.");
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await using var agentCleanup = new AgentCleanup(agent, this.Fixture);
|
||||
await using var sessionCleanup = new SessionCleanup(session, this.Fixture);
|
||||
|
||||
@@ -53,7 +53,7 @@ public abstract class ChatClientAgentRunTests<TAgentFixture>(Func<TAgentFixture>
|
||||
AIFunctionFactory.Create(MenuPlugin.GetSpecials),
|
||||
AIFunctionFactory.Create(MenuPlugin.GetItemPrice)
|
||||
]);
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
|
||||
foreach (var questionAndAnswer in questionsAndAnswers)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ public abstract class RunStreamingTests<TAgentFixture>(Func<TAgentFixture> creat
|
||||
{
|
||||
// Arrange
|
||||
var agent = this.Fixture.Agent;
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await using var cleanup = new SessionCleanup(session, this.Fixture);
|
||||
|
||||
// Act
|
||||
@@ -36,7 +36,7 @@ public abstract class RunStreamingTests<TAgentFixture>(Func<TAgentFixture> creat
|
||||
{
|
||||
// Arrange
|
||||
var agent = this.Fixture.Agent;
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await using var cleanup = new SessionCleanup(session, this.Fixture);
|
||||
|
||||
// Act
|
||||
@@ -52,7 +52,7 @@ public abstract class RunStreamingTests<TAgentFixture>(Func<TAgentFixture> creat
|
||||
{
|
||||
// Arrange
|
||||
var agent = this.Fixture.Agent;
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await using var cleanup = new SessionCleanup(session, this.Fixture);
|
||||
|
||||
// Act
|
||||
@@ -68,7 +68,7 @@ public abstract class RunStreamingTests<TAgentFixture>(Func<TAgentFixture> creat
|
||||
{
|
||||
// Arrange
|
||||
var agent = this.Fixture.Agent;
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await using var cleanup = new SessionCleanup(session, this.Fixture);
|
||||
|
||||
// Act
|
||||
@@ -92,7 +92,7 @@ public abstract class RunStreamingTests<TAgentFixture>(Func<TAgentFixture> creat
|
||||
const string Q1 = "What is the capital of France.";
|
||||
const string Q2 = "And Austria?";
|
||||
var agent = this.Fixture.Agent;
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await using var cleanup = new SessionCleanup(session, this.Fixture);
|
||||
|
||||
// Act
|
||||
|
||||
@@ -24,7 +24,7 @@ public abstract class RunTests<TAgentFixture>(Func<TAgentFixture> createAgentFix
|
||||
{
|
||||
// Arrange
|
||||
var agent = this.Fixture.Agent;
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await using var cleanup = new SessionCleanup(session, this.Fixture);
|
||||
|
||||
// Act
|
||||
@@ -39,7 +39,7 @@ public abstract class RunTests<TAgentFixture>(Func<TAgentFixture> createAgentFix
|
||||
{
|
||||
// Arrange
|
||||
var agent = this.Fixture.Agent;
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await using var cleanup = new SessionCleanup(session, this.Fixture);
|
||||
|
||||
// Act
|
||||
@@ -57,7 +57,7 @@ public abstract class RunTests<TAgentFixture>(Func<TAgentFixture> createAgentFix
|
||||
{
|
||||
// Arrange
|
||||
var agent = this.Fixture.Agent;
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await using var cleanup = new SessionCleanup(session, this.Fixture);
|
||||
|
||||
// Act
|
||||
@@ -74,7 +74,7 @@ public abstract class RunTests<TAgentFixture>(Func<TAgentFixture> createAgentFix
|
||||
{
|
||||
// Arrange
|
||||
var agent = this.Fixture.Agent;
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await using var cleanup = new SessionCleanup(session, this.Fixture);
|
||||
|
||||
// Act
|
||||
@@ -99,7 +99,7 @@ public abstract class RunTests<TAgentFixture>(Func<TAgentFixture> createAgentFix
|
||||
const string Q1 = "What is the capital of France.";
|
||||
const string Q2 = "And Austria?";
|
||||
var agent = this.Fixture.Agent;
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await using var cleanup = new SessionCleanup(session, this.Fixture);
|
||||
|
||||
// Act
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ public class AnthropicChatCompletionFixture : IChatClientAgentFixture
|
||||
string instructions = "You are a helpful assistant.",
|
||||
IList<AITool>? aiTools = null)
|
||||
{
|
||||
var anthropicClient = new AnthropicClient() { APIKey = s_config.ApiKey };
|
||||
var anthropicClient = new AnthropicClient() { ApiKey = s_config.ApiKey };
|
||||
|
||||
IChatClient? chatClient = this._useBeta
|
||||
? anthropicClient
|
||||
|
||||
@@ -148,7 +148,7 @@ public sealed class A2AAgentTests : IDisposable
|
||||
new(ChatRole.User, "Test message")
|
||||
};
|
||||
|
||||
var session = await this._agent.GetNewSessionAsync();
|
||||
var session = await this._agent.CreateSessionAsync();
|
||||
|
||||
// Act
|
||||
await this._agent.RunAsync(inputMessages, session);
|
||||
@@ -168,7 +168,7 @@ public sealed class A2AAgentTests : IDisposable
|
||||
new(ChatRole.User, "Test message")
|
||||
};
|
||||
|
||||
var session = await this._agent.GetNewSessionAsync();
|
||||
var session = await this._agent.CreateSessionAsync();
|
||||
var a2aSession = (A2AAgentSession)session;
|
||||
a2aSession.ContextId = "existing-context-id";
|
||||
|
||||
@@ -201,7 +201,7 @@ public sealed class A2AAgentTests : IDisposable
|
||||
ContextId = "different-context"
|
||||
};
|
||||
|
||||
var session = await this._agent.GetNewSessionAsync();
|
||||
var session = await this._agent.CreateSessionAsync();
|
||||
var a2aSession = (A2AAgentSession)session;
|
||||
a2aSession.ContextId = "existing-context-id";
|
||||
|
||||
@@ -272,7 +272,7 @@ public sealed class A2AAgentTests : IDisposable
|
||||
ContextId = "new-stream-context"
|
||||
};
|
||||
|
||||
var session = await this._agent.GetNewSessionAsync();
|
||||
var session = await this._agent.CreateSessionAsync();
|
||||
|
||||
// Act
|
||||
await foreach (var _ in this._agent.RunStreamingAsync(inputMessages, session))
|
||||
@@ -296,7 +296,7 @@ public sealed class A2AAgentTests : IDisposable
|
||||
|
||||
this._handler.StreamingResponseToReturn = new AgentMessage();
|
||||
|
||||
var session = await this._agent.GetNewSessionAsync();
|
||||
var session = await this._agent.CreateSessionAsync();
|
||||
var a2aSession = (A2AAgentSession)session;
|
||||
a2aSession.ContextId = "existing-context-id";
|
||||
|
||||
@@ -316,7 +316,7 @@ public sealed class A2AAgentTests : IDisposable
|
||||
public async Task RunStreamingAsync_WithSessionHavingDifferentContextId_ThrowsInvalidOperationExceptionAsync()
|
||||
{
|
||||
// Arrange
|
||||
var session = await this._agent.GetNewSessionAsync();
|
||||
var session = await this._agent.CreateSessionAsync();
|
||||
var a2aSession = (A2AAgentSession)session;
|
||||
a2aSession.ContextId = "existing-context-id";
|
||||
|
||||
@@ -440,7 +440,7 @@ public sealed class A2AAgentTests : IDisposable
|
||||
Parts = [new TextPart { Text = "Response to task" }]
|
||||
};
|
||||
|
||||
var session = (A2AAgentSession)await this._agent.GetNewSessionAsync();
|
||||
var session = (A2AAgentSession)await this._agent.CreateSessionAsync();
|
||||
session.TaskId = "task-123";
|
||||
|
||||
var inputMessage = new ChatMessage(ChatRole.User, "Please make the background transparent");
|
||||
@@ -466,7 +466,7 @@ public sealed class A2AAgentTests : IDisposable
|
||||
Status = new() { State = TaskState.Submitted }
|
||||
};
|
||||
|
||||
var session = await this._agent.GetNewSessionAsync();
|
||||
var session = await this._agent.CreateSessionAsync();
|
||||
|
||||
// Act
|
||||
await this._agent.RunAsync("Start a task", session);
|
||||
@@ -492,7 +492,7 @@ public sealed class A2AAgentTests : IDisposable
|
||||
}
|
||||
};
|
||||
|
||||
var session = await this._agent.GetNewSessionAsync();
|
||||
var session = await this._agent.CreateSessionAsync();
|
||||
|
||||
// Act
|
||||
var result = await this._agent.RunAsync("Start a long-running task", session);
|
||||
@@ -586,7 +586,7 @@ public sealed class A2AAgentTests : IDisposable
|
||||
Parts = [new TextPart { Text = "Response to task" }]
|
||||
};
|
||||
|
||||
var session = (A2AAgentSession)await this._agent.GetNewSessionAsync();
|
||||
var session = (A2AAgentSession)await this._agent.CreateSessionAsync();
|
||||
session.TaskId = "task-123";
|
||||
|
||||
// Act
|
||||
@@ -613,7 +613,7 @@ public sealed class A2AAgentTests : IDisposable
|
||||
Status = new() { State = TaskState.Submitted }
|
||||
};
|
||||
|
||||
var session = await this._agent.GetNewSessionAsync();
|
||||
var session = await this._agent.CreateSessionAsync();
|
||||
|
||||
// Act
|
||||
await foreach (var _ in this._agent.RunStreamingAsync("Start a task", session))
|
||||
@@ -686,7 +686,7 @@ public sealed class A2AAgentTests : IDisposable
|
||||
]
|
||||
};
|
||||
|
||||
var session = await this._agent.GetNewSessionAsync();
|
||||
var session = await this._agent.CreateSessionAsync();
|
||||
|
||||
// Act
|
||||
var updates = new List<AgentResponseUpdate>();
|
||||
@@ -725,7 +725,7 @@ public sealed class A2AAgentTests : IDisposable
|
||||
Status = new() { State = TaskState.Working }
|
||||
};
|
||||
|
||||
var session = await this._agent.GetNewSessionAsync();
|
||||
var session = await this._agent.CreateSessionAsync();
|
||||
|
||||
// Act
|
||||
var updates = new List<AgentResponseUpdate>();
|
||||
@@ -768,7 +768,7 @@ public sealed class A2AAgentTests : IDisposable
|
||||
}
|
||||
};
|
||||
|
||||
var session = await this._agent.GetNewSessionAsync();
|
||||
var session = await this._agent.CreateSessionAsync();
|
||||
|
||||
// Act
|
||||
var updates = new List<AgentResponseUpdate>();
|
||||
|
||||
@@ -228,7 +228,7 @@ public sealed class AGUIAgentTests
|
||||
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
List<ChatMessage> messages = [new ChatMessage(ChatRole.User, "Hello")];
|
||||
|
||||
// Act
|
||||
@@ -250,7 +250,7 @@ public sealed class AGUIAgentTests
|
||||
using var httpClient = new HttpClient();
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: []);
|
||||
AgentSession originalSession = await agent.GetNewSessionAsync();
|
||||
AgentSession originalSession = await agent.CreateSessionAsync();
|
||||
JsonElement serialized = originalSession.Serialize();
|
||||
|
||||
// Act
|
||||
@@ -487,7 +487,7 @@ public sealed class AGUIAgentTests
|
||||
|
||||
var chatClient = new AGUIChatClient(httpClient, "http://localhost/agent", null, AGUIJsonSerializerContext.Default.Options);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "agent1", description: "Test agent", tools: [testTool]);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
List<ChatMessage> messages = [new ChatMessage(ChatRole.User, "Test")];
|
||||
|
||||
// Act
|
||||
|
||||
@@ -378,7 +378,7 @@ public class AIAgentTests
|
||||
|
||||
protected override string? IdCore { get; }
|
||||
|
||||
public override async ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default)
|
||||
public override async ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public override async ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
|
||||
|
||||
@@ -35,7 +35,7 @@ public class DelegatingAIAgentTests
|
||||
this._innerAgentMock.Protected().SetupGet<string>("IdCore").Returns("test-agent-id");
|
||||
this._innerAgentMock.Setup(x => x.Name).Returns("Test Agent");
|
||||
this._innerAgentMock.Setup(x => x.Description).Returns("Test Description");
|
||||
this._innerAgentMock.Setup(x => x.GetNewSessionAsync()).ReturnsAsync(this._testSession);
|
||||
this._innerAgentMock.Setup(x => x.CreateSessionAsync()).ReturnsAsync(this._testSession);
|
||||
|
||||
this._innerAgentMock
|
||||
.Protected()
|
||||
@@ -132,17 +132,17 @@ public class DelegatingAIAgentTests
|
||||
#region Method Delegation Tests
|
||||
|
||||
/// <summary>
|
||||
/// Verify that GetNewSessionAsync delegates to inner agent.
|
||||
/// Verify that CreateSessionAsync delegates to inner agent.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task GetNewSessionAsync_DelegatesToInnerAgentAsync()
|
||||
public async Task CreateSessionAsync_DelegatesToInnerAgentAsync()
|
||||
{
|
||||
// Act
|
||||
var session = await this._delegatingAgent.GetNewSessionAsync();
|
||||
var session = await this._delegatingAgent.CreateSessionAsync();
|
||||
|
||||
// Assert
|
||||
Assert.Same(this._testSession, session);
|
||||
this._innerAgentMock.Verify(x => x.GetNewSessionAsync(), Times.Once);
|
||||
this._innerAgentMock.Verify(x => x.CreateSessionAsync(), Times.Once);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+10
-7
@@ -242,7 +242,7 @@ public sealed class AnthropicBetaServiceExtensionsTests
|
||||
var client = new AnthropicClient
|
||||
{
|
||||
HttpClient = new HttpClient(handler) { BaseAddress = new Uri("http://localhost") },
|
||||
APIKey = "test-key"
|
||||
ApiKey = "test-key"
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -252,7 +252,7 @@ public sealed class AnthropicBetaServiceExtensionsTests
|
||||
defaultMaxTokens: 8192);
|
||||
|
||||
// Invoke the agent to trigger the request
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
try
|
||||
{
|
||||
await agent.RunAsync("Test message", session);
|
||||
@@ -436,13 +436,15 @@ public sealed class AnthropicBetaServiceExtensionsTests
|
||||
}
|
||||
|
||||
public HttpClient HttpClient { get => throw new NotImplementedException(); init => throw new NotImplementedException(); }
|
||||
public Uri BaseUrl { get => new("http://localhost"); init => throw new NotImplementedException(); }
|
||||
public string BaseUrl { get => "http://localhost"; init => throw new NotImplementedException(); }
|
||||
public bool ResponseValidation { get => throw new NotImplementedException(); init => throw new NotImplementedException(); }
|
||||
public int? MaxRetries { get => throw new NotImplementedException(); init => throw new NotImplementedException(); }
|
||||
public TimeSpan? Timeout { get => throw new NotImplementedException(); init => throw new NotImplementedException(); }
|
||||
public string? APIKey { get => throw new NotImplementedException(); init => throw new NotImplementedException(); }
|
||||
public string? ApiKey { get => throw new NotImplementedException(); init => throw new NotImplementedException(); }
|
||||
public string? AuthToken { get => throw new NotImplementedException(); init => throw new NotImplementedException(); }
|
||||
|
||||
public IAnthropicClientWithRawResponse WithRawResponse => throw new NotImplementedException();
|
||||
|
||||
public IMessageService Messages => throw new NotImplementedException();
|
||||
|
||||
public IModelService Models => throw new NotImplementedException();
|
||||
@@ -453,14 +455,13 @@ public sealed class AnthropicBetaServiceExtensionsTests
|
||||
|
||||
IMessageService IAnthropicClient.Messages => new Mock<IMessageService>().Object;
|
||||
|
||||
public Task<HttpResponse> Execute<T>(HttpRequest<T> request, CancellationToken cancellationToken = default) where T : ParamsBase
|
||||
public IAnthropicClient WithOptions(Func<ClientOptions, ClientOptions> modifier)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IAnthropicClient WithOptions(Func<ClientOptions, ClientOptions> modifier)
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private sealed class TestBetaService : IBetaService
|
||||
@@ -472,6 +473,8 @@ public sealed class AnthropicBetaServiceExtensionsTests
|
||||
this._client = client;
|
||||
}
|
||||
|
||||
public IBetaServiceWithRawResponse WithRawResponse => throw new NotImplementedException();
|
||||
|
||||
public global::Anthropic.Services.Beta.IModelService Models => throw new NotImplementedException();
|
||||
|
||||
public global::Anthropic.Services.Beta.IFileService Files => throw new NotImplementedException();
|
||||
|
||||
+8
-7
@@ -66,27 +66,28 @@ public sealed class AnthropicClientExtensionsTests
|
||||
}
|
||||
|
||||
public HttpClient HttpClient { get => throw new NotImplementedException(); init => throw new NotImplementedException(); }
|
||||
public Uri BaseUrl { get => new("http://localhost"); init => throw new NotImplementedException(); }
|
||||
public string BaseUrl { get => "http://localhost"; init => throw new NotImplementedException(); }
|
||||
public bool ResponseValidation { get => throw new NotImplementedException(); init => throw new NotImplementedException(); }
|
||||
public int? MaxRetries { get => throw new NotImplementedException(); init => throw new NotImplementedException(); }
|
||||
public TimeSpan? Timeout { get => throw new NotImplementedException(); init => throw new NotImplementedException(); }
|
||||
public string? APIKey { get => throw new NotImplementedException(); init => throw new NotImplementedException(); }
|
||||
public string? ApiKey { get => throw new NotImplementedException(); init => throw new NotImplementedException(); }
|
||||
public string? AuthToken { get => throw new NotImplementedException(); init => throw new NotImplementedException(); }
|
||||
|
||||
public IAnthropicClientWithRawResponse WithRawResponse => throw new NotImplementedException();
|
||||
|
||||
public IMessageService Messages => throw new NotImplementedException();
|
||||
|
||||
public IModelService Models => throw new NotImplementedException();
|
||||
|
||||
public IBetaService Beta => throw new NotImplementedException();
|
||||
|
||||
public Task<HttpResponse> Execute<T>(HttpRequest<T> request, CancellationToken cancellationToken = default) where T : ParamsBase
|
||||
public IAnthropicClient WithOptions(Func<ClientOptions, ClientOptions> modifier)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IAnthropicClient WithOptions(Func<ClientOptions, ClientOptions> modifier)
|
||||
public void Dispose()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,7 +310,7 @@ public sealed class AnthropicClientExtensionsTests
|
||||
var client = new AnthropicClient
|
||||
{
|
||||
HttpClient = new HttpClient(handler) { BaseAddress = new Uri("http://localhost") },
|
||||
APIKey = "test-key"
|
||||
ApiKey = "test-key"
|
||||
};
|
||||
|
||||
// Act
|
||||
@@ -319,7 +320,7 @@ public sealed class AnthropicClientExtensionsTests
|
||||
defaultMaxTokens: 8192);
|
||||
|
||||
// Invoke the agent to trigger the request
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
try
|
||||
{
|
||||
await agent.RunAsync("Test message", session);
|
||||
|
||||
@@ -53,7 +53,7 @@ public class AzureAIProjectChatClientTests
|
||||
});
|
||||
|
||||
// Act
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await agent.RunAsync("Hello", session);
|
||||
|
||||
Assert.True(requestTriggered);
|
||||
@@ -102,7 +102,7 @@ public class AzureAIProjectChatClientTests
|
||||
});
|
||||
|
||||
// Act
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await agent.RunAsync("Hello", session, options: new ChatClientAgentRunOptions() { ChatOptions = new() { ConversationId = "conv_12345" } });
|
||||
|
||||
Assert.True(requestTriggered);
|
||||
@@ -151,7 +151,7 @@ public class AzureAIProjectChatClientTests
|
||||
});
|
||||
|
||||
// Act
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await agent.RunAsync("Hello", session, options: new ChatClientAgentRunOptions() { ChatOptions = new() { ConversationId = "conv_12345" } });
|
||||
|
||||
Assert.True(requestTriggered);
|
||||
@@ -200,7 +200,7 @@ public class AzureAIProjectChatClientTests
|
||||
});
|
||||
|
||||
// Act
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
await agent.RunAsync("Hello", session, options: new ChatClientAgentRunOptions() { ChatOptions = new() { ConversationId = "resp_0888a" } });
|
||||
|
||||
Assert.True(requestTriggered);
|
||||
|
||||
+1
-1
@@ -71,7 +71,7 @@ public sealed class AggregatorPromptAgentFactoryTests
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default)
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public sealed class AgentEntityTests(ITestOutputHelper outputHelper) : IDisposab
|
||||
// A proxy agent is needed to call the hosted test agent
|
||||
AIAgent simpleAgentProxy = simpleAgent.AsDurableAgentProxy(testHelper.Services);
|
||||
|
||||
AgentSession session = await simpleAgentProxy.GetNewSessionAsync(this.TestTimeoutToken);
|
||||
AgentSession session = await simpleAgentProxy.CreateSessionAsync(this.TestTimeoutToken);
|
||||
|
||||
DurableTaskClient client = testHelper.GetClient();
|
||||
|
||||
@@ -98,7 +98,7 @@ public sealed class AgentEntityTests(ITestOutputHelper outputHelper) : IDisposab
|
||||
// A proxy agent is needed to call the hosted test agent
|
||||
AIAgent simpleAgentProxy = simpleAgent.AsDurableAgentProxy(testHelper.Services);
|
||||
|
||||
AgentSession session = await simpleAgentProxy.GetNewSessionAsync(this.TestTimeoutToken);
|
||||
AgentSession session = await simpleAgentProxy.CreateSessionAsync(this.TestTimeoutToken);
|
||||
|
||||
DurableTaskClient client = testHelper.GetClient();
|
||||
|
||||
@@ -184,7 +184,7 @@ public sealed class AgentEntityTests(ITestOutputHelper outputHelper) : IDisposab
|
||||
public override async Task<string> RunAsync(TaskOrchestrationContext context, string input)
|
||||
{
|
||||
DurableAIAgent writer = context.GetAgent("TestAgent");
|
||||
AgentSession writerSession = await writer.GetNewSessionAsync();
|
||||
AgentSession writerSession = await writer.CreateSessionAsync();
|
||||
|
||||
await writer.RunAsync(
|
||||
message: context.GetInput<string>()!,
|
||||
|
||||
+3
-3
@@ -51,7 +51,7 @@ public sealed class ExternalClientTests(ITestOutputHelper outputHelper) : IDispo
|
||||
AIAgent simpleAgentProxy = simpleAgent.AsDurableAgentProxy(testHelper.Services);
|
||||
|
||||
// Act: send a prompt to the agent and wait for a response
|
||||
AgentSession session = await simpleAgentProxy.GetNewSessionAsync(this.TestTimeoutToken);
|
||||
AgentSession session = await simpleAgentProxy.CreateSessionAsync(this.TestTimeoutToken);
|
||||
await simpleAgentProxy.RunAsync(
|
||||
message: "Hello!",
|
||||
session,
|
||||
@@ -156,7 +156,7 @@ public sealed class ExternalClientTests(ITestOutputHelper outputHelper) : IDispo
|
||||
{
|
||||
// 1. Get agent and create a session
|
||||
DurableAIAgent agent = context.GetAgent("SimpleAgent");
|
||||
AgentSession session = await agent.GetNewSessionAsync(this.TestTimeoutToken);
|
||||
AgentSession session = await agent.CreateSessionAsync(this.TestTimeoutToken);
|
||||
|
||||
// 2. Call an agent and tell it my name
|
||||
await agent.RunAsync($"My name is {name}.", session);
|
||||
@@ -194,7 +194,7 @@ public sealed class ExternalClientTests(ITestOutputHelper outputHelper) : IDispo
|
||||
AIAgent workflowManagerAgentProxy = testHelper.Services.GetDurableAgentProxy("WorkflowAgent");
|
||||
|
||||
// Act: send a prompt to the agent
|
||||
AgentSession session = await workflowManagerAgentProxy.GetNewSessionAsync(this.TestTimeoutToken);
|
||||
AgentSession session = await workflowManagerAgentProxy.CreateSessionAsync(this.TestTimeoutToken);
|
||||
await workflowManagerAgentProxy.RunAsync(
|
||||
message: "Start a greeting workflow for \"John Doe\".",
|
||||
session,
|
||||
|
||||
@@ -55,7 +55,7 @@ public sealed class TimeToLiveTests(ITestOutputHelper outputHelper) : IDisposabl
|
||||
});
|
||||
|
||||
AIAgent agentProxy = simpleAgent.AsDurableAgentProxy(testHelper.Services);
|
||||
AgentSession session = await agentProxy.GetNewSessionAsync(this.TestTimeoutToken);
|
||||
AgentSession session = await agentProxy.CreateSessionAsync(this.TestTimeoutToken);
|
||||
DurableTaskClient client = testHelper.GetClient();
|
||||
AgentSessionId sessionId = session.GetService<AgentSessionId>();
|
||||
|
||||
@@ -120,7 +120,7 @@ public sealed class TimeToLiveTests(ITestOutputHelper outputHelper) : IDisposabl
|
||||
});
|
||||
|
||||
AIAgent agentProxy = simpleAgent.AsDurableAgentProxy(testHelper.Services);
|
||||
AgentSession session = await agentProxy.GetNewSessionAsync(this.TestTimeoutToken);
|
||||
AgentSession session = await agentProxy.CreateSessionAsync(this.TestTimeoutToken);
|
||||
DurableTaskClient client = testHelper.GetClient();
|
||||
AgentSessionId sessionId = session.GetService<AgentSessionId>();
|
||||
|
||||
|
||||
+3
-3
@@ -96,7 +96,7 @@ public class GitHubCopilotAgentTests
|
||||
client,
|
||||
instructions: "You are a helpful assistant. Keep your answers short.");
|
||||
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
|
||||
// Act - First turn
|
||||
AgentResponse response1 = await agent.RunAsync("My name is Alice.", session);
|
||||
@@ -123,7 +123,7 @@ public class GitHubCopilotAgentTests
|
||||
client1,
|
||||
instructions: "You are a helpful assistant. Keep your answers short.");
|
||||
|
||||
AgentSession session1 = await agent1.GetNewSessionAsync();
|
||||
AgentSession session1 = await agent1.CreateSessionAsync();
|
||||
await agent1.RunAsync("Remember this number: 42.", session1);
|
||||
|
||||
sessionId = ((GitHubCopilotAgentSession)session1).SessionId;
|
||||
@@ -137,7 +137,7 @@ public class GitHubCopilotAgentTests
|
||||
client2,
|
||||
instructions: "You are a helpful assistant. Keep your answers short.");
|
||||
|
||||
AgentSession session2 = await agent2.GetNewSessionAsync(sessionId);
|
||||
AgentSession session2 = await agent2.CreateSessionAsync(sessionId);
|
||||
AgentResponse response = await agent2.RunAsync("What number did I ask you to remember?", session2);
|
||||
|
||||
// Assert
|
||||
|
||||
+4
-4
@@ -55,14 +55,14 @@ public sealed class GitHubCopilotAgentTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetNewSessionAsync_ReturnsGitHubCopilotAgentSessionAsync()
|
||||
public async Task CreateSessionAsync_ReturnsGitHubCopilotAgentSessionAsync()
|
||||
{
|
||||
// Arrange
|
||||
CopilotClient copilotClient = new(new CopilotClientOptions { AutoStart = false });
|
||||
var agent = new GitHubCopilotAgent(copilotClient, ownsClient: false, tools: null);
|
||||
|
||||
// Act
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(session);
|
||||
@@ -70,7 +70,7 @@ public sealed class GitHubCopilotAgentTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetNewSessionAsync_WithSessionId_ReturnsSessionWithSessionIdAsync()
|
||||
public async Task CreateSessionAsync_WithSessionId_ReturnsSessionWithSessionIdAsync()
|
||||
{
|
||||
// Arrange
|
||||
CopilotClient copilotClient = new(new CopilotClientOptions { AutoStart = false });
|
||||
@@ -78,7 +78,7 @@ public sealed class GitHubCopilotAgentTests
|
||||
const string TestSessionId = "test-session-id";
|
||||
|
||||
// Act
|
||||
var session = await agent.GetNewSessionAsync(TestSessionId);
|
||||
var session = await agent.CreateSessionAsync(TestSessionId);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(session);
|
||||
|
||||
@@ -175,7 +175,7 @@ public sealed class AIAgentExtensionsTests
|
||||
{
|
||||
Mock<AIAgent> agentMock = new() { CallBase = true };
|
||||
agentMock.SetupGet(x => x.Name).Returns("TestAgent");
|
||||
agentMock.Setup(x => x.GetNewSessionAsync()).ReturnsAsync(new TestAgentSession());
|
||||
agentMock.Setup(x => x.CreateSessionAsync()).ReturnsAsync(new TestAgentSession());
|
||||
agentMock
|
||||
.Protected()
|
||||
.Setup<Task<AgentResponse>>("RunCoreAsync",
|
||||
@@ -194,7 +194,7 @@ public sealed class AIAgentExtensionsTests
|
||||
{
|
||||
Mock<AIAgent> agentMock = new() { CallBase = true };
|
||||
agentMock.SetupGet(x => x.Name).Returns("TestAgent");
|
||||
agentMock.Setup(x => x.GetNewSessionAsync()).ReturnsAsync(new TestAgentSession());
|
||||
agentMock.Setup(x => x.CreateSessionAsync()).ReturnsAsync(new TestAgentSession());
|
||||
agentMock
|
||||
.Protected()
|
||||
.Setup<Task<AgentResponse>>("RunCoreAsync",
|
||||
|
||||
+8
-8
@@ -31,7 +31,7 @@ public sealed class BasicStreamingTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync();
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "hello");
|
||||
|
||||
List<AgentResponseUpdate> updates = [];
|
||||
@@ -62,7 +62,7 @@ public sealed class BasicStreamingTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync();
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "test");
|
||||
|
||||
List<AgentResponseUpdate> updates = [];
|
||||
@@ -106,7 +106,7 @@ public sealed class BasicStreamingTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync();
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "hello");
|
||||
|
||||
// Act
|
||||
@@ -125,7 +125,7 @@ public sealed class BasicStreamingTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentSession chatClientSession = (ChatClientAgentSession)await agent.GetNewSessionAsync();
|
||||
ChatClientAgentSession chatClientSession = (ChatClientAgentSession)await agent.CreateSessionAsync();
|
||||
ChatMessage firstUserMessage = new(ChatRole.User, "First question");
|
||||
|
||||
// Act - First turn
|
||||
@@ -169,7 +169,7 @@ public sealed class BasicStreamingTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync(useMultiMessageAgent: true);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentSession chatClientSession = (ChatClientAgentSession)await agent.GetNewSessionAsync();
|
||||
ChatClientAgentSession chatClientSession = (ChatClientAgentSession)await agent.CreateSessionAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Tell me a story");
|
||||
|
||||
List<AgentResponseUpdate> updates = [];
|
||||
@@ -201,7 +201,7 @@ public sealed class BasicStreamingTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentSession chatClientSession = (ChatClientAgentSession)await agent.GetNewSessionAsync();
|
||||
ChatClientAgentSession chatClientSession = (ChatClientAgentSession)await agent.CreateSessionAsync();
|
||||
|
||||
// Multiple user messages sent in one turn
|
||||
ChatMessage[] userMessages =
|
||||
@@ -280,7 +280,7 @@ internal sealed class FakeChatClientAgent : AIAgent
|
||||
|
||||
public override string? Description => "A fake agent for testing";
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
new(new FakeInMemoryAgentSession());
|
||||
|
||||
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) =>
|
||||
@@ -344,7 +344,7 @@ internal sealed class FakeMultiMessageAgent : AIAgent
|
||||
|
||||
public override string? Description => "A fake agent that sends multiple messages for testing";
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
new(new FakeInMemoryAgentSession());
|
||||
|
||||
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) =>
|
||||
|
||||
+1
-1
@@ -334,7 +334,7 @@ internal sealed class FakeForwardedPropsAgent : AIAgent
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
new(new FakeInMemoryAgentSession());
|
||||
|
||||
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) =>
|
||||
|
||||
+8
-8
@@ -34,7 +34,7 @@ public sealed class SharedStateTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync(fakeAgent);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync();
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync();
|
||||
|
||||
string stateJson = JsonSerializer.Serialize(initialState);
|
||||
byte[] stateBytes = System.Text.Encoding.UTF8.GetBytes(stateJson);
|
||||
@@ -77,7 +77,7 @@ public sealed class SharedStateTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync(fakeAgent);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync();
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync();
|
||||
|
||||
string stateJson = JsonSerializer.Serialize(initialState);
|
||||
byte[] stateBytes = System.Text.Encoding.UTF8.GetBytes(stateJson);
|
||||
@@ -119,7 +119,7 @@ public sealed class SharedStateTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync(fakeAgent);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync();
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync();
|
||||
|
||||
string stateJson = JsonSerializer.Serialize(complexState);
|
||||
byte[] stateBytes = System.Text.Encoding.UTF8.GetBytes(stateJson);
|
||||
@@ -159,7 +159,7 @@ public sealed class SharedStateTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync(fakeAgent);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync();
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync();
|
||||
|
||||
string stateJson = JsonSerializer.Serialize(initialState);
|
||||
byte[] stateBytes = System.Text.Encoding.UTF8.GetBytes(stateJson);
|
||||
@@ -210,7 +210,7 @@ public sealed class SharedStateTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync(fakeAgent);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync();
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync();
|
||||
|
||||
ChatMessage userMessage = new(ChatRole.User, "hello");
|
||||
|
||||
@@ -243,7 +243,7 @@ public sealed class SharedStateTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync(fakeAgent);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync();
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync();
|
||||
|
||||
string stateJson = JsonSerializer.Serialize(emptyState);
|
||||
byte[] stateBytes = System.Text.Encoding.UTF8.GetBytes(stateJson);
|
||||
@@ -280,7 +280,7 @@ public sealed class SharedStateTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync(fakeAgent);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Sample assistant", tools: []);
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.GetNewSessionAsync();
|
||||
ChatClientAgentSession? session = (ChatClientAgentSession)await agent.CreateSessionAsync();
|
||||
|
||||
string stateJson = JsonSerializer.Serialize(initialState);
|
||||
byte[] stateBytes = System.Text.Encoding.UTF8.GetBytes(stateJson);
|
||||
@@ -417,7 +417,7 @@ internal sealed class FakeStateAgent : AIAgent
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
new(new FakeInMemoryAgentSession());
|
||||
|
||||
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) =>
|
||||
|
||||
+9
-9
@@ -45,7 +45,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync(serverTools: [serverTool]);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Call the server function");
|
||||
|
||||
List<AgentResponseUpdate> updates = [];
|
||||
@@ -93,7 +93,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync(serverTools: [getWeatherTool, getTimeTool]);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "What's the weather and time?");
|
||||
|
||||
List<AgentResponseUpdate> updates = [];
|
||||
@@ -134,7 +134,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Call the client function");
|
||||
|
||||
List<AgentResponseUpdate> updates = [];
|
||||
@@ -182,7 +182,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [calculateTool, formatTool]);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Calculate 5 + 3 and format 'hello'");
|
||||
|
||||
List<AgentResponseUpdate> updates = [];
|
||||
@@ -233,7 +233,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync(serverTools: [serverTool]);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Get both server and client data");
|
||||
|
||||
List<AgentResponseUpdate> updates = [];
|
||||
@@ -298,7 +298,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync(serverTools: [testTool]);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Call the test function");
|
||||
|
||||
List<AgentResponseUpdate> updates = [];
|
||||
@@ -342,7 +342,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync(serverTools: [func1, func2], triggerParallelCalls: true);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Call both functions in parallel");
|
||||
|
||||
List<AgentResponseUpdate> updates = [];
|
||||
@@ -428,7 +428,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync(serverTools: [serverTool], jsonSerializerOptions: ServerJsonContext.Default.Options);
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null, ServerJsonContext.Default.Options);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: []);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Get server forecast for Seattle for 5 days");
|
||||
|
||||
List<AgentResponseUpdate> updates = [];
|
||||
@@ -474,7 +474,7 @@ public sealed class ToolCallingTests : IAsyncDisposable
|
||||
await this.SetupTestServerAsync();
|
||||
var chatClient = new AGUIChatClient(this._client!, "", null, ClientJsonContext.Default.Options);
|
||||
AIAgent agent = chatClient.AsAIAgent(instructions: null, name: "assistant", description: "Test assistant", tools: [clientTool]);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatMessage userMessage = new(ChatRole.User, "Get client forecast for Portland with hourly data");
|
||||
|
||||
List<AgentResponseUpdate> updates = [];
|
||||
|
||||
+2
-2
@@ -425,7 +425,7 @@ public sealed class AGUIEndpointRouteBuilderExtensionsTests
|
||||
|
||||
public override string? Description => "Agent that produces multiple text chunks";
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
new(new TestInMemoryAgentSession());
|
||||
|
||||
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) =>
|
||||
@@ -515,7 +515,7 @@ public sealed class AGUIEndpointRouteBuilderExtensionsTests
|
||||
|
||||
public override string? Description => "Test agent";
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
new(new TestInMemoryAgentSession());
|
||||
|
||||
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) =>
|
||||
|
||||
@@ -11,7 +11,7 @@ internal sealed class TestAgent(string name, string description) : AIAgent
|
||||
|
||||
public override string? Description => description;
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default) => new(new DummyAgentSession());
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default) => new(new DummyAgentSession());
|
||||
|
||||
public override ValueTask<AgentSession> DeserializeSessionAsync(
|
||||
JsonElement serializedSession,
|
||||
|
||||
@@ -382,7 +382,7 @@ public class AgentExtensionsTests
|
||||
this._exceptionToThrow = exceptionToThrow;
|
||||
}
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default)
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
|
||||
|
||||
@@ -241,8 +241,8 @@ public partial class ChatClientAgentTests
|
||||
|
||||
ChatClientAgent agent = new(mockService.Object, options: new() { ChatOptions = new() { Instructions = "test instructions" } });
|
||||
|
||||
// Create a session using the agent's GetNewSessionAsync method
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
// Create a session using the agent's CreateSessionAsync method
|
||||
var session = await agent.CreateSessionAsync();
|
||||
|
||||
// Act
|
||||
await agent.RunAsync([new(ChatRole.User, "new message")], session: session);
|
||||
@@ -356,7 +356,7 @@ public partial class ChatClientAgentTests
|
||||
ChatClientAgent agent = new(mockService.Object, options: new() { AIContextProviderFactory = (_, _) => new(mockProvider.Object), ChatOptions = new() { Instructions = "base instructions", Tools = [AIFunctionFactory.Create(() => { }, "base function")] } });
|
||||
|
||||
// Act
|
||||
var session = await agent.GetNewSessionAsync() as ChatClientAgentSession;
|
||||
var session = await agent.CreateSessionAsync() as ChatClientAgentSession;
|
||||
await agent.RunAsync(requestMessages, session);
|
||||
|
||||
// Assert
|
||||
@@ -1296,7 +1296,7 @@ public partial class ChatClientAgentTests
|
||||
});
|
||||
|
||||
// Act
|
||||
ChatClientAgentSession? session = await agent.GetNewSessionAsync() as ChatClientAgentSession;
|
||||
ChatClientAgentSession? session = await agent.CreateSessionAsync() as ChatClientAgentSession;
|
||||
await agent.RunStreamingAsync([new(ChatRole.User, "test")], session).ToListAsync();
|
||||
|
||||
// Assert
|
||||
@@ -1334,7 +1334,7 @@ public partial class ChatClientAgentTests
|
||||
});
|
||||
|
||||
// Act & Assert
|
||||
ChatClientAgentSession? session = await agent.GetNewSessionAsync() as ChatClientAgentSession;
|
||||
ChatClientAgentSession? session = await agent.CreateSessionAsync() as ChatClientAgentSession;
|
||||
var exception = await Assert.ThrowsAsync<InvalidOperationException>(async () => await agent.RunStreamingAsync([new(ChatRole.User, "test")], session).ToListAsync());
|
||||
Assert.Equal("Only the ConversationId or ChatHistoryProvider may be set, but not both and switching from one to another is not supported.", exception.Message);
|
||||
}
|
||||
@@ -1391,7 +1391,7 @@ public partial class ChatClientAgentTests
|
||||
});
|
||||
|
||||
// Act
|
||||
var session = await agent.GetNewSessionAsync() as ChatClientAgentSession;
|
||||
var session = await agent.CreateSessionAsync() as ChatClientAgentSession;
|
||||
var updates = agent.RunStreamingAsync(requestMessages, session);
|
||||
_ = await updates.ToAgentResponseAsync();
|
||||
|
||||
|
||||
+5
-5
@@ -158,7 +158,7 @@ public class ChatClientAgent_ChatHistoryManagementTests
|
||||
});
|
||||
|
||||
// Act
|
||||
ChatClientAgentSession? session = await agent.GetNewSessionAsync() as ChatClientAgentSession;
|
||||
ChatClientAgentSession? session = await agent.CreateSessionAsync() as ChatClientAgentSession;
|
||||
await agent.RunAsync([new(ChatRole.User, "test")], session);
|
||||
|
||||
// Assert
|
||||
@@ -200,7 +200,7 @@ public class ChatClientAgent_ChatHistoryManagementTests
|
||||
});
|
||||
|
||||
// Act
|
||||
ChatClientAgentSession? session = await agent.GetNewSessionAsync() as ChatClientAgentSession;
|
||||
ChatClientAgentSession? session = await agent.CreateSessionAsync() as ChatClientAgentSession;
|
||||
await agent.RunAsync([new(ChatRole.User, "test")], session);
|
||||
|
||||
// Assert
|
||||
@@ -248,7 +248,7 @@ public class ChatClientAgent_ChatHistoryManagementTests
|
||||
});
|
||||
|
||||
// Act
|
||||
ChatClientAgentSession? session = await agent.GetNewSessionAsync() as ChatClientAgentSession;
|
||||
ChatClientAgentSession? session = await agent.CreateSessionAsync() as ChatClientAgentSession;
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => agent.RunAsync([new(ChatRole.User, "test")], session));
|
||||
|
||||
// Assert
|
||||
@@ -282,7 +282,7 @@ public class ChatClientAgent_ChatHistoryManagementTests
|
||||
});
|
||||
|
||||
// Act & Assert
|
||||
ChatClientAgentSession? session = await agent.GetNewSessionAsync() as ChatClientAgentSession;
|
||||
ChatClientAgentSession? session = await agent.CreateSessionAsync() as ChatClientAgentSession;
|
||||
InvalidOperationException exception = await Assert.ThrowsAsync<InvalidOperationException>(() => agent.RunAsync([new(ChatRole.User, "test")], session));
|
||||
Assert.Equal("Only the ConversationId or ChatHistoryProvider may be set, but not both and switching from one to another is not supported.", exception.Message);
|
||||
}
|
||||
@@ -335,7 +335,7 @@ public class ChatClientAgent_ChatHistoryManagementTests
|
||||
});
|
||||
|
||||
// Act
|
||||
ChatClientAgentSession? session = await agent.GetNewSessionAsync() as ChatClientAgentSession;
|
||||
ChatClientAgentSession? session = await agent.CreateSessionAsync() as ChatClientAgentSession;
|
||||
AdditionalPropertiesDictionary additionalProperties = new();
|
||||
additionalProperties.Add(mockOverrideChatHistoryProvider.Object);
|
||||
await agent.RunAsync([new(ChatRole.User, "test")], session, options: new AgentRunOptions { AdditionalProperties = additionalProperties });
|
||||
|
||||
+10
-10
@@ -7,12 +7,12 @@ using Moq;
|
||||
namespace Microsoft.Agents.AI.UnitTests;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the ChatClientAgent.GetNewSessionAsync methods.
|
||||
/// Contains unit tests for the ChatClientAgent.CreateSessionAsync methods.
|
||||
/// </summary>
|
||||
public class ChatClientAgent_GetNewSessionTests
|
||||
public class ChatClientAgent_CreateSessionTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task GetNewSession_UsesAIContextProviderFactory_IfProvidedAsync()
|
||||
public async Task CreateSession_UsesAIContextProviderFactory_IfProvidedAsync()
|
||||
{
|
||||
// Arrange
|
||||
var mockChatClient = new Mock<IChatClient>();
|
||||
@@ -29,7 +29,7 @@ public class ChatClientAgent_GetNewSessionTests
|
||||
});
|
||||
|
||||
// Act
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
|
||||
// Assert
|
||||
Assert.True(factoryCalled, "AIContextProviderFactory was not called.");
|
||||
@@ -39,7 +39,7 @@ public class ChatClientAgent_GetNewSessionTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetNewSession_UsesChatHistoryProviderFactory_IfProvidedAsync()
|
||||
public async Task CreateSession_UsesChatHistoryProviderFactory_IfProvidedAsync()
|
||||
{
|
||||
// Arrange
|
||||
var mockChatClient = new Mock<IChatClient>();
|
||||
@@ -56,7 +56,7 @@ public class ChatClientAgent_GetNewSessionTests
|
||||
});
|
||||
|
||||
// Act
|
||||
var session = await agent.GetNewSessionAsync();
|
||||
var session = await agent.CreateSessionAsync();
|
||||
|
||||
// Assert
|
||||
Assert.True(factoryCalled, "ChatHistoryProviderFactory was not called.");
|
||||
@@ -66,7 +66,7 @@ public class ChatClientAgent_GetNewSessionTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetNewSession_UsesChatHistoryProvider_FromTypedOverloadAsync()
|
||||
public async Task CreateSession_UsesChatHistoryProvider_FromTypedOverloadAsync()
|
||||
{
|
||||
// Arrange
|
||||
var mockChatClient = new Mock<IChatClient>();
|
||||
@@ -74,7 +74,7 @@ public class ChatClientAgent_GetNewSessionTests
|
||||
var agent = new ChatClientAgent(mockChatClient.Object);
|
||||
|
||||
// Act
|
||||
var session = await agent.GetNewSessionAsync(mockChatHistoryProvider.Object);
|
||||
var session = await agent.CreateSessionAsync(mockChatHistoryProvider.Object);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<ChatClientAgentSession>(session);
|
||||
@@ -83,7 +83,7 @@ public class ChatClientAgent_GetNewSessionTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetNewSession_UsesConversationId_FromTypedOverloadAsync()
|
||||
public async Task CreateSession_UsesConversationId_FromTypedOverloadAsync()
|
||||
{
|
||||
// Arrange
|
||||
var mockChatClient = new Mock<IChatClient>();
|
||||
@@ -91,7 +91,7 @@ public class ChatClientAgent_GetNewSessionTests
|
||||
var agent = new ChatClientAgent(mockChatClient.Object);
|
||||
|
||||
// Act
|
||||
var session = await agent.GetNewSessionAsync(TestConversationId);
|
||||
var session = await agent.CreateSessionAsync(TestConversationId);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<ChatClientAgentSession>(session);
|
||||
+12
-12
@@ -30,7 +30,7 @@ public sealed partial class ChatClientAgent_RunWithCustomOptionsTests
|
||||
It.IsAny<CancellationToken>())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, "Response")]));
|
||||
|
||||
ChatClientAgent agent = new(mockChatClient.Object);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatClientAgentRunOptions options = new();
|
||||
|
||||
// Act
|
||||
@@ -59,7 +59,7 @@ public sealed partial class ChatClientAgent_RunWithCustomOptionsTests
|
||||
It.IsAny<CancellationToken>())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, "Response")]));
|
||||
|
||||
ChatClientAgent agent = new(mockChatClient.Object);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatClientAgentRunOptions options = new();
|
||||
|
||||
// Act
|
||||
@@ -88,7 +88,7 @@ public sealed partial class ChatClientAgent_RunWithCustomOptionsTests
|
||||
It.IsAny<CancellationToken>())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, "Response")]));
|
||||
|
||||
ChatClientAgent agent = new(mockChatClient.Object);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatMessage message = new(ChatRole.User, "Test message");
|
||||
ChatClientAgentRunOptions options = new();
|
||||
|
||||
@@ -118,7 +118,7 @@ public sealed partial class ChatClientAgent_RunWithCustomOptionsTests
|
||||
It.IsAny<CancellationToken>())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, "Response")]));
|
||||
|
||||
ChatClientAgent agent = new(mockChatClient.Object);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
IEnumerable<ChatMessage> messages = [new(ChatRole.User, "Message 1"), new(ChatRole.User, "Message 2")];
|
||||
ChatClientAgentRunOptions options = new();
|
||||
|
||||
@@ -179,7 +179,7 @@ public sealed partial class ChatClientAgent_RunWithCustomOptionsTests
|
||||
It.IsAny<CancellationToken>())).Returns(GetAsyncUpdatesAsync());
|
||||
|
||||
ChatClientAgent agent = new(mockChatClient.Object);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatClientAgentRunOptions options = new();
|
||||
|
||||
// Act
|
||||
@@ -211,7 +211,7 @@ public sealed partial class ChatClientAgent_RunWithCustomOptionsTests
|
||||
It.IsAny<CancellationToken>())).Returns(GetAsyncUpdatesAsync());
|
||||
|
||||
ChatClientAgent agent = new(mockChatClient.Object);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatClientAgentRunOptions options = new();
|
||||
|
||||
// Act
|
||||
@@ -243,7 +243,7 @@ public sealed partial class ChatClientAgent_RunWithCustomOptionsTests
|
||||
It.IsAny<CancellationToken>())).Returns(GetAsyncUpdatesAsync());
|
||||
|
||||
ChatClientAgent agent = new(mockChatClient.Object);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatMessage message = new(ChatRole.User, "Test message");
|
||||
ChatClientAgentRunOptions options = new();
|
||||
|
||||
@@ -276,7 +276,7 @@ public sealed partial class ChatClientAgent_RunWithCustomOptionsTests
|
||||
It.IsAny<CancellationToken>())).Returns(GetAsyncUpdatesAsync());
|
||||
|
||||
ChatClientAgent agent = new(mockChatClient.Object);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
IEnumerable<ChatMessage> messages = [new ChatMessage(ChatRole.User, "Message 1"), new ChatMessage(ChatRole.User, "Message 2")];
|
||||
ChatClientAgentRunOptions options = new();
|
||||
|
||||
@@ -324,7 +324,7 @@ public sealed partial class ChatClientAgent_RunWithCustomOptionsTests
|
||||
It.IsAny<CancellationToken>())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, """{"id":2, "fullName":"Tigger", "species":"Tiger"}""")]));
|
||||
|
||||
ChatClientAgent agent = new(mockChatClient.Object);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatClientAgentRunOptions options = new();
|
||||
|
||||
// Act
|
||||
@@ -354,7 +354,7 @@ public sealed partial class ChatClientAgent_RunWithCustomOptionsTests
|
||||
It.IsAny<CancellationToken>())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, """{"id":2, "fullName":"Tigger", "species":"Tiger"}""")]));
|
||||
|
||||
ChatClientAgent agent = new(mockChatClient.Object);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatClientAgentRunOptions options = new();
|
||||
|
||||
// Act
|
||||
@@ -384,7 +384,7 @@ public sealed partial class ChatClientAgent_RunWithCustomOptionsTests
|
||||
It.IsAny<CancellationToken>())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, """{"id":2, "fullName":"Tigger", "species":"Tiger"}""")]));
|
||||
|
||||
ChatClientAgent agent = new(mockChatClient.Object);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
ChatMessage message = new(ChatRole.User, "Test message");
|
||||
ChatClientAgentRunOptions options = new();
|
||||
|
||||
@@ -415,7 +415,7 @@ public sealed partial class ChatClientAgent_RunWithCustomOptionsTests
|
||||
It.IsAny<CancellationToken>())).ReturnsAsync(new ChatResponse([new(ChatRole.Assistant, """{"id":2, "fullName":"Tigger", "species":"Tiger"}""")]));
|
||||
|
||||
ChatClientAgent agent = new(mockChatClient.Object);
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
IEnumerable<ChatMessage> messages = [new(ChatRole.User, "Message 1"), new(ChatRole.User, "Message 2")];
|
||||
ChatClientAgentRunOptions options = new();
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ internal sealed class TestAIAgent : AIAgent
|
||||
public Func<string>? NameFunc;
|
||||
public Func<string>? DescriptionFunc;
|
||||
|
||||
public Func<JsonElement, JsonSerializerOptions?, AgentSession> DeserializeSessionFunc = delegate { throw new NotSupportedException(); };
|
||||
public Func<AgentSession> GetNewSessionFunc = delegate { throw new NotSupportedException(); };
|
||||
public readonly Func<JsonElement, JsonSerializerOptions?, AgentSession> DeserializeSessionFunc = delegate { throw new NotSupportedException(); };
|
||||
public readonly Func<AgentSession> CreateSessionFunc = delegate { throw new NotSupportedException(); };
|
||||
public Func<IEnumerable<ChatMessage>, AgentSession?, AgentRunOptions?, CancellationToken, Task<AgentResponse>> RunAsyncFunc = delegate { throw new NotSupportedException(); };
|
||||
public Func<IEnumerable<ChatMessage>, AgentSession?, AgentRunOptions?, CancellationToken, IAsyncEnumerable<AgentResponseUpdate>> RunStreamingAsyncFunc = delegate { throw new NotSupportedException(); };
|
||||
public Func<Type, object?, object?>? GetServiceFunc;
|
||||
@@ -27,8 +27,8 @@ internal sealed class TestAIAgent : AIAgent
|
||||
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) =>
|
||||
new(this.DeserializeSessionFunc(serializedSession, jsonSerializerOptions));
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
new(this.GetNewSessionFunc());
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
new(this.CreateSessionFunc());
|
||||
|
||||
protected override Task<AgentResponse> RunCoreAsync(IEnumerable<ChatMessage> messages, AgentSession? session = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default) =>
|
||||
this.RunAsyncFunc(messages, session, options, cancellationToken);
|
||||
|
||||
+31
-20
@@ -19,43 +19,48 @@ namespace Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests;
|
||||
/// </summary>
|
||||
public sealed class MediaInputTest(ITestOutputHelper output) : IntegrationTest(output)
|
||||
{
|
||||
private const string WorkflowFileName = "MediaInput.yaml";
|
||||
private const string WorkflowWithConversationFileName = "MediaInputConversation.yaml";
|
||||
private const string WorkflowWithAutoSendFileName = "MediaInputAutoSend.yaml";
|
||||
private const string PdfReference = "https://sample-files.com/downloads/documents/pdf/basic-text.pdf";
|
||||
private const string ImageReference = "https://sample-files.com/downloads/images/jpg/web_optimized_1200x800_97kb.jpg";
|
||||
|
||||
[Theory]
|
||||
[InlineData(ImageReference, "image/jpeg", Skip = "Failing consistently in the agent service api")]
|
||||
[InlineData(PdfReference, "application/pdf", Skip = "Not currently supported by agent service api")]
|
||||
public async Task ValidateFileUrlAsync(string fileSource, string mediaType)
|
||||
[InlineData(ImageReference, "image/jpeg", true, Skip = "Failing due to agent service bug.")]
|
||||
[InlineData(ImageReference, "image/jpeg", false, Skip = "Failing due to agent service bug.")]
|
||||
public async Task ValidateFileUrlAsync(string fileSource, string mediaType, bool useConversation)
|
||||
{
|
||||
this.Output.WriteLine($"File: {ImageReference}");
|
||||
await this.ValidateFileAsync(new UriContent(fileSource, mediaType));
|
||||
await this.ValidateFileAsync(new UriContent(fileSource, mediaType), useConversation);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(ImageReference, "image/jpeg")]
|
||||
[InlineData(PdfReference, "application/pdf")]
|
||||
public async Task ValidateFileDataAsync(string fileSource, string mediaType)
|
||||
[InlineData(ImageReference, "image/jpeg", true)]
|
||||
[InlineData(ImageReference, "image/jpeg", false, Skip = "Failing due to agent service bug.")]
|
||||
[InlineData(PdfReference, "application/pdf", true)]
|
||||
[InlineData(PdfReference, "application/pdf", false)]
|
||||
public async Task ValidateFileDataAsync(string fileSource, string mediaType, bool useConversation)
|
||||
{
|
||||
byte[] fileData = await DownloadFileAsync(fileSource);
|
||||
string encodedData = Convert.ToBase64String(fileData);
|
||||
string fileUrl = $"data:{mediaType};base64,{encodedData}";
|
||||
this.Output.WriteLine($"Content: {fileUrl.Substring(0, 112)}...");
|
||||
await this.ValidateFileAsync(new DataContent(fileUrl));
|
||||
await this.ValidateFileAsync(new DataContent(fileUrl), useConversation);
|
||||
}
|
||||
|
||||
[Fact(Skip = "Not currently supported by agent service api")]
|
||||
public async Task ValidateFileUploadAsync()
|
||||
[Theory]
|
||||
[InlineData(PdfReference, "doc.pdf", true, Skip = "Failing due to agent service bug.")]
|
||||
[InlineData(PdfReference, "doc.pdf", false, Skip = "Failing due to agent service bug.")]
|
||||
public async Task ValidateFileUploadAsync(string fileSource, string documentName, bool useConversation)
|
||||
{
|
||||
byte[] fileData = await DownloadFileAsync(PdfReference);
|
||||
byte[] fileData = await DownloadFileAsync(fileSource);
|
||||
AIProjectClient client = new(this.TestEndpoint, new AzureCliCredential());
|
||||
using MemoryStream contentStream = new(fileData);
|
||||
OpenAIFileClient fileClient = client.GetProjectOpenAIClient().GetOpenAIFileClient();
|
||||
OpenAIFile fileInfo = await fileClient.UploadFileAsync(contentStream, "basic-text.pdf", FileUploadPurpose.Assistants);
|
||||
OpenAIFile fileInfo = await fileClient.UploadFileAsync(contentStream, documentName, FileUploadPurpose.Assistants);
|
||||
try
|
||||
{
|
||||
this.Output.WriteLine($"File: {fileInfo.Id}");
|
||||
await this.ValidateFileAsync(new HostedFileContent(fileInfo.Id));
|
||||
await this.ValidateFileAsync(new HostedFileContent(fileInfo.Id), useConversation);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -70,20 +75,26 @@ public sealed class MediaInputTest(ITestOutputHelper output) : IntegrationTest(o
|
||||
return await client.GetByteArrayAsync(new Uri(uri));
|
||||
}
|
||||
|
||||
private async Task ValidateFileAsync(AIContent fileContent)
|
||||
private async Task ValidateFileAsync(AIContent fileContent, bool useConversation)
|
||||
{
|
||||
AgentProvider agentProvider = AgentProvider.Create(this.Configuration, AgentProvider.Names.Vision);
|
||||
await agentProvider.CreateAgentsAsync().ConfigureAwait(false);
|
||||
|
||||
ChatMessage inputMessage = new(ChatRole.User, [new TextContent("I've provided a file:"), fileContent]);
|
||||
ChatMessage inputMessage =
|
||||
new(ChatRole.User,
|
||||
[
|
||||
new TextContent("I've provided a file:"),
|
||||
fileContent
|
||||
]);
|
||||
|
||||
string workflowFileName = useConversation ? WorkflowWithConversationFileName : WorkflowWithAutoSendFileName;
|
||||
DeclarativeWorkflowOptions options = await this.CreateOptionsAsync();
|
||||
Workflow workflow = DeclarativeWorkflowBuilder.Build<ChatMessage>(Path.Combine(Environment.CurrentDirectory, "Workflows", WorkflowFileName), options);
|
||||
Workflow workflow = DeclarativeWorkflowBuilder.Build<ChatMessage>(Path.Combine(Environment.CurrentDirectory, "Workflows", workflowFileName), options);
|
||||
|
||||
WorkflowHarness harness = new(workflow, runId: Path.GetFileNameWithoutExtension(WorkflowFileName));
|
||||
WorkflowHarness harness = new(workflow, runId: Path.GetFileNameWithoutExtension(workflowFileName));
|
||||
WorkflowEvents workflowEvents = await harness.RunWorkflowAsync(inputMessage).ConfigureAwait(false);
|
||||
ConversationUpdateEvent conversationEvent = Assert.Single(workflowEvents.ConversationEvents);
|
||||
this.Output.WriteLine("CONVERSATION: " + conversationEvent.ConversationId);
|
||||
Assert.Equal(useConversation ? 1 : 2, workflowEvents.ConversationEvents.Count);
|
||||
this.Output.WriteLine("CONVERSATION: " + workflowEvents.ConversationEvents[0].ConversationId);
|
||||
AgentResponseEvent agentResponseEvent = Assert.Single(workflowEvents.AgentResponseEvents);
|
||||
this.Output.WriteLine("RESPONSE: " + agentResponseEvent.Response.Text);
|
||||
Assert.NotEmpty(agentResponseEvent.Response.Text);
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
kind: Workflow
|
||||
trigger:
|
||||
|
||||
kind: OnConversationStart
|
||||
id: workflow_test
|
||||
actions:
|
||||
|
||||
- kind: InvokeAzureAgent
|
||||
id: invoke_vision
|
||||
agent:
|
||||
name: VisionAgent
|
||||
input:
|
||||
messages: =System.LastMessage
|
||||
output:
|
||||
autoSend: true
|
||||
+104
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Agents.AI.Workflows.Declarative.Extensions;
|
||||
@@ -666,4 +667,107 @@ public sealed class ChatMessageExtensionsTests
|
||||
RecordValue metadataRecord = Assert.IsType<RecordValue>(metadataField, exactMatch: false);
|
||||
Assert.Equal(2, metadataRecord.Fields.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTripChatMessageAsRecord()
|
||||
{
|
||||
// Arrange
|
||||
ChatMessage message =
|
||||
new(ChatRole.User,
|
||||
[
|
||||
new TextContent("Test message"),
|
||||
new UriContent("https://example.com/image.jpg", "image/jpeg"),
|
||||
new HostedFileContent("file_123abc"),
|
||||
new DataContent(new byte[] { 1, 2, 3, 4, 5 }, "application/pdf"),
|
||||
])
|
||||
{
|
||||
MessageId = "msg-001"
|
||||
};
|
||||
|
||||
// Act
|
||||
RecordValue result = message.ToRecord();
|
||||
DataValue resultValue = result.ToDataValue();
|
||||
ChatMessage? messageCopy = resultValue.ToChatMessage();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(messageCopy);
|
||||
Assert.Equal(message.Role, messageCopy.Role);
|
||||
Assert.Equal(message.MessageId, messageCopy.MessageId);
|
||||
Assert.Equal(message.Contents.Count, messageCopy.Contents.Count);
|
||||
foreach (AIContent contentCopy in messageCopy.Contents)
|
||||
{
|
||||
AIContent sourceContent = Assert.Single(message.Contents, c => c.GetType() == contentCopy.GetType());
|
||||
AssertAIContentEquivalent(sourceContent, contentCopy);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTripChatMessageAsTable()
|
||||
{
|
||||
// Arrange
|
||||
ChatMessage message =
|
||||
new(ChatRole.User,
|
||||
[
|
||||
new TextContent("Test message"),
|
||||
new UriContent("https://example.com/image.jpg", "image/jpeg"),
|
||||
new HostedFileContent("file_123abc"),
|
||||
new DataContent(new byte[] { 1, 2, 3, 4, 5 }, "application/pdf"),
|
||||
])
|
||||
{
|
||||
MessageId = "msg-001"
|
||||
};
|
||||
|
||||
IEnumerable<ChatMessage> messages = [message];
|
||||
|
||||
// Act
|
||||
TableValue result = messages.ToTable();
|
||||
TableDataValue resultValue = result.ToTable();
|
||||
ChatMessage[] messagesCopy = resultValue.ToChatMessages().ToArray();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(messagesCopy);
|
||||
ChatMessage messageCopy = Assert.Single(messagesCopy);
|
||||
Assert.Equal(message.Role, messageCopy.Role);
|
||||
Assert.Equal(message.MessageId, messageCopy.MessageId);
|
||||
Assert.Equal(message.Contents.Count, messageCopy.Contents.Count);
|
||||
foreach (AIContent contentCopy in messageCopy.Contents)
|
||||
{
|
||||
AIContent sourceContent = Assert.Single(message.Contents, c => c.GetType() == contentCopy.GetType());
|
||||
AssertAIContentEquivalent(sourceContent, contentCopy);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two AIContent instances for equivalence without using Assert.Equivalent,
|
||||
/// which fails on .NET Framework 4.7.2 due to ReadOnlySpan.GetHashCode() not being supported.
|
||||
/// </summary>
|
||||
private static void AssertAIContentEquivalent(AIContent expected, AIContent actual)
|
||||
{
|
||||
Assert.Equal(expected.GetType(), actual.GetType());
|
||||
|
||||
switch (expected)
|
||||
{
|
||||
case TextContent expectedText:
|
||||
TextContent actualText = Assert.IsType<TextContent>(actual);
|
||||
Assert.Equal(expectedText.Text, actualText.Text);
|
||||
break;
|
||||
case UriContent expectedUri:
|
||||
UriContent actualUri = Assert.IsType<UriContent>(actual);
|
||||
Assert.Equal(expectedUri.Uri, actualUri.Uri);
|
||||
Assert.Equal(expectedUri.MediaType, actualUri.MediaType);
|
||||
break;
|
||||
case HostedFileContent expectedFile:
|
||||
HostedFileContent actualFile = Assert.IsType<HostedFileContent>(actual);
|
||||
Assert.Equal(expectedFile.FileId, actualFile.FileId);
|
||||
break;
|
||||
case DataContent expectedData:
|
||||
DataContent actualData = Assert.IsType<DataContent>(actual);
|
||||
Assert.Equal(expectedData.MediaType, actualData.MediaType);
|
||||
Assert.Equal(expectedData.Data.ToArray(), actualData.Data.ToArray());
|
||||
break;
|
||||
default:
|
||||
Assert.Fail($"Unexpected AIContent type: {expected.GetType().Name}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public class AgentWorkflowBuilderTests
|
||||
{
|
||||
public override string Name => name;
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default)
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default)
|
||||
=> new(new DoubleEchoAgentSession());
|
||||
|
||||
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
|
||||
|
||||
@@ -144,7 +144,7 @@ public class InProcessExecutionTests
|
||||
|
||||
public override string Name { get; }
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default) => new(new SimpleTestAgentSession());
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default) => new(new SimpleTestAgentSession());
|
||||
|
||||
public override ValueTask<AgentSession> DeserializeSessionAsync(System.Text.Json.JsonElement serializedSession,
|
||||
System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) => new(new SimpleTestAgentSession());
|
||||
|
||||
@@ -24,7 +24,7 @@ public class RepresentationTests
|
||||
|
||||
private sealed class TestAgent : AIAgent
|
||||
{
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default)
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
|
||||
|
||||
@@ -19,7 +19,7 @@ internal sealed class RoleCheckAgent(bool allowOtherAssistantRoles, string? id =
|
||||
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
|
||||
=> new(new RoleCheckAgentSession());
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default) => new(new RoleCheckAgentSession());
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default) => new(new RoleCheckAgentSession());
|
||||
|
||||
protected override Task<AgentResponse> RunCoreAsync(IEnumerable<ChatMessage> messages, AgentSession? session = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default)
|
||||
=> this.RunStreamingAsync(messages, session, options, cancellationToken).ToAgentResponseAsync(cancellationToken);
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ internal sealed class HelloAgent(string id = nameof(HelloAgent)) : AIAgent
|
||||
protected override string? IdCore => id;
|
||||
public override string? Name => id;
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default)
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default)
|
||||
=> new(new HelloAgentSession());
|
||||
|
||||
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ internal static class Step7EntryPoint
|
||||
|
||||
for (int i = 0; i < numIterations; i++)
|
||||
{
|
||||
AgentSession session = await agent.GetNewSessionAsync();
|
||||
AgentSession session = await agent.CreateSessionAsync();
|
||||
await foreach (AgentResponseUpdate update in agent.RunStreamingAsync(session).ConfigureAwait(false))
|
||||
{
|
||||
if (update.RawRepresentation is WorkflowEvent)
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ internal static class Step10EntryPoint
|
||||
{
|
||||
AIAgent hostAgent = WorkflowInstance.AsAgent("echo-workflow", "EchoW", executionEnvironment: executionEnvironment);
|
||||
|
||||
AgentSession session = await hostAgent.GetNewSessionAsync();
|
||||
AgentSession session = await hostAgent.CreateSessionAsync();
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
AgentResponse response;
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ internal static class Step11EntryPoint
|
||||
{
|
||||
AIAgent hostAgent = WorkflowInstance.AsAgent("echo-workflow", "EchoW", executionEnvironment: executionEnvironment);
|
||||
|
||||
AgentSession session = await hostAgent.GetNewSessionAsync();
|
||||
AgentSession session = await hostAgent.CreateSessionAsync();
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
AgentResponse response;
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ internal static class Step12EntryPoint
|
||||
{
|
||||
AIAgent hostAgent = WorkflowInstance.AsAgent("echo-workflow", "EchoW", executionEnvironment: executionEnvironment);
|
||||
|
||||
AgentSession session = await hostAgent.GetNewSessionAsync();
|
||||
AgentSession session = await hostAgent.CreateSessionAsync();
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
AgentResponse response;
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ internal static class Step13EntryPoint
|
||||
{
|
||||
AIAgent hostAgent = WorkflowInstance.AsAgent("echo-workflow", "EchoW", executionEnvironment: environment, includeWorkflowOutputsInResponse: true);
|
||||
|
||||
session ??= await hostAgent.GetNewSessionAsync();
|
||||
session ??= await hostAgent.CreateSessionAsync();
|
||||
AgentResponse response;
|
||||
ResponseContinuationToken? continuationToken = null;
|
||||
do
|
||||
|
||||
@@ -18,10 +18,10 @@ internal class TestEchoAgent(string? id = null, string? name = null, string? pre
|
||||
|
||||
public override async ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return serializedSession.Deserialize<EchoAgentSession>(jsonSerializerOptions) ?? await this.GetNewSessionAsync(cancellationToken);
|
||||
return serializedSession.Deserialize<EchoAgentSession>(jsonSerializerOptions) ?? await this.CreateSessionAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default) =>
|
||||
new(new EchoAgentSession());
|
||||
|
||||
private static ChatMessage UpdateSession(ChatMessage message, InMemoryAgentSession? session = null)
|
||||
|
||||
@@ -45,7 +45,7 @@ public class TestReplayAgent(List<ChatMessage>? messages = null, string? id = nu
|
||||
return result;
|
||||
}
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default)
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default)
|
||||
=> new(new ReplayAgentSession());
|
||||
|
||||
public override ValueTask<AgentSession> DeserializeSessionAsync(JsonElement serializedSession, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)
|
||||
|
||||
@@ -29,7 +29,7 @@ internal sealed class TestRequestAgent(TestAgentRequestType requestType, int unp
|
||||
protected override string? IdCore => id;
|
||||
public override string? Name => name;
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken)
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken)
|
||||
=> new(requestType switch
|
||||
{
|
||||
TestAgentRequestType.FunctionCall => new TestRequestAgentSession<FunctionCallContent, FunctionResultContent>(),
|
||||
@@ -73,7 +73,7 @@ internal sealed class TestRequestAgent(TestAgentRequestType requestType, int unp
|
||||
where TRequest : AIContent
|
||||
where TResponse : AIContent
|
||||
{
|
||||
this.LastSession = session ??= await this.GetNewSessionAsync(cancellationToken);
|
||||
this.LastSession = session ??= await this.CreateSessionAsync(cancellationToken);
|
||||
TestRequestAgentSession<TRequest, TResponse> traSessin = ConvertSession<TRequest, TResponse>(session);
|
||||
|
||||
if (traSessin.HasSentRequests)
|
||||
|
||||
@@ -46,7 +46,7 @@ public class WorkflowHostSmokeTests
|
||||
return new(new Session(serializedSession, jsonSerializerOptions));
|
||||
}
|
||||
|
||||
public override ValueTask<AgentSession> GetNewSessionAsync(CancellationToken cancellationToken = default)
|
||||
public override ValueTask<AgentSession> CreateSessionAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new(new Session());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user