Skip to content

Commit 9c1b2f9

Browse files
.NET: Annotate all public methods of OpenAIAssistantClientExtensions with Obsolete attribute (#2640)
* Initial plan * Add Obsolete attribute to all public methods of OpenAIAssistantClientExtensions Co-authored-by: SergeyMenshykh <[email protected]> * Add pragma warning disable CS0618 to files using deprecated OpenAI Assistants API Co-authored-by: SergeyMenshykh <[email protected]> * Update Obsolete attribute message to use requested text Co-authored-by: SergeyMenshykh <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: SergeyMenshykh <[email protected]>
1 parent 51721bd commit 9c1b2f9

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

dotnet/samples/GettingStarted/AgentProviders/Agent_With_OpenAIAssistants/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// WARNING: The Assistants API is deprecated and will be shut down.
66
// For more information see the OpenAI documentation: https://platform.openai.com/docs/assistants/migration
77

8+
#pragma warning disable CS0618 // Type or member is obsolete - OpenAI Assistants API is deprecated but still used in this sample
9+
810
using Microsoft.Agents.AI;
911
using OpenAI;
1012

dotnet/src/Microsoft.Agents.AI.OpenAI/Extensions/OpenAIAssistantClientExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public static class OpenAIAssistantClientExtensions
3030
/// <param name="clientFactory">Provides a way to customize the creation of the underlying <see cref="IChatClient"/> used by the agent.</param>
3131
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
3232
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the assistant.</returns>
33+
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
3334
public static ChatClientAgent GetAIAgent(
3435
this AssistantClient assistantClient,
3536
ClientResult<Assistant> assistantClientResult,
@@ -54,6 +55,7 @@ public static ChatClientAgent GetAIAgent(
5455
/// <param name="clientFactory">Provides a way to customize the creation of the underlying <see cref="IChatClient"/> used by the agent.</param>
5556
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
5657
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the assistant.</returns>
58+
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
5759
public static ChatClientAgent GetAIAgent(
5860
this AssistantClient assistantClient,
5961
Assistant assistantMetadata,
@@ -102,6 +104,7 @@ public static ChatClientAgent GetAIAgent(
102104
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
103105
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
104106
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the assistant agent.</returns>
107+
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
105108
public static ChatClientAgent GetAIAgent(
106109
this AssistantClient assistantClient,
107110
string agentId,
@@ -134,6 +137,7 @@ public static ChatClientAgent GetAIAgent(
134137
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
135138
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
136139
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the assistant agent.</returns>
140+
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
137141
public static async Task<ChatClientAgent> GetAIAgentAsync(
138142
this AssistantClient assistantClient,
139143
string agentId,
@@ -166,6 +170,7 @@ public static async Task<ChatClientAgent> GetAIAgentAsync(
166170
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
167171
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the assistant.</returns>
168172
/// <exception cref="ArgumentNullException"><paramref name="assistantClientResult"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
173+
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
169174
public static ChatClientAgent GetAIAgent(
170175
this AssistantClient assistantClient,
171176
ClientResult<Assistant> assistantClientResult,
@@ -191,6 +196,7 @@ public static ChatClientAgent GetAIAgent(
191196
/// <param name="services">An optional <see cref="IServiceProvider"/> to use for resolving services required by the <see cref="AIFunction"/> instances being invoked.</param>
192197
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the assistant.</returns>
193198
/// <exception cref="ArgumentNullException"><paramref name="assistantMetadata"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
199+
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
194200
public static ChatClientAgent GetAIAgent(
195201
this AssistantClient assistantClient,
196202
Assistant assistantMetadata,
@@ -252,6 +258,7 @@ public static ChatClientAgent GetAIAgent(
252258
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the assistant agent.</returns>
253259
/// <exception cref="ArgumentNullException"><paramref name="assistantClient"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
254260
/// <exception cref="ArgumentException"><paramref name="agentId"/> is empty or whitespace.</exception>
261+
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
255262
public static ChatClientAgent GetAIAgent(
256263
this AssistantClient assistantClient,
257264
string agentId,
@@ -291,6 +298,7 @@ public static ChatClientAgent GetAIAgent(
291298
/// <returns>A <see cref="ChatClientAgent"/> instance that can be used to perform operations on the assistant agent.</returns>
292299
/// <exception cref="ArgumentNullException"><paramref name="assistantClient"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
293300
/// <exception cref="ArgumentException"><paramref name="agentId"/> is empty or whitespace.</exception>
301+
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
294302
public static async Task<ChatClientAgent> GetAIAgentAsync(
295303
this AssistantClient assistantClient,
296304
string agentId,
@@ -333,6 +341,7 @@ public static async Task<ChatClientAgent> GetAIAgentAsync(
333341
/// <returns>An <see cref="ChatClientAgent"/> instance backed by the OpenAI Assistant service.</returns>
334342
/// <exception cref="ArgumentNullException">Thrown when <paramref name="client"/> or <paramref name="model"/> is <see langword="null"/>.</exception>
335343
/// <exception cref="ArgumentException">Thrown when <paramref name="model"/> is empty or whitespace.</exception>
344+
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
336345
public static ChatClientAgent CreateAIAgent(
337346
this AssistantClient client,
338347
string model,
@@ -371,6 +380,7 @@ public static ChatClientAgent CreateAIAgent(
371380
/// <returns>An <see cref="ChatClientAgent"/> instance backed by the OpenAI Assistant service.</returns>
372381
/// <exception cref="ArgumentNullException">Thrown when <paramref name="client"/> or <paramref name="model"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
373382
/// <exception cref="ArgumentException">Thrown when <paramref name="model"/> is empty or whitespace.</exception>
383+
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
374384
public static ChatClientAgent CreateAIAgent(
375385
this AssistantClient client,
376386
string model,
@@ -437,6 +447,7 @@ public static ChatClientAgent CreateAIAgent(
437447
/// <returns>An <see cref="ChatClientAgent"/> instance backed by the OpenAI Assistant service.</returns>
438448
/// <exception cref="ArgumentNullException">Thrown when <paramref name="client"/> or <paramref name="model"/> is <see langword="null"/>.</exception>
439449
/// <exception cref="ArgumentException">Thrown when <paramref name="model"/> is empty or whitespace.</exception>
450+
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
440451
public static async Task<ChatClientAgent> CreateAIAgentAsync(
441452
this AssistantClient client,
442453
string model,
@@ -477,6 +488,7 @@ await client.CreateAIAgentAsync(model,
477488
/// <returns>An <see cref="ChatClientAgent"/> instance backed by the OpenAI Assistant service.</returns>
478489
/// <exception cref="ArgumentNullException">Thrown when <paramref name="client"/> or <paramref name="model"/> is <see langword="null"/>.</exception>
479490
/// <exception cref="ArgumentException">Thrown when <paramref name="model"/> is empty or whitespace.</exception>
491+
[Obsolete("The Assistants API has been deprecated. Please use the Responses API instead.")]
480492
public static async Task<ChatClientAgent> CreateAIAgentAsync(
481493
this AssistantClient client,
482494
string model,

dotnet/tests/Microsoft.Agents.AI.OpenAI.UnitTests/Extensions/OpenAIAssistantClientExtensionsTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

3+
#pragma warning disable CS0618 // Type or member is obsolete - This is intentional as we are testing deprecated methods
4+
35
using System;
46
using System.ClientModel;
57
using System.ClientModel.Primitives;

dotnet/tests/OpenAIAssistant.IntegrationTests/OpenAIAssistantClientExtensionsTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

3+
#pragma warning disable CS0618 // Type or member is obsolete - Testing deprecated OpenAI Assistants API extension methods
4+
35
using System;
46
using System.Diagnostics;
57
using System.IO;

0 commit comments

Comments
 (0)