Skip to content

.Net: Remove returned id from AgentThread.Create to support responses #11125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dotnet/src/Agents/Abstractions/AgentInvokeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.SemanticKernel.Agents;
/// <summary>
/// Optional parameters for agent invocation.
/// </summary>
public class AgentInvokeOptions
public sealed class AgentInvokeOptions
{
/// <summary>
/// Gets or sets optional arguments to pass to the agent's invocation, including any <see cref="PromptExecutionSettings"/>
Expand Down
11 changes: 5 additions & 6 deletions dotnet/src/Agents/Abstractions/AgentThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public abstract class AgentThread
/// Creates the thread and returns the thread id.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
/// <returns>The id of the new thread.</returns>
public virtual async Task<string> CreateAsync(CancellationToken cancellationToken = default)
/// <returns>A task that completes when the thread has been created.</returns>
public virtual async Task CreateAsync(CancellationToken cancellationToken = default)
{
if (this.IsDeleted)
{
Expand All @@ -40,11 +40,10 @@ public virtual async Task<string> CreateAsync(CancellationToken cancellationToke

if (this.Id is not null)
{
return this.Id;
return;
}

this.Id = await this.CreateInternalAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
return this.Id;
}

/// <summary>
Expand Down Expand Up @@ -98,8 +97,8 @@ public virtual async Task OnNewMessageAsync(ChatMessageContent newMessage, Cance
/// Checks have already been completed in the <see cref="CreateAsync"/> method to ensure that the thread can be created.
/// </summary>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
/// <returns>The id of the thread that was created.</returns>
protected abstract Task<string> CreateInternalAsync(CancellationToken cancellationToken);
/// <returns>The id of the thread that was created if one is available.</returns>
protected abstract Task<string?> CreateInternalAsync(CancellationToken cancellationToken);

/// <summary>
/// Deletes the current thread.
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/Agents/AzureAI/AzureAIAgentThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public AzureAIAgentThread(AgentsClient client, string id)
}

/// <inheritdoc />
protected async override Task<string> CreateInternalAsync(CancellationToken cancellationToken)
protected async override Task<string?> CreateInternalAsync(CancellationToken cancellationToken)
{
const string ErrorMessage = "The thread could not be created due to an error response from the service.";

Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/Agents/Core/ChatHistoryAgentThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public ChatHistoryAgentThread(ChatHistory chatHistory, string? id = null)
}

/// <inheritdoc />
protected override Task<string> CreateInternalAsync(CancellationToken cancellationToken)
protected override Task<string?> CreateInternalAsync(CancellationToken cancellationToken)
{
return Task.FromResult(Guid.NewGuid().ToString("N"));
return Task.FromResult<string?>(Guid.NewGuid().ToString("N"));
}

/// <inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/Agents/OpenAI/OpenAIAssistantAgentThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public OpenAIAssistantAgentThread(AssistantClient client, string id)
}

/// <inheritdoc />
protected async override Task<string> CreateInternalAsync(CancellationToken cancellationToken)
protected async override Task<string?> CreateInternalAsync(CancellationToken cancellationToken)
{
const string ErrorMessage = "The thread could not be created due to an error response from the service.";

Expand Down
Loading