Skip to content

.NET: Add Missing CreateSessionAsync(conversationId) to FoundryAgent#5144

Merged
rogerbarreto merged 1 commit intomicrosoft:mainfrom
rogerbarreto:issues/5138-add-createsession-conversation-id
Apr 7, 2026
Merged

.NET: Add Missing CreateSessionAsync(conversationId) to FoundryAgent#5144
rogerbarreto merged 1 commit intomicrosoft:mainfrom
rogerbarreto:issues/5138-add-createsession-conversation-id

Conversation

@rogerbarreto
Copy link
Copy Markdown
Member

@rogerbarreto rogerbarreto commented Apr 7, 2026

Motivation and Context

Users who already have a server-side conversation ID (e.g., created via \ProjectConversationsClient) cannot pass it to \FoundryAgent.CreateSessionAsync\ because the overload accepting a \conversationId\ parameter only exists on \ChatClientAgent.

Description

Adds a public \CreateSessionAsync(string conversationId, CancellationToken)\ method to \FoundryAgent\ that delegates to the inner \ChatClientAgent, allowing users to create sessions with existing server-side conversation IDs directly from the \FoundryAgent\ type.

Usage

\\csharp
// Create or obtain an existing conversation ID
ProjectConversation conversation = await conversationsClient.CreateProjectConversationAsync();

// Now directly usable on FoundryAgent
AgentSession session = await foundryAgent.CreateSessionAsync(conversation.Id);
\\

Changes

  • **\FoundryAgent.cs**: Added \CreateSessionAsync(string conversationId, CancellationToken)\ that delegates to ((ChatClientAgent)this.InnerAgent).CreateSessionAsync(conversationId, cancellationToken)\
  • **\FoundryAgentTests.cs**: Added 2 unit tests covering the new method and the parameterless overload

Checklist

  • dotnet format passes (verified via Docker \mcr.microsoft.com/dotnet/sdk:10.0)
  • All 310 existing + new tests pass on both
    et48\ and
    et10.0\

Adds a public CreateSessionAsync(string conversationId, CancellationToken)
method to FoundryAgent that delegates to the inner ChatClientAgent,
allowing users to create sessions with existing server-side conversation IDs.

Fixes microsoft#5138
Copilot AI review requested due to automatic review settings April 7, 2026 10:51
@moonbox3 moonbox3 added the .NET label Apr 7, 2026
@rogerbarreto rogerbarreto self-assigned this Apr 7, 2026
@rogerbarreto rogerbarreto moved this to In Review in Agent Framework Apr 7, 2026
@rogerbarreto rogerbarreto enabled auto-merge April 7, 2026 10:54
@rogerbarreto rogerbarreto changed the title .NET: Add CreateSessionAsync(conversationId) to FoundryAgent .NET: Add Missing CreateSessionAsync(conversationId) to FoundryAgent Apr 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a FoundryAgent.CreateSessionAsync(string conversationId, CancellationToken) convenience overload so callers can resume/attach to an existing server-side Foundry conversation without needing to downcast or access the inner ChatClientAgent.

Changes:

  • Add FoundryAgent.CreateSessionAsync(string conversationId, CancellationToken) that delegates to the inner ChatClientAgent.
  • Add unit tests asserting the returned session type and that ConversationId is set (or null for the parameterless overload).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
dotnet/src/Microsoft.Agents.AI.Foundry/FoundryAgent.cs Adds CreateSessionAsync(conversationId) overload delegating to the inner ChatClientAgent.
dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/FoundryAgentTests.cs Adds unit tests for creating sessions with/without a conversation ID.

@rogerbarreto rogerbarreto added this pull request to the merge queue Apr 7, 2026
Merged via the queue into microsoft:main with commit 4134c74 Apr 7, 2026
26 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in Agent Framework Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: MS Foundry Agent Multi Turn Conversations with existing Foundry Agents

5 participants