.NET: Add CreateSessionAsync overload with taskId for A2AAgent session resumption#3924
.NET: Add CreateSessionAsync overload with taskId for A2AAgent session resumption#3924
Conversation
Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds an additional CreateSessionAsync overload to A2AAgent to enable session resumption with both context and task identifiers. Previously, only the context ID could be specified when resuming a session, but A2A protocol sessions track both ContextId (conversation) and TaskId (current task). This change enables users to resume from a specific task within a conversation.
Changes:
- Added
CreateSessionAsync(string contextId, string taskId)overload toA2AAgent - Added unit tests for both existing and new
CreateSessionAsyncoverloads
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs | Added new CreateSessionAsync overload accepting both contextId and taskId parameters |
| dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs | Added two test methods to verify both CreateSessionAsync overloads create sessions with correct IDs |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot, the unit tests are failing, please fix, and address the PR comments. |
Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com>
... Fixed in commit 0f48857. Added parameter validation using |
| public ValueTask<AgentSession> CreateSessionAsync(string contextId) | ||
| => new(new A2AAgentSession() { ContextId = contextId }); | ||
| { | ||
| _ = Throw.IfNullOrWhitespace(contextId); |
There was a problem hiding this comment.
Throw.IfNullOrWhitespace(contextId) can be inline inside the new(new A2AAgentSession() { ContextId = contextId }); statement, e.g. new(new A2AAgentSession() { ContextId = Throw.IfNullOrWhitespace(contextId) });
Using this pattern means we can use a lambda style for the method body reducing the lines of code. Same below for CreateSessionAsync(string contextId, string taskId)
There was a problem hiding this comment.
Done in commit 74a6622. Inlined Throw.IfNullOrWhitespace calls within the object initializers, reducing both methods to lambda-style expression bodies.
Co-authored-by: westey-m <164392973+westey-m@users.noreply.github.com>
Motivation and Context
A2AAgent sessions track both
ContextId(conversation) andTaskId(current task), butCreateSessionAsynconly acceptedcontextId, preventing session resumption from a specific task.Description
Added
CreateSessionAsync(string contextId, string taskId)overload to enable resuming sessions with both conversation and task context. Both overloads use expression-bodied members with inlined parameter validation for a concise implementation.Changes:
A2AAgentSessionwith both IDs setThrow.IfNullOrWhitespacecalls within object initializersCreateSessionAsync(string contextId)overload unchanged in functionalityExample:
Implementation:
Contribution Checklist
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.