From d529a7dcecaf4da4556b23bccc457684aa7f3d0c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 15:27:12 +0000 Subject: [PATCH 1/5] Initial plan From 3810043006abab1a986a9725a507c87dde046565 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 15:31:17 +0000 Subject: [PATCH 2/5] Add CreateSessionAsync overload with contextId and taskId parameters Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com> --- .../src/Microsoft.Agents.AI.A2A/A2AAgent.cs | 9 ++++ .../A2AAgentTests.cs | 41 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs b/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs index 5601653e8f..e7852fe164 100644 --- a/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs @@ -65,6 +65,15 @@ protected sealed override ValueTask CreateSessionCoreAsync(Cancell public ValueTask CreateSessionAsync(string contextId) => new(new A2AAgentSession() { ContextId = contextId }); + /// + /// Get a new instance using an existing context id and task id, to resume that conversation from a specific task. + /// + /// The context id to continue. + /// The task id to resume from. + /// A value task representing the asynchronous operation. The task result contains a new instance. + public ValueTask CreateSessionAsync(string contextId, string taskId) + => new(new A2AAgentSession() { ContextId = contextId, TaskId = taskId }); + /// protected override ValueTask SerializeSessionCoreAsync(AgentSession session, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) { diff --git a/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs b/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs index d6e736a528..541119b7f4 100644 --- a/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs @@ -1146,6 +1146,47 @@ public void GetService_RequestingAIAgentMetadata_ReturnsConsistentMetadata() Assert.Equal("a2a", metadata.ProviderName); } + /// + /// Verify that CreateSessionAsync with contextId creates a session with the correct context ID. + /// + [Fact] + public async Task CreateSessionAsync_WithContextId_CreatesSessionWithContextIdAsync() + { + // Arrange + const string ContextId = "test-context-123"; + + // Act + var session = await this._agent.CreateSessionAsync(ContextId); + + // Assert + Assert.NotNull(session); + Assert.IsType(session); + var typedSession = (A2AAgentSession)session; + Assert.Equal(ContextId, typedSession.ContextId); + Assert.Null(typedSession.TaskId); + } + + /// + /// Verify that CreateSessionAsync with contextId and taskId creates a session with both IDs set correctly. + /// + [Fact] + public async Task CreateSessionAsync_WithContextIdAndTaskId_CreatesSessionWithBothIdsAsync() + { + // Arrange + const string ContextId = "test-context-456"; + const string TaskId = "test-task-789"; + + // Act + var session = await this._agent.CreateSessionAsync(ContextId, TaskId); + + // Assert + Assert.NotNull(session); + Assert.IsType(session); + var typedSession = (A2AAgentSession)session; + Assert.Equal(ContextId, typedSession.ContextId); + Assert.Equal(TaskId, typedSession.TaskId); + } + #endregion public void Dispose() From 87b8298937eba9a6b8a51cc2ea432c3d8fbb0124 Mon Sep 17 00:00:00 2001 From: westey <164392973+westey-m@users.noreply.github.com> Date: Fri, 13 Feb 2026 17:38:35 +0000 Subject: [PATCH 3/5] Update dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../A2AAgentTests.cs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs b/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs index 541119b7f4..eef9758c56 100644 --- a/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs @@ -1187,6 +1187,59 @@ public async Task CreateSessionAsync_WithContextIdAndTaskId_CreatesSessionWithBo Assert.Equal(TaskId, typedSession.TaskId); } + /// + /// Verify that CreateSessionAsync throws when contextId is null, empty, or whitespace. + /// + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData(" ")] + [InlineData("\t")] + [InlineData("\r\n")] + public async Task CreateSessionAsync_WithInvalidContextId_ThrowsArgumentExceptionAsync(string? contextId) + { + // Act & Assert + await Assert.ThrowsAsync(async () => + await this._agent.CreateSessionAsync(contextId!)); + } + + /// + /// Verify that CreateSessionAsync with both parameters throws when contextId is null, empty, or whitespace. + /// + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData(" ")] + [InlineData("\t")] + [InlineData("\r\n")] + public async Task CreateSessionAsync_WithInvalidContextIdAndValidTaskId_ThrowsArgumentExceptionAsync(string? contextId) + { + // Arrange + const string TaskId = "valid-task-id"; + + // Act & Assert + await Assert.ThrowsAsync(async () => + await this._agent.CreateSessionAsync(contextId!, TaskId)); + } + + /// + /// Verify that CreateSessionAsync with both parameters throws when taskId is null, empty, or whitespace. + /// + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData(" ")] + [InlineData("\t")] + [InlineData("\r\n")] + public async Task CreateSessionAsync_WithValidContextIdAndInvalidTaskId_ThrowsArgumentExceptionAsync(string? taskId) + { + // Arrange + const string ContextId = "valid-context-id"; + + // Act & Assert + await Assert.ThrowsAsync(async () => + await this._agent.CreateSessionAsync(ContextId, taskId!)); + } #endregion public void Dispose() From 0f48857e98c77684fce4080946145f24e5e02f89 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 19:02:40 +0000 Subject: [PATCH 4/5] Add parameter validation to CreateSessionAsync methods Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com> --- dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs | 11 +++++++++-- .../A2AAgentTests.cs | 6 +++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs b/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs index e7852fe164..144447f648 100644 --- a/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs @@ -63,7 +63,10 @@ protected sealed override ValueTask CreateSessionCoreAsync(Cancell /// The context id to continue. /// A value task representing the asynchronous operation. The task result contains a new instance. public ValueTask CreateSessionAsync(string contextId) - => new(new A2AAgentSession() { ContextId = contextId }); + { + _ = Throw.IfNullOrWhitespace(contextId); + return new(new A2AAgentSession() { ContextId = contextId }); + } /// /// Get a new instance using an existing context id and task id, to resume that conversation from a specific task. @@ -72,7 +75,11 @@ public ValueTask CreateSessionAsync(string contextId) /// The task id to resume from. /// A value task representing the asynchronous operation. The task result contains a new instance. public ValueTask CreateSessionAsync(string contextId, string taskId) - => new(new A2AAgentSession() { ContextId = contextId, TaskId = taskId }); + { + _ = Throw.IfNullOrWhitespace(contextId); + _ = Throw.IfNullOrWhitespace(taskId); + return new(new A2AAgentSession() { ContextId = contextId, TaskId = taskId }); + } /// protected override ValueTask SerializeSessionCoreAsync(AgentSession session, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default) diff --git a/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs b/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs index eef9758c56..50d83c140d 100644 --- a/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs @@ -1199,7 +1199,7 @@ public async Task CreateSessionAsync_WithContextIdAndTaskId_CreatesSessionWithBo public async Task CreateSessionAsync_WithInvalidContextId_ThrowsArgumentExceptionAsync(string? contextId) { // Act & Assert - await Assert.ThrowsAsync(async () => + await Assert.ThrowsAnyAsync(async () => await this._agent.CreateSessionAsync(contextId!)); } @@ -1218,7 +1218,7 @@ public async Task CreateSessionAsync_WithInvalidContextIdAndValidTaskId_ThrowsAr const string TaskId = "valid-task-id"; // Act & Assert - await Assert.ThrowsAsync(async () => + await Assert.ThrowsAnyAsync(async () => await this._agent.CreateSessionAsync(contextId!, TaskId)); } @@ -1237,7 +1237,7 @@ public async Task CreateSessionAsync_WithValidContextIdAndInvalidTaskId_ThrowsAr const string ContextId = "valid-context-id"; // Act & Assert - await Assert.ThrowsAsync(async () => + await Assert.ThrowsAnyAsync(async () => await this._agent.CreateSessionAsync(ContextId, taskId!)); } #endregion From 74a662215dca330a70fed02256df357ab0f73ffd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 13 Feb 2026 19:10:56 +0000 Subject: [PATCH 5/5] Inline parameter validation in CreateSessionAsync methods Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com> --- dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs b/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs index 144447f648..18d8bfacdd 100644 --- a/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs @@ -63,10 +63,7 @@ protected sealed override ValueTask CreateSessionCoreAsync(Cancell /// The context id to continue. /// A value task representing the asynchronous operation. The task result contains a new instance. public ValueTask CreateSessionAsync(string contextId) - { - _ = Throw.IfNullOrWhitespace(contextId); - return new(new A2AAgentSession() { ContextId = contextId }); - } + => new(new A2AAgentSession() { ContextId = Throw.IfNullOrWhitespace(contextId) }); /// /// Get a new instance using an existing context id and task id, to resume that conversation from a specific task. @@ -75,11 +72,7 @@ public ValueTask CreateSessionAsync(string contextId) /// The task id to resume from. /// A value task representing the asynchronous operation. The task result contains a new instance. public ValueTask CreateSessionAsync(string contextId, string taskId) - { - _ = Throw.IfNullOrWhitespace(contextId); - _ = Throw.IfNullOrWhitespace(taskId); - return new(new A2AAgentSession() { ContextId = contextId, TaskId = taskId }); - } + => new(new A2AAgentSession() { ContextId = Throw.IfNullOrWhitespace(contextId), TaskId = Throw.IfNullOrWhitespace(taskId) }); /// protected override ValueTask SerializeSessionCoreAsync(AgentSession session, JsonSerializerOptions? jsonSerializerOptions = null, CancellationToken cancellationToken = default)