diff --git a/sdk/ai/Azure.AI.Client/Azure.AI.Client.sln b/sdk/ai/Azure.AI.Client/Azure.AI.Client.sln
new file mode 100644
index 000000000000..991bcddfdc86
--- /dev/null
+++ b/sdk/ai/Azure.AI.Client/Azure.AI.Client.sln
@@ -0,0 +1,56 @@
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29709.97
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{ECC730C1-4AEA-420C-916A-66B19B79E4DC}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.AI.Client", "src\Azure.AI.Client.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.AI.Client.Tests", "tests\Azure.AI.Client.Tests.csproj", "{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU
+ {ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {ECC730C1-4AEA-420C-916A-66B19B79E4DC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}
+ EndGlobalSection
+EndGlobal
diff --git a/sdk/ai/Azure.AI.Client/CHANGELOG.md b/sdk/ai/Azure.AI.Client/CHANGELOG.md
new file mode 100644
index 000000000000..13dd08af78ab
--- /dev/null
+++ b/sdk/ai/Azure.AI.Client/CHANGELOG.md
@@ -0,0 +1,11 @@
+# Release History
+
+## 1.0.0-beta.1 (Unreleased)
+
+### Features Added
+
+### Breaking Changes
+
+### Bugs Fixed
+
+### Other Changes
diff --git a/sdk/ai/Azure.AI.Client/Directory.Build.props b/sdk/ai/Azure.AI.Client/Directory.Build.props
new file mode 100644
index 000000000000..63bd836ad44b
--- /dev/null
+++ b/sdk/ai/Azure.AI.Client/Directory.Build.props
@@ -0,0 +1,6 @@
+
+
+
+
diff --git a/sdk/ai/Azure.AI.Client/README.md b/sdk/ai/Azure.AI.Client/README.md
new file mode 100644
index 000000000000..487c3a2a5a7f
--- /dev/null
+++ b/sdk/ai/Azure.AI.Client/README.md
@@ -0,0 +1,107 @@
+# Azure.AI.Client client library for .NET
+
+Azure.AI.Client is a managed service that helps developers get secret simply and securely.
+
+Use the client library for to:
+
+* [Get secret](https://docs.microsoft.com/azure)
+
+[Source code][source_root] | [Package (NuGet)][package] | [API reference documentation][reference_docs] | [Product documentation][azconfig_docs] | [Samples][source_samples]
+
+ [Source code](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/ai/Azure.AI.Client/src) | [Package (NuGet)](https://www.nuget.org/packages) | [API reference documentation](https://azure.github.io/azure-sdk-for-net) | [Product documentation](https://docs.microsoft.com/azure)
+
+## Getting started
+
+This section should include everything a developer needs to do to install and create their first client connection *very quickly*.
+
+### Install the package
+
+First, provide instruction for obtaining and installing the package or library. This section might include only a single line of code, like `dotnet add package package-name`, but should enable a developer to successfully install the package from NuGet, npm, or even cloning a GitHub repository.
+
+Install the client library for .NET with [NuGet](https://www.nuget.org/ ):
+
+```dotnetcli
+dotnet add package Azure.AI.Client --prerelease
+```
+
+### Prerequisites
+
+Include a section after the install command that details any requirements that must be satisfied before a developer can [authenticate](#authenticate-the-client) and test all of the snippets in the [Examples](#examples) section. For example, for Cosmos DB:
+
+> You must have an [Azure subscription](https://azure.microsoft.com/free/dotnet/) and [Cosmos DB account](https://docs.microsoft.com/azure/cosmos-db/account-overview) (SQL API). In order to take advantage of the C# 8.0 syntax, it is recommended that you compile using the [.NET Core SDK](https://dotnet.microsoft.com/download) 3.0 or higher with a [language version](https://docs.microsoft.com/dotnet/csharp/language-reference/configure-language-version#override-a-default) of `latest`. It is also possible to compile with the .NET Core SDK 2.1.x using a language version of `preview`.
+
+### Authenticate the client
+
+If your library requires authentication for use, such as for Azure services, include instructions and example code needed for initializing and authenticating.
+
+For example, include details on obtaining an account key and endpoint URI, setting environment variables for each, and initializing the client object.
+
+### Service API versions
+
+The client library targets the latest service API version by default. A client instance accepts an optional service API version parameter from its options to specify which API version service to communicate.
+
+#### Select a service API version
+
+You have the flexibility to explicitly select a supported service API version when instantiating a client by configuring its associated options. This ensures that the client can communicate with services using the specified API version.
+
+For example,
+
+```C# Snippet:CreateClientForSpecificApiVersion
+Uri endpoint = new Uri("");
+DefaultAzureCredential credential = new DefaultAzureCredential();
+ClientOptions options = new ClientOptions(ClientOptions.ServiceVersion.)
+var client = new Client(endpoint, credential, options);
+```
+
+When selecting an API version, it's important to verify that there are no breaking changes compared to the latest API version. If there are significant differences, API calls may fail due to incompatibility.
+
+Always ensure that the chosen API version is fully supported and operational for your specific use case and that it aligns with the service's versioning policy.
+
+## Key concepts
+
+The *Key concepts* section should describe the functionality of the main classes. Point out the most important and useful classes in the package (with links to their reference pages) and explain how those classes work together. Feel free to use bulleted lists, tables, code blocks, or even diagrams for clarity.
+
+Include the *Thread safety* and *Additional concepts* sections below at the end of your *Key concepts* section. You may remove or add links depending on what your library makes use of:
+
+### Thread safety
+
+We guarantee that all client instance methods are thread-safe and independent of each other ([guideline](https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-service-methods-thread-safety)). This ensures that the recommendation of reusing client instances is always safe, even across threads.
+
+### Additional concepts
+
+[Client options](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#configuring-service-clients-using-clientoptions) |
+[Accessing the response](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#accessing-http-response-details-using-responset) |
+[Long-running operations](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#consuming-long-running-operations-using-operationt) |
+[Handling failures](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#reporting-errors-requestfailedexception) |
+[Diagnostics](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/Diagnostics.md) |
+[Mocking](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md#mocking) |
+[Client lifetime](https://devblogs.microsoft.com/azure-sdk/lifetime-management-and-thread-safety-guarantees-of-azure-sdk-net-clients/)
+
+
+## Examples
+
+You can familiarize yourself with different APIs using [Samples](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/ai/Azure.AI.Client/samples).
+
+## Troubleshooting
+
+Describe common errors and exceptions, how to "unpack" them if necessary, and include guidance for graceful handling and recovery.
+
+Provide information to help developers avoid throttling or other service-enforced errors they might encounter. For example, provide guidance and examples for using retry or connection policies in the API.
+
+If the package or a related package supports it, include tips for logging or enabling instrumentation to help them debug their code.
+
+## Next steps
+
+* Provide a link to additional code examples, ideally to those sitting alongside the README in the package's `/samples` directory.
+* If appropriate, point users to other packages that might be useful.
+* If you think there's a good chance that developers might stumble across your package in error (because they're searching for specific functionality and mistakenly think the package provides that functionality), point them to the packages they might be looking for.
+
+## Contributing
+
+This is a template, but your SDK readme should include details on how to contribute code to the repo/package.
+
+
+[style-guide-msft]: https://docs.microsoft.com/style-guide/capitalization
+[style-guide-cloud]: https://aka.ms/azsdk/cloud-style-guide
+
+
diff --git a/sdk/ai/Azure.AI.Client/src/Azure.AI.Client.csproj b/sdk/ai/Azure.AI.Client/src/Azure.AI.Client.csproj
new file mode 100644
index 000000000000..dd506b512bc8
--- /dev/null
+++ b/sdk/ai/Azure.AI.Client/src/Azure.AI.Client.csproj
@@ -0,0 +1,19 @@
+
+
+ This is the Azure.AI.Client client library for developing .NET applications with rich experience.
+ Azure SDK Code Generation Azure.AI.Client for Azure Data Plane
+ 1.0.0-beta.1
+ Azure.AI.Client
+ $(RequiredTargetFrameworks)
+ true
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sdk/ai/Azure.AI.Client/src/Generated/AIClientClientBuilderExtensions.cs b/sdk/ai/Azure.AI.Client/src/Generated/AIClientClientBuilderExtensions.cs
new file mode 100644
index 000000000000..d6d21e07bf5e
--- /dev/null
+++ b/sdk/ai/Azure.AI.Client/src/Generated/AIClientClientBuilderExtensions.cs
@@ -0,0 +1,38 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using Azure.AI.Client;
+using Azure.Core.Extensions;
+
+namespace Microsoft.Extensions.Azure
+{
+ /// Extension methods to add to client builder.
+ public static partial class AIClientClientBuilderExtensions
+ {
+ /// Registers a instance.
+ /// The builder to register with.
+ /// The Azure AI Studio project endpoint, in the form `https://<azure-region>.api.azureml.ms` or `https://<private-link-guid>.<azure-region>.api.azureml.ms`, where <azure-region> is the Azure region where the project is deployed (e.g. westus) and <private-link-guid> is the GUID of the Enterprise private link.
+ /// The Azure subscription ID.
+ /// The name of the Azure Resource Group.
+ /// The Azure AI Studio project name.
+ public static IAzureClientBuilder AddAzureAIClient(this TBuilder builder, Uri endpoint, string subscriptionId, string resourceGroupName, string projectName)
+ where TBuilder : IAzureClientFactoryBuilderWithCredential
+ {
+ return builder.RegisterClientFactory((options, cred) => new AzureAIClient(endpoint, subscriptionId, resourceGroupName, projectName, cred, options));
+ }
+
+ /// Registers a instance.
+ /// The builder to register with.
+ /// The configuration values.
+ public static IAzureClientBuilder AddAzureAIClient(this TBuilder builder, TConfiguration configuration)
+ where TBuilder : IAzureClientFactoryBuilderWithConfiguration
+ {
+ return builder.RegisterClientFactory(configuration);
+ }
+ }
+}
diff --git a/sdk/ai/Azure.AI.Client/src/Generated/AIClientModelFactory.cs b/sdk/ai/Azure.AI.Client/src/Generated/AIClientModelFactory.cs
new file mode 100644
index 000000000000..7af317a16b76
--- /dev/null
+++ b/sdk/ai/Azure.AI.Client/src/Generated/AIClientModelFactory.cs
@@ -0,0 +1,1022 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+
+namespace Azure.AI.Client.Models
+{
+ /// Model factory for models.
+ public static partial class AIClientModelFactory
+ {
+ /// Initializes a new instance of .
+ /// Identifier of the evaluation.
+ ///
+ /// Data for evaluation.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include and .
+ ///
+ /// Display Name for evaluation. It helps to find evaluation easily in AI Studio. It does not need to be unique.
+ /// Description of the evaluation. It can be used to store additional information about the evaluation and is mutable.
+ /// Metadata containing createdBy and modifiedBy information.
+ /// Status of the evaluation. It is set by service and is read-only.
+ /// Evaluation's tags. Unlike properties, tags are fully mutable.
+ /// Evaluation's properties. Unlike tags, properties are add-only. Once added, a property cannot be removed.
+ /// Evaluators to be used for the evaluation.
+ /// A new instance for mocking.
+ public static Evaluation Evaluation(string id = null, InputData data = null, string displayName = null, string description = null, SystemData systemData = null, string status = null, IDictionary tags = null, IDictionary properties = null, IDictionary evaluators = null)
+ {
+ tags ??= new Dictionary();
+ properties ??= new Dictionary();
+ evaluators ??= new Dictionary();
+
+ return new Evaluation(
+ id,
+ data,
+ displayName,
+ description,
+ systemData,
+ status,
+ tags,
+ properties,
+ evaluators,
+ serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The timestamp the resource was created at.
+ /// The identity that created the resource.
+ /// The identity type that created the resource.
+ /// The timestamp of resource last modification (UTC).
+ /// A new instance for mocking.
+ public static SystemData SystemData(DateTimeOffset? createdAt = null, string createdBy = null, string createdByType = null, DateTimeOffset? lastModifiedAt = null)
+ {
+ return new SystemData(createdAt, createdBy, createdByType, lastModifiedAt, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// Identifier of the evaluation.
+ ///
+ /// Data for evaluation.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include and .
+ ///
+ /// Display Name for evaluation. It helps to find evaluation easily in AI Studio. It does not need to be unique.
+ /// Description of the evaluation. It can be used to store additional information about the evaluation and is mutable.
+ /// Metadata containing createdBy and modifiedBy information.
+ /// Status of the evaluation. It is set by service and is read-only.
+ /// Evaluation's tags. Unlike properties, tags are fully mutable.
+ /// Evaluation's properties. Unlike tags, properties are add-only. Once added, a property cannot be removed.
+ /// Evaluators to be used for the evaluation.
+ ///
+ /// Trigger for the evaluation.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include and .
+ ///
+ /// Sampling strategy for the evaluation.
+ /// A new instance for mocking.
+ public static EvaluationSchedule EvaluationSchedule(string id = null, InputData data = null, string displayName = null, string description = null, SystemData systemData = null, string provisioningStatus = null, IDictionary tags = null, IDictionary properties = null, IDictionary evaluators = null, Trigger trigger = null, SamplingStrategy samplingStrategy = null)
+ {
+ tags ??= new Dictionary();
+ properties ??= new Dictionary();
+ evaluators ??= new Dictionary();
+
+ return new EvaluationSchedule(
+ id,
+ data,
+ displayName,
+ description,
+ systemData,
+ provisioningStatus,
+ tags,
+ properties,
+ evaluators,
+ trigger,
+ samplingStrategy,
+ serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The identifier, which can be referenced in API endpoints.
+ /// The object type, which is always assistant.
+ /// The Unix timestamp, in seconds, representing when this object was created.
+ /// The name of the agent.
+ /// The description of the agent.
+ /// The ID of the model to use.
+ /// The system instructions for the agent to use.
+ ///
+ /// The collection of tools enabled for the agent.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include , , , , , and .
+ ///
+ ///
+ /// A set of resources that are used by the agent's tools. The resources are specific to the type of tool. For example, the `code_interpreter`
+ /// tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs.
+ ///
+ ///
+ /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random,
+ /// while lower values like 0.2 will make it more focused and deterministic.
+ ///
+ ///
+ /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.
+ /// So 0.1 means only the tokens comprising the top 10% probability mass are considered.
+ ///
+ /// We generally recommend altering this or temperature but not both.
+ ///
+ /// The response format of the tool calls used by this agent.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// A new instance for mocking.
+ public static Agent Agent(string id = null, AgentObject @object = default, DateTimeOffset createdAt = default, string name = null, string description = null, string model = null, string instructions = null, IEnumerable tools = null, ToolResources toolResources = null, float? temperature = null, float? topP = null, BinaryData responseFormat = null, IReadOnlyDictionary metadata = null)
+ {
+ tools ??= new List();
+ metadata ??= new Dictionary();
+
+ return new Agent(
+ id,
+ @object,
+ createdAt,
+ name,
+ description,
+ model,
+ instructions,
+ tools?.ToList(),
+ toolResources,
+ temperature,
+ topP,
+ responseFormat,
+ metadata,
+ serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ ///
+ /// The role of the entity that is creating the message. Allowed values include:
+ /// - `user`: Indicates the message is sent by an actual user and should be used in most cases to represent user-generated messages.
+ /// - `assistant`: Indicates the message is generated by the agent. Use this value to insert messages from the agent into
+ /// the conversation.
+ ///
+ ///
+ /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via
+ /// a separate call to the create message API.
+ ///
+ /// A list of files attached to the message, and the tools they should be added to.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// A new instance for mocking.
+ public static ThreadMessageOptions ThreadMessageOptions(MessageRole role = default, string content = null, IEnumerable attachments = null, IDictionary metadata = null)
+ {
+ attachments ??= new List();
+ metadata ??= new Dictionary();
+
+ return new ThreadMessageOptions(role, content, attachments?.ToList(), metadata, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The identifier, which can be referenced in API endpoints.
+ /// The object type, which is always 'thread'.
+ /// The Unix timestamp, in seconds, representing when this object was created.
+ ///
+ /// A set of resources that are made available to the agent's tools in this thread. The resources are specific to the type
+ /// of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list
+ /// of vector store IDs.
+ ///
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// A new instance for mocking.
+ public static AgentThread AgentThread(string id = null, AgentThreadObject @object = default, DateTimeOffset createdAt = default, ToolResources toolResources = null, IReadOnlyDictionary metadata = null)
+ {
+ metadata ??= new Dictionary();
+
+ return new AgentThread(
+ id,
+ @object,
+ createdAt,
+ toolResources,
+ metadata,
+ serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The identifier, which can be referenced in API endpoints.
+ /// The object type, which is always 'thread.message'.
+ /// The Unix timestamp, in seconds, representing when this object was created.
+ /// The ID of the thread that this message belongs to.
+ /// The status of the message.
+ /// On an incomplete message, details about why the message is incomplete.
+ /// The Unix timestamp (in seconds) for when the message was completed.
+ /// The Unix timestamp (in seconds) for when the message was marked as incomplete.
+ /// The role associated with the agent thread message.
+ ///
+ /// The list of content items associated with the agent thread message.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include and .
+ ///
+ /// If applicable, the ID of the agent that authored this message.
+ /// If applicable, the ID of the run associated with the authoring of this message.
+ /// A list of files attached to the message, and the tools they were added to.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// A new instance for mocking.
+ public static ThreadMessage ThreadMessage(string id = null, ThreadMessageObject @object = default, DateTimeOffset createdAt = default, string threadId = null, MessageStatus status = default, MessageIncompleteDetails incompleteDetails = null, DateTimeOffset? completedAt = null, DateTimeOffset? incompleteAt = null, MessageRole role = default, IEnumerable contentItems = null, string assistantId = null, string runId = null, IEnumerable attachments = null, IDictionary metadata = null)
+ {
+ contentItems ??= new List();
+ attachments ??= new List();
+ metadata ??= new Dictionary();
+
+ return new ThreadMessage(
+ id,
+ @object,
+ createdAt,
+ threadId,
+ status,
+ incompleteDetails,
+ completedAt,
+ incompleteAt,
+ role,
+ contentItems?.ToList(),
+ assistantId,
+ runId,
+ attachments?.ToList(),
+ metadata,
+ serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The identifier, which can be referenced in API endpoints.
+ /// The object type, which is always 'thread.run'.
+ /// The ID of the thread associated with this run.
+ /// The ID of the agent associated with the thread this run was performed against.
+ /// The status of the agent thread run.
+ ///
+ /// The details of the action required for the agent thread run to continue.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include .
+ ///
+ /// The last error, if any, encountered by this agent thread run.
+ /// The ID of the model to use.
+ /// The overridden system instructions used for this agent thread run.
+ ///
+ /// The overridden enabled tools used for this agent thread run.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include , , , , , and .
+ ///
+ /// The Unix timestamp, in seconds, representing when this object was created.
+ /// The Unix timestamp, in seconds, representing when this item expires.
+ /// The Unix timestamp, in seconds, representing when this item was started.
+ /// The Unix timestamp, in seconds, representing when this completed.
+ /// The Unix timestamp, in seconds, representing when this was cancelled.
+ /// The Unix timestamp, in seconds, representing when this failed.
+ /// Details on why the run is incomplete. Will be `null` if the run is not incomplete.
+ /// Usage statistics related to the run. This value will be `null` if the run is not in a terminal state (i.e. `in_progress`, `queued`, etc.).
+ /// The sampling temperature used for this run. If not set, defaults to 1.
+ /// The nucleus sampling value used for this run. If not set, defaults to 1.
+ /// The maximum number of prompt tokens specified to have been used over the course of the run.
+ /// The maximum number of completion tokens specified to have been used over the course of the run.
+ /// The strategy to use for dropping messages as the context windows moves forward.
+ /// Controls whether or not and which tool is called by the model.
+ /// The response format of the tool calls used in this run.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// Override the tools the agent can use for this run. This is useful for modifying the behavior on a per-run basis.
+ /// Determines if tools can be executed in parallel within the run.
+ /// A new instance for mocking.
+ public static ThreadRun ThreadRun(string id = null, ThreadRunObject @object = default, string threadId = null, string assistantId = null, RunStatus status = default, RequiredAction requiredAction = null, RunError lastError = null, string model = null, string instructions = null, IEnumerable tools = null, DateTimeOffset createdAt = default, DateTimeOffset? expiresAt = null, DateTimeOffset? startedAt = null, DateTimeOffset? completedAt = null, DateTimeOffset? cancelledAt = null, DateTimeOffset? failedAt = null, IncompleteRunDetails? incompleteDetails = null, RunCompletionUsage usage = null, float? temperature = null, float? topP = null, int? maxPromptTokens = null, int? maxCompletionTokens = null, TruncationObject truncationStrategy = null, BinaryData toolChoice = null, BinaryData responseFormat = null, IReadOnlyDictionary metadata = null, UpdateToolResourcesOptions toolResources = null, bool? parallelToolCalls = null)
+ {
+ tools ??= new List();
+ metadata ??= new Dictionary();
+
+ return new ThreadRun(
+ id,
+ @object,
+ threadId,
+ assistantId,
+ status,
+ requiredAction,
+ lastError,
+ model,
+ instructions,
+ tools?.ToList(),
+ createdAt,
+ expiresAt,
+ startedAt,
+ completedAt,
+ cancelledAt,
+ failedAt,
+ incompleteDetails,
+ usage,
+ temperature,
+ topP,
+ maxPromptTokens,
+ maxCompletionTokens,
+ truncationStrategy,
+ toolChoice,
+ responseFormat,
+ metadata,
+ toolResources,
+ parallelToolCalls,
+ serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The object type for the required tool call.
+ /// The ID of the tool call. This ID must be referenced when submitting tool outputs.
+ /// A new instance for mocking.
+ public static RequiredToolCall RequiredToolCall(string type = null, string id = null)
+ {
+ return new UnknownRequiredToolCall(type, id, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The status for the error.
+ /// The human-readable text associated with the error.
+ /// A new instance for mocking.
+ public static RunError RunError(string code = null, string message = null)
+ {
+ return new RunError(code, message, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// Number of completion tokens used over the course of the run.
+ /// Number of prompt tokens used over the course of the run.
+ /// Total number of tokens used (prompt + completion).
+ /// A new instance for mocking.
+ public static RunCompletionUsage RunCompletionUsage(long completionTokens = default, long promptTokens = default, long totalTokens = default)
+ {
+ return new RunCompletionUsage(completionTokens, promptTokens, totalTokens, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The identifier, which can be referenced in API endpoints.
+ /// The object type, which is always 'thread.run.step'.
+ /// The type of run step, which can be either message_creation or tool_calls.
+ /// The ID of the agent associated with the run step.
+ /// The ID of the thread that was run.
+ /// The ID of the run that this run step is a part of.
+ /// The status of this run step.
+ ///
+ /// The details for this run step.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include and .
+ ///
+ /// If applicable, information about the last error encountered by this run step.
+ /// The Unix timestamp, in seconds, representing when this object was created.
+ /// The Unix timestamp, in seconds, representing when this item expired.
+ /// The Unix timestamp, in seconds, representing when this completed.
+ /// The Unix timestamp, in seconds, representing when this was cancelled.
+ /// The Unix timestamp, in seconds, representing when this failed.
+ /// Usage statistics related to the run step. This value will be `null` while the run step's status is `in_progress`.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// A new instance for mocking.
+ public static RunStep RunStep(string id = null, RunStepObject @object = default, RunStepType type = default, string assistantId = null, string threadId = null, string runId = null, RunStepStatus status = default, RunStepDetails stepDetails = null, RunStepError lastError = null, DateTimeOffset createdAt = default, DateTimeOffset? expiredAt = null, DateTimeOffset? completedAt = null, DateTimeOffset? cancelledAt = null, DateTimeOffset? failedAt = null, RunStepCompletionUsage usage = null, IReadOnlyDictionary metadata = null)
+ {
+ metadata ??= new Dictionary();
+
+ return new RunStep(
+ id,
+ @object,
+ type,
+ assistantId,
+ threadId,
+ runId,
+ status,
+ stepDetails,
+ lastError,
+ createdAt,
+ expiredAt,
+ completedAt,
+ cancelledAt,
+ failedAt,
+ usage,
+ metadata,
+ serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// Information about the message creation associated with this run step.
+ /// A new instance for mocking.
+ public static RunStepMessageCreationDetails RunStepMessageCreationDetails(RunStepMessageCreationReference messageCreation = null)
+ {
+ return new RunStepMessageCreationDetails(RunStepType.MessageCreation, serializedAdditionalRawData: null, messageCreation);
+ }
+
+ /// Initializes a new instance of .
+ /// The ID of the message created by this run step.
+ /// A new instance for mocking.
+ public static RunStepMessageCreationReference RunStepMessageCreationReference(string messageId = null)
+ {
+ return new RunStepMessageCreationReference(messageId, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ ///
+ /// A list of tool call details for this run step.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include , , , , , and .
+ ///
+ /// A new instance for mocking.
+ public static RunStepToolCallDetails RunStepToolCallDetails(IEnumerable toolCalls = null)
+ {
+ toolCalls ??= new List();
+
+ return new RunStepToolCallDetails(RunStepType.ToolCalls, serializedAdditionalRawData: null, toolCalls?.ToList());
+ }
+
+ /// Initializes a new instance of .
+ /// The object type.
+ /// The ID of the tool call. This ID must be referenced when you submit tool outputs.
+ /// A new instance for mocking.
+ public static RunStepToolCall RunStepToolCall(string type = null, string id = null)
+ {
+ return new UnknownRunStepToolCall(type, id, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The ID of the tool call. This ID must be referenced when you submit tool outputs.
+ /// Reserved for future use.
+ /// A new instance for mocking.
+ public static RunStepFileSearchToolCall RunStepFileSearchToolCall(string id = null, IReadOnlyDictionary fileSearch = null)
+ {
+ fileSearch ??= new Dictionary();
+
+ return new RunStepFileSearchToolCall("file_search", id, serializedAdditionalRawData: null, fileSearch);
+ }
+
+ /// Initializes a new instance of .
+ /// The ID of the tool call. This ID must be referenced when you submit tool outputs.
+ /// Reserved for future use.
+ /// A new instance for mocking.
+ public static RunStepBingSearchToolCall RunStepBingSearchToolCall(string id = null, IReadOnlyDictionary bingSearch = null)
+ {
+ bingSearch ??= new Dictionary();
+
+ return new RunStepBingSearchToolCall("bing_search", id, serializedAdditionalRawData: null, bingSearch);
+ }
+
+ /// Initializes a new instance of .
+ /// The ID of the tool call. This ID must be referenced when you submit tool outputs.
+ /// Reserved for future use.
+ /// A new instance for mocking.
+ public static RunStepAzureAISearchToolCall RunStepAzureAISearchToolCall(string id = null, IReadOnlyDictionary azureAISearch = null)
+ {
+ azureAISearch ??= new Dictionary();
+
+ return new RunStepAzureAISearchToolCall("azure_ai_search", id, serializedAdditionalRawData: null, azureAISearch);
+ }
+
+ /// Initializes a new instance of .
+ /// The ID of the tool call. This ID must be referenced when you submit tool outputs.
+ /// Reserved for future use.
+ /// A new instance for mocking.
+ public static RunStepSharepointToolCall RunStepSharepointToolCall(string id = null, IReadOnlyDictionary sharePoint = null)
+ {
+ sharePoint ??= new Dictionary();
+
+ return new RunStepSharepointToolCall("sharepoint", id, serializedAdditionalRawData: null, sharePoint);
+ }
+
+ /// Initializes a new instance of .
+ /// The ID of the tool call. This ID must be referenced when you submit tool outputs.
+ /// Reserved for future use.
+ /// A new instance for mocking.
+ public static RunStepMicrosoftFabricToolCall RunStepMicrosoftFabricToolCall(string id = null, IReadOnlyDictionary microsoftFabric = null)
+ {
+ microsoftFabric ??= new Dictionary();
+
+ return new RunStepMicrosoftFabricToolCall("microsoft_fabric", id, serializedAdditionalRawData: null, microsoftFabric);
+ }
+
+ /// Initializes a new instance of .
+ /// The error code for this error.
+ /// The human-readable text associated with this error.
+ /// A new instance for mocking.
+ public static RunStepError RunStepError(RunStepErrorCode code = default, string message = null)
+ {
+ return new RunStepError(code, message, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// Number of completion tokens used over the course of the run step.
+ /// Number of prompt tokens used over the course of the run step.
+ /// Total number of tokens used (prompt + completion).
+ /// A new instance for mocking.
+ public static RunStepCompletionUsage RunStepCompletionUsage(long completionTokens = default, long promptTokens = default, long totalTokens = default)
+ {
+ return new RunStepCompletionUsage(completionTokens, promptTokens, totalTokens, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The object type, which is always 'file'.
+ /// The identifier, which can be referenced in API endpoints.
+ /// The size of the file, in bytes.
+ /// The name of the file.
+ /// The Unix timestamp, in seconds, representing when this object was created.
+ /// The intended purpose of a file.
+ /// The state of the file. This field is available in Azure OpenAI only.
+ /// The error message with details in case processing of this file failed. This field is available in Azure OpenAI only.
+ /// A new instance for mocking.
+ public static OpenAIFile OpenAIFile(OpenAIFileObject @object = default, string id = null, int size = default, string filename = null, DateTimeOffset createdAt = default, OpenAIFilePurpose purpose = default, FileState? status = null, string statusDetails = null)
+ {
+ return new OpenAIFile(
+ @object,
+ id,
+ size,
+ filename,
+ createdAt,
+ purpose,
+ status,
+ statusDetails,
+ serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The content of the file, in bytes.
+ /// A new instance for mocking.
+ public static FileContentResponse FileContentResponse(BinaryData content = null)
+ {
+ return new FileContentResponse(content, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The object type, which is always list.
+ /// The requested list of items.
+ /// The first ID represented in this list.
+ /// The last ID represented in this list.
+ /// A value indicating whether there are additional values available not captured in this list.
+ /// A new instance for mocking.
+ public static OpenAIPageableListOfVectorStore OpenAIPageableListOfVectorStore(OpenAIPageableListOfVectorStoreObject @object = default, IEnumerable data = null, string firstId = null, string lastId = null, bool hasMore = default)
+ {
+ data ??= new List();
+
+ return new OpenAIPageableListOfVectorStore(
+ @object,
+ data?.ToList(),
+ firstId,
+ lastId,
+ hasMore,
+ serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The identifier, which can be referenced in API endpoints.
+ /// The object type, which is always `vector_store`.
+ /// The Unix timestamp (in seconds) for when the vector store was created.
+ /// The name of the vector store.
+ /// The total number of bytes used by the files in the vector store.
+ /// Files count grouped by status processed or being processed by this vector store.
+ /// The status of the vector store, which can be either `expired`, `in_progress`, or `completed`. A status of `completed` indicates that the vector store is ready for use.
+ /// Details on when this vector store expires.
+ /// The Unix timestamp (in seconds) for when the vector store will expire.
+ /// The Unix timestamp (in seconds) for when the vector store was last active.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// A new instance for mocking.
+ public static VectorStore VectorStore(string id = null, VectorStoreObject @object = default, DateTimeOffset createdAt = default, string name = null, int usageBytes = default, VectorStoreFileCount fileCounts = null, VectorStoreStatus status = default, VectorStoreExpirationPolicy expiresAfter = null, DateTimeOffset? expiresAt = null, DateTimeOffset? lastActiveAt = null, IReadOnlyDictionary metadata = null)
+ {
+ metadata ??= new Dictionary();
+
+ return new VectorStore(
+ id,
+ @object,
+ createdAt,
+ name,
+ usageBytes,
+ fileCounts,
+ status,
+ expiresAfter,
+ expiresAt,
+ lastActiveAt,
+ metadata,
+ serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The number of files that are currently being processed.
+ /// The number of files that have been successfully processed.
+ /// The number of files that have failed to process.
+ /// The number of files that were cancelled.
+ /// The total number of files.
+ /// A new instance for mocking.
+ public static VectorStoreFileCount VectorStoreFileCount(int inProgress = default, int completed = default, int failed = default, int cancelled = default, int total = default)
+ {
+ return new VectorStoreFileCount(
+ inProgress,
+ completed,
+ failed,
+ cancelled,
+ total,
+ serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The options for the static chunking strategy.
+ /// A new instance for mocking.
+ public static VectorStoreStaticChunkingStrategyRequest VectorStoreStaticChunkingStrategyRequest(VectorStoreStaticChunkingStrategyOptions @static = null)
+ {
+ return new VectorStoreStaticChunkingStrategyRequest(VectorStoreChunkingStrategyRequestType.Static, serializedAdditionalRawData: null, @static);
+ }
+
+ /// Initializes a new instance of .
+ /// The ID of the resource specified for deletion.
+ /// A value indicating whether deletion was successful.
+ /// The object type, which is always 'vector_store.deleted'.
+ /// A new instance for mocking.
+ public static VectorStoreDeletionStatus VectorStoreDeletionStatus(string id = null, bool deleted = default, VectorStoreDeletionStatusObject @object = default)
+ {
+ return new VectorStoreDeletionStatus(id, deleted, @object, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The object type, which is always list.
+ /// The requested list of items.
+ /// The first ID represented in this list.
+ /// The last ID represented in this list.
+ /// A value indicating whether there are additional values available not captured in this list.
+ /// A new instance for mocking.
+ public static OpenAIPageableListOfVectorStoreFile OpenAIPageableListOfVectorStoreFile(OpenAIPageableListOfVectorStoreFileObject @object = default, IEnumerable data = null, string firstId = null, string lastId = null, bool hasMore = default)
+ {
+ data ??= new List();
+
+ return new OpenAIPageableListOfVectorStoreFile(
+ @object,
+ data?.ToList(),
+ firstId,
+ lastId,
+ hasMore,
+ serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The identifier, which can be referenced in API endpoints.
+ /// The object type, which is always `vector_store.file`.
+ ///
+ /// The total vector store usage in bytes. Note that this may be different from the original file
+ /// size.
+ ///
+ /// The Unix timestamp (in seconds) for when the vector store file was created.
+ /// The ID of the vector store that the file is attached to.
+ /// The status of the vector store file, which can be either `in_progress`, `completed`, `cancelled`, or `failed`. The status `completed` indicates that the vector store file is ready for use.
+ /// The last error associated with this vector store file. Will be `null` if there are no errors.
+ ///
+ /// The strategy used to chunk the file.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include and .
+ ///
+ /// A new instance for mocking.
+ public static VectorStoreFile VectorStoreFile(string id = null, VectorStoreFileObject @object = default, int usageBytes = default, DateTimeOffset createdAt = default, string vectorStoreId = null, VectorStoreFileStatus status = default, VectorStoreFileError lastError = null, VectorStoreChunkingStrategyResponse chunkingStrategy = null)
+ {
+ return new VectorStoreFile(
+ id,
+ @object,
+ usageBytes,
+ createdAt,
+ vectorStoreId,
+ status,
+ lastError,
+ chunkingStrategy,
+ serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// One of `server_error` or `rate_limit_exceeded`.
+ /// A human-readable description of the error.
+ /// A new instance for mocking.
+ public static VectorStoreFileError VectorStoreFileError(VectorStoreFileErrorCode code = default, string message = null)
+ {
+ return new VectorStoreFileError(code, message, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The options for the static chunking strategy.
+ /// A new instance for mocking.
+ public static VectorStoreStaticChunkingStrategyResponse VectorStoreStaticChunkingStrategyResponse(VectorStoreStaticChunkingStrategyOptions @static = null)
+ {
+ return new VectorStoreStaticChunkingStrategyResponse(VectorStoreChunkingStrategyResponseType.Static, serializedAdditionalRawData: null, @static);
+ }
+
+ /// Initializes a new instance of .
+ /// The ID of the resource specified for deletion.
+ /// A value indicating whether deletion was successful.
+ /// The object type, which is always 'vector_store.deleted'.
+ /// A new instance for mocking.
+ public static VectorStoreFileDeletionStatus VectorStoreFileDeletionStatus(string id = null, bool deleted = default, VectorStoreFileDeletionStatusObject @object = default)
+ {
+ return new VectorStoreFileDeletionStatus(id, deleted, @object, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The identifier, which can be referenced in API endpoints.
+ /// The object type, which is always `vector_store.file_batch`.
+ /// The Unix timestamp (in seconds) for when the vector store files batch was created.
+ /// The ID of the vector store that the file is attached to.
+ /// The status of the vector store files batch, which can be either `in_progress`, `completed`, `cancelled` or `failed`.
+ /// Files count grouped by status processed or being processed by this vector store.
+ /// A new instance for mocking.
+ public static VectorStoreFileBatch VectorStoreFileBatch(string id = null, VectorStoreFileBatchObject @object = default, DateTimeOffset createdAt = default, string vectorStoreId = null, VectorStoreFileBatchStatus status = default, VectorStoreFileCount fileCounts = null)
+ {
+ return new VectorStoreFileBatch(
+ id,
+ @object,
+ createdAt,
+ vectorStoreId,
+ status,
+ fileCounts,
+ serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The identifier of the message, which can be referenced in API endpoints.
+ /// The object type, which is always `thread.message.delta`.
+ /// The delta containing the fields that have changed on the Message.
+ /// A new instance for mocking.
+ public static MessageDeltaChunk MessageDeltaChunk(string id = null, MessageDeltaChunkObject @object = default, MessageDelta delta = null)
+ {
+ return new MessageDeltaChunk(id, @object, delta, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The entity that produced the message.
+ ///
+ /// The content of the message as an array of text and/or images.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include and .
+ ///
+ /// A new instance for mocking.
+ public static MessageDelta MessageDelta(MessageRole role = default, IEnumerable content = null)
+ {
+ content ??= new List();
+
+ return new MessageDelta(role, content?.ToList(), serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the content part of the message.
+ /// The type of content for this content part.
+ /// A new instance for mocking.
+ public static MessageDeltaContent MessageDeltaContent(int index = default, string type = null)
+ {
+ return new UnknownMessageDeltaContent(index, type, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the content part of the message.
+ /// The image_file data.
+ /// A new instance for mocking.
+ public static MessageDeltaImageFileContent MessageDeltaImageFileContent(int index = default, MessageDeltaImageFileContentObject imageFile = null)
+ {
+ return new MessageDeltaImageFileContent(index, "image_file", serializedAdditionalRawData: null, imageFile);
+ }
+
+ /// Initializes a new instance of .
+ /// The file ID of the image in the message content.
+ /// A new instance for mocking.
+ public static MessageDeltaImageFileContentObject MessageDeltaImageFileContentObject(string fileId = null)
+ {
+ return new MessageDeltaImageFileContentObject(fileId, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the content part of the message.
+ /// The text content details.
+ /// A new instance for mocking.
+ public static MessageDeltaTextContent MessageDeltaTextContent(int index = default, MessageDeltaTextContentObject text = null)
+ {
+ return new MessageDeltaTextContent(index, "text", serializedAdditionalRawData: null, text);
+ }
+
+ /// Initializes a new instance of .
+ /// The data that makes up the text.
+ ///
+ /// Annotations for the text.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include and .
+ ///
+ /// A new instance for mocking.
+ public static MessageDeltaTextContentObject MessageDeltaTextContentObject(string value = null, IEnumerable annotations = null)
+ {
+ annotations ??= new List();
+
+ return new MessageDeltaTextContentObject(value, annotations?.ToList(), serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the annotation within a text content part.
+ /// The type of the text content annotation.
+ /// A new instance for mocking.
+ public static MessageDeltaTextAnnotation MessageDeltaTextAnnotation(int index = default, string type = null)
+ {
+ return new UnknownMessageDeltaTextAnnotation(index, type, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the annotation within a text content part.
+ /// The file citation information.
+ /// The text in the message content that needs to be replaced.
+ /// The start index of this annotation in the content text.
+ /// The end index of this annotation in the content text.
+ /// A new instance for mocking.
+ public static MessageDeltaTextFileCitationAnnotation MessageDeltaTextFileCitationAnnotation(int index = default, MessageDeltaTextFileCitationAnnotationObject fileCitation = null, string text = null, int? startIndex = null, int? endIndex = null)
+ {
+ return new MessageDeltaTextFileCitationAnnotation(
+ index,
+ "file_citation",
+ serializedAdditionalRawData: null,
+ fileCitation,
+ text,
+ startIndex,
+ endIndex);
+ }
+
+ /// Initializes a new instance of .
+ /// The ID of the specific file the citation is from.
+ /// The specific quote in the cited file.
+ /// A new instance for mocking.
+ public static MessageDeltaTextFileCitationAnnotationObject MessageDeltaTextFileCitationAnnotationObject(string fileId = null, string quote = null)
+ {
+ return new MessageDeltaTextFileCitationAnnotationObject(fileId, quote, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the annotation within a text content part.
+ /// The file path information.
+ /// The start index of this annotation in the content text.
+ /// The end index of this annotation in the content text.
+ /// The text in the message content that needs to be replaced.
+ /// A new instance for mocking.
+ public static MessageDeltaTextFilePathAnnotation MessageDeltaTextFilePathAnnotation(int index = default, MessageDeltaTextFilePathAnnotationObject filePath = null, int? startIndex = null, int? endIndex = null, string text = null)
+ {
+ return new MessageDeltaTextFilePathAnnotation(
+ index,
+ "file_path",
+ serializedAdditionalRawData: null,
+ filePath,
+ startIndex,
+ endIndex,
+ text);
+ }
+
+ /// Initializes a new instance of .
+ /// The file ID for the annotation.
+ /// A new instance for mocking.
+ public static MessageDeltaTextFilePathAnnotationObject MessageDeltaTextFilePathAnnotationObject(string fileId = null)
+ {
+ return new MessageDeltaTextFilePathAnnotationObject(fileId, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The identifier of the run step, which can be referenced in API endpoints.
+ /// The object type, which is always `thread.run.step.delta`.
+ /// The delta containing the fields that have changed on the run step.
+ /// A new instance for mocking.
+ public static RunStepDeltaChunk RunStepDeltaChunk(string id = null, RunStepDeltaChunkObject @object = default, RunStepDelta delta = null)
+ {
+ return new RunStepDeltaChunk(id, @object, delta, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ ///
+ /// The details of the run step.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include and .
+ ///
+ /// A new instance for mocking.
+ public static RunStepDelta RunStepDelta(RunStepDeltaDetail stepDetails = null)
+ {
+ return new RunStepDelta(stepDetails, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The message creation data.
+ /// A new instance for mocking.
+ public static RunStepDeltaMessageCreation RunStepDeltaMessageCreation(RunStepDeltaMessageCreationObject messageCreation = null)
+ {
+ return new RunStepDeltaMessageCreation("message_creation", serializedAdditionalRawData: null, messageCreation);
+ }
+
+ /// Initializes a new instance of .
+ /// The ID of the newly-created message.
+ /// A new instance for mocking.
+ public static RunStepDeltaMessageCreationObject RunStepDeltaMessageCreationObject(string messageId = null)
+ {
+ return new RunStepDeltaMessageCreationObject(messageId, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ ///
+ /// The collection of tool calls for the tool call detail item.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include , and .
+ ///
+ /// A new instance for mocking.
+ public static RunStepDeltaToolCallObject RunStepDeltaToolCallObject(IEnumerable toolCalls = null)
+ {
+ toolCalls ??= new List();
+
+ return new RunStepDeltaToolCallObject("tool_calls", serializedAdditionalRawData: null, toolCalls?.ToList());
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the tool call detail in the run step's tool_calls array.
+ /// The ID of the tool call, used when submitting outputs to the run.
+ /// The type of the tool call detail item in a streaming run step's details.
+ /// A new instance for mocking.
+ public static RunStepDeltaToolCall RunStepDeltaToolCall(int index = default, string id = null, string type = null)
+ {
+ return new UnknownRunStepDeltaToolCall(index, id, type, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the tool call detail in the run step's tool_calls array.
+ /// The ID of the tool call, used when submitting outputs to the run.
+ /// The function data for the tool call.
+ /// A new instance for mocking.
+ public static RunStepDeltaFunctionToolCall RunStepDeltaFunctionToolCall(int index = default, string id = null, RunStepDeltaFunction function = null)
+ {
+ return new RunStepDeltaFunctionToolCall(index, id, "function", serializedAdditionalRawData: null, function);
+ }
+
+ /// Initializes a new instance of .
+ /// The name of the function.
+ /// The arguments passed to the function as input.
+ /// The output of the function, null if outputs have not yet been submitted.
+ /// A new instance for mocking.
+ public static RunStepDeltaFunction RunStepDeltaFunction(string name = null, string arguments = null, string output = null)
+ {
+ return new RunStepDeltaFunction(name, arguments, output, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the tool call detail in the run step's tool_calls array.
+ /// The ID of the tool call, used when submitting outputs to the run.
+ /// Reserved for future use.
+ /// A new instance for mocking.
+ public static RunStepDeltaFileSearchToolCall RunStepDeltaFileSearchToolCall(int index = default, string id = null, IReadOnlyDictionary fileSearch = null)
+ {
+ fileSearch ??= new Dictionary();
+
+ return new RunStepDeltaFileSearchToolCall(index, id, "file_search", serializedAdditionalRawData: null, fileSearch);
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the tool call detail in the run step's tool_calls array.
+ /// The ID of the tool call, used when submitting outputs to the run.
+ /// The Code Interpreter data for the tool call.
+ /// A new instance for mocking.
+ public static RunStepDeltaCodeInterpreterToolCall RunStepDeltaCodeInterpreterToolCall(int index = default, string id = null, RunStepDeltaCodeInterpreterDetailItemObject codeInterpreter = null)
+ {
+ return new RunStepDeltaCodeInterpreterToolCall(index, id, "code_interpreter", serializedAdditionalRawData: null, codeInterpreter);
+ }
+
+ /// Initializes a new instance of .
+ /// The input into the Code Interpreter tool call.
+ ///
+ /// The outputs from the Code Interpreter tool call. Code Interpreter can output one or more
+ /// items, including text (`logs`) or images (`image`). Each of these are represented by a
+ /// different object type.
+ /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes.
+ /// The available derived classes include and .
+ ///
+ /// A new instance for mocking.
+ public static RunStepDeltaCodeInterpreterDetailItemObject RunStepDeltaCodeInterpreterDetailItemObject(string input = null, IEnumerable outputs = null)
+ {
+ outputs ??= new List();
+
+ return new RunStepDeltaCodeInterpreterDetailItemObject(input, outputs?.ToList(), serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the output in the streaming run step tool call's Code Interpreter outputs array.
+ /// The type of the streaming run step tool call's Code Interpreter output.
+ /// A new instance for mocking.
+ public static RunStepDeltaCodeInterpreterOutput RunStepDeltaCodeInterpreterOutput(int index = default, string type = null)
+ {
+ return new UnknownRunStepDeltaCodeInterpreterOutput(index, type, serializedAdditionalRawData: null);
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the output in the streaming run step tool call's Code Interpreter outputs array.
+ /// The text output from the Code Interpreter tool call.
+ /// A new instance for mocking.
+ public static RunStepDeltaCodeInterpreterLogOutput RunStepDeltaCodeInterpreterLogOutput(int index = default, string logs = null)
+ {
+ return new RunStepDeltaCodeInterpreterLogOutput(index, "logs", serializedAdditionalRawData: null, logs);
+ }
+
+ /// Initializes a new instance of .
+ /// The index of the output in the streaming run step tool call's Code Interpreter outputs array.
+ /// The image data for the Code Interpreter tool call output.
+ /// A new instance for mocking.
+ public static RunStepDeltaCodeInterpreterImageOutput RunStepDeltaCodeInterpreterImageOutput(int index = default, RunStepDeltaCodeInterpreterImageOutputObject image = null)
+ {
+ return new RunStepDeltaCodeInterpreterImageOutput(index, "image", serializedAdditionalRawData: null, image);
+ }
+
+ /// Initializes a new instance of .
+ /// The file ID for the image.
+ /// A new instance for mocking.
+ public static RunStepDeltaCodeInterpreterImageOutputObject RunStepDeltaCodeInterpreterImageOutputObject(string fileId = null)
+ {
+ return new RunStepDeltaCodeInterpreterImageOutputObject(fileId, serializedAdditionalRawData: null);
+ }
+ }
+}
diff --git a/sdk/ai/Azure.AI.Client/src/Generated/Agents.cs b/sdk/ai/Azure.AI.Client/src/Generated/Agents.cs
new file mode 100644
index 000000000000..fb943276f87d
--- /dev/null
+++ b/sdk/ai/Azure.AI.Client/src/Generated/Agents.cs
@@ -0,0 +1,6146 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using Azure.AI.Client.Models;
+using Azure.Core;
+using Azure.Core.Pipeline;
+
+namespace Azure.AI.Client
+{
+ // Data plane generated sub-client.
+ /// The Agents sub-client.
+ public partial class Agents
+ {
+ private static readonly string[] AuthorizationScopes = new string[] { "https://management.azure.com/.default" };
+ private readonly TokenCredential _tokenCredential;
+ private readonly HttpPipeline _pipeline;
+ private readonly Uri _endpoint;
+ private readonly string _subscriptionId;
+ private readonly string _resourceGroupName;
+ private readonly string _projectName;
+ private readonly string _apiVersion;
+
+ /// The ClientDiagnostics is used to provide tracing support for the client library.
+ internal ClientDiagnostics ClientDiagnostics { get; }
+
+ /// The HTTP pipeline for sending and receiving REST requests and responses.
+ public virtual HttpPipeline Pipeline => _pipeline;
+
+ /// Initializes a new instance of Agents for mocking.
+ protected Agents()
+ {
+ }
+
+ /// Initializes a new instance of Agents.
+ /// The handler for diagnostic messaging in the client.
+ /// The HTTP pipeline for sending and receiving REST requests and responses.
+ /// The token credential to copy.
+ /// The Azure AI Studio project endpoint, in the form `https://<azure-region>.api.azureml.ms` or `https://<private-link-guid>.<azure-region>.api.azureml.ms`, where <azure-region> is the Azure region where the project is deployed (e.g. westus) and <private-link-guid> is the GUID of the Enterprise private link.
+ /// The Azure subscription ID.
+ /// The name of the Azure Resource Group.
+ /// The Azure AI Studio project name.
+ /// The API version to use for this operation.
+ internal Agents(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, TokenCredential tokenCredential, Uri endpoint, string subscriptionId, string resourceGroupName, string projectName, string apiVersion)
+ {
+ ClientDiagnostics = clientDiagnostics;
+ _pipeline = pipeline;
+ _tokenCredential = tokenCredential;
+ _endpoint = endpoint;
+ _subscriptionId = subscriptionId;
+ _resourceGroupName = resourceGroupName;
+ _projectName = projectName;
+ _apiVersion = apiVersion;
+ }
+
+ /// Creates a new agent.
+ /// The ID of the model to use.
+ /// The name of the new agent.
+ /// The description of the new agent.
+ /// The system instructions for the new agent to use.
+ /// The collection of tools to enable for the new agent.
+ ///
+ /// A set of resources that are used by the agent's tools. The resources are specific to the type of tool. For example, the `code_interpreter`
+ /// tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs.
+ ///
+ ///
+ /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random,
+ /// while lower values like 0.2 will make it more focused and deterministic.
+ ///
+ ///
+ /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.
+ /// So 0.1 means only the tokens comprising the top 10% probability mass are considered.
+ ///
+ /// We generally recommend altering this or temperature but not both.
+ ///
+ /// The response format of the tool calls used by this agent.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// is null.
+ ///
+ public virtual async Task> CreateAgentAsync(string model, string name = null, string description = null, string instructions = null, IEnumerable tools = null, ToolResources toolResources = null, float? temperature = null, float? topP = null, BinaryData responseFormat = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNull(model, nameof(model));
+
+ CreateAgentRequest createAgentRequest = new CreateAgentRequest(
+ model,
+ name,
+ description,
+ instructions,
+ tools?.ToList() as IReadOnlyList ?? new ChangeTrackingList(),
+ toolResources,
+ temperature,
+ topP,
+ responseFormat,
+ metadata ?? new ChangeTrackingDictionary(),
+ null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await CreateAgentAsync(createAgentRequest.ToRequestContent(), context).ConfigureAwait(false);
+ return Response.FromValue(Agent.FromResponse(response), response);
+ }
+
+ /// Creates a new agent.
+ /// The ID of the model to use.
+ /// The name of the new agent.
+ /// The description of the new agent.
+ /// The system instructions for the new agent to use.
+ /// The collection of tools to enable for the new agent.
+ ///
+ /// A set of resources that are used by the agent's tools. The resources are specific to the type of tool. For example, the `code_interpreter`
+ /// tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs.
+ ///
+ ///
+ /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random,
+ /// while lower values like 0.2 will make it more focused and deterministic.
+ ///
+ ///
+ /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.
+ /// So 0.1 means only the tokens comprising the top 10% probability mass are considered.
+ ///
+ /// We generally recommend altering this or temperature but not both.
+ ///
+ /// The response format of the tool calls used by this agent.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// is null.
+ ///
+ public virtual Response CreateAgent(string model, string name = null, string description = null, string instructions = null, IEnumerable tools = null, ToolResources toolResources = null, float? temperature = null, float? topP = null, BinaryData responseFormat = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNull(model, nameof(model));
+
+ CreateAgentRequest createAgentRequest = new CreateAgentRequest(
+ model,
+ name,
+ description,
+ instructions,
+ tools?.ToList() as IReadOnlyList ?? new ChangeTrackingList(),
+ toolResources,
+ temperature,
+ topP,
+ responseFormat,
+ metadata ?? new ChangeTrackingDictionary(),
+ null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = CreateAgent(createAgentRequest.ToRequestContent(), context);
+ return Response.FromValue(Agent.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Creates a new agent.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task CreateAgentAsync(RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.CreateAgent");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCreateAgentRequest(content, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Creates a new agent.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response CreateAgent(RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.CreateAgent");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCreateAgentRequest(content, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Gets a list of agents that were previously created.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The cancellation token to use.
+ internal virtual async Task> InternalGetAgentsAsync(int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default)
+ {
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await InternalGetAgentsAsync(limit, order?.ToString(), after, before, context).ConfigureAwait(false);
+ return Response.FromValue(OpenAIPageableListOfAgent.FromResponse(response), response);
+ }
+
+ /// Gets a list of agents that were previously created.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The cancellation token to use.
+ internal virtual Response InternalGetAgents(int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default)
+ {
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = InternalGetAgents(limit, order?.ToString(), after, before, context);
+ return Response.FromValue(OpenAIPageableListOfAgent.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Gets a list of agents that were previously created.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc".
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual async Task InternalGetAgentsAsync(int? limit, string order, string after, string before, RequestContext context)
+ {
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalGetAgents");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalGetAgentsRequest(limit, order, after, before, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Gets a list of agents that were previously created.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc".
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual Response InternalGetAgents(int? limit, string order, string after, string before, RequestContext context)
+ {
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalGetAgents");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalGetAgentsRequest(limit, order, after, before, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Retrieves an existing agent.
+ /// Identifier of the agent.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> GetAgentAsync(string assistantId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await GetAgentAsync(assistantId, context).ConfigureAwait(false);
+ return Response.FromValue(Agent.FromResponse(response), response);
+ }
+
+ /// Retrieves an existing agent.
+ /// Identifier of the agent.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response GetAgent(string assistantId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = GetAgent(assistantId, context);
+ return Response.FromValue(Agent.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Retrieves an existing agent.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the agent.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task GetAgentAsync(string assistantId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetAgent");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetAgentRequest(assistantId, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Retrieves an existing agent.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the agent.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response GetAgent(string assistantId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetAgent");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetAgentRequest(assistantId, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Modifies an existing agent.
+ /// The ID of the agent to modify.
+ /// The ID of the model to use.
+ /// The modified name for the agent to use.
+ /// The modified description for the agent to use.
+ /// The modified system instructions for the new agent to use.
+ /// The modified collection of tools to enable for the agent.
+ ///
+ /// A set of resources that are used by the agent's tools. The resources are specific to the type of tool. For example,
+ /// the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs.
+ ///
+ ///
+ /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random,
+ /// while lower values like 0.2 will make it more focused and deterministic.
+ ///
+ ///
+ /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.
+ /// So 0.1 means only the tokens comprising the top 10% probability mass are considered.
+ ///
+ /// We generally recommend altering this or temperature but not both.
+ ///
+ /// The response format of the tool calls used by this agent.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> UpdateAgentAsync(string assistantId, string model = null, string name = null, string description = null, string instructions = null, IEnumerable tools = null, ToolResources toolResources = null, float? temperature = null, float? topP = null, BinaryData responseFormat = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
+
+ UpdateAgentRequest updateAgentRequest = new UpdateAgentRequest(
+ model,
+ name,
+ description,
+ instructions,
+ tools?.ToList() as IReadOnlyList ?? new ChangeTrackingList(),
+ toolResources,
+ temperature,
+ topP,
+ responseFormat,
+ metadata ?? new ChangeTrackingDictionary(),
+ null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await UpdateAgentAsync(assistantId, updateAgentRequest.ToRequestContent(), context).ConfigureAwait(false);
+ return Response.FromValue(Agent.FromResponse(response), response);
+ }
+
+ /// Modifies an existing agent.
+ /// The ID of the agent to modify.
+ /// The ID of the model to use.
+ /// The modified name for the agent to use.
+ /// The modified description for the agent to use.
+ /// The modified system instructions for the new agent to use.
+ /// The modified collection of tools to enable for the agent.
+ ///
+ /// A set of resources that are used by the agent's tools. The resources are specific to the type of tool. For example,
+ /// the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires a list of vector store IDs.
+ ///
+ ///
+ /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random,
+ /// while lower values like 0.2 will make it more focused and deterministic.
+ ///
+ ///
+ /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.
+ /// So 0.1 means only the tokens comprising the top 10% probability mass are considered.
+ ///
+ /// We generally recommend altering this or temperature but not both.
+ ///
+ /// The response format of the tool calls used by this agent.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response UpdateAgent(string assistantId, string model = null, string name = null, string description = null, string instructions = null, IEnumerable tools = null, ToolResources toolResources = null, float? temperature = null, float? topP = null, BinaryData responseFormat = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
+
+ UpdateAgentRequest updateAgentRequest = new UpdateAgentRequest(
+ model,
+ name,
+ description,
+ instructions,
+ tools?.ToList() as IReadOnlyList ?? new ChangeTrackingList(),
+ toolResources,
+ temperature,
+ topP,
+ responseFormat,
+ metadata ?? new ChangeTrackingDictionary(),
+ null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = UpdateAgent(assistantId, updateAgentRequest.ToRequestContent(), context);
+ return Response.FromValue(Agent.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Modifies an existing agent.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The ID of the agent to modify.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task UpdateAgentAsync(string assistantId, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.UpdateAgent");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateUpdateAgentRequest(assistantId, content, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Modifies an existing agent.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The ID of the agent to modify.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response UpdateAgent(string assistantId, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.UpdateAgent");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateUpdateAgentRequest(assistantId, content, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Deletes an agent.
+ /// Identifier of the agent.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ internal virtual async Task> InternalDeleteAgentAsync(string assistantId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await InternalDeleteAgentAsync(assistantId, context).ConfigureAwait(false);
+ return Response.FromValue(InternalAgentDeletionStatus.FromResponse(response), response);
+ }
+
+ /// Deletes an agent.
+ /// Identifier of the agent.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ internal virtual Response InternalDeleteAgent(string assistantId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = InternalDeleteAgent(assistantId, context);
+ return Response.FromValue(InternalAgentDeletionStatus.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Deletes an agent.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the agent.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual async Task InternalDeleteAgentAsync(string assistantId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalDeleteAgent");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalDeleteAgentRequest(assistantId, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Deletes an agent.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the agent.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual Response InternalDeleteAgent(string assistantId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(assistantId, nameof(assistantId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalDeleteAgent");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalDeleteAgentRequest(assistantId, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Creates a new thread. Threads contain messages and can be run by agents.
+ /// The initial messages to associate with the new thread.
+ ///
+ /// A set of resources that are made available to the agent's tools in this thread. The resources are specific to the
+ /// type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires
+ /// a list of vector store IDs.
+ ///
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ ///
+ public virtual async Task> CreateThreadAsync(IEnumerable messages = null, ToolResources toolResources = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ CreateThreadRequest createThreadRequest = new CreateThreadRequest(messages?.ToList() as IReadOnlyList ?? new ChangeTrackingList(), toolResources, metadata ?? new ChangeTrackingDictionary(), null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await CreateThreadAsync(createThreadRequest.ToRequestContent(), context).ConfigureAwait(false);
+ return Response.FromValue(AgentThread.FromResponse(response), response);
+ }
+
+ /// Creates a new thread. Threads contain messages and can be run by agents.
+ /// The initial messages to associate with the new thread.
+ ///
+ /// A set of resources that are made available to the agent's tools in this thread. The resources are specific to the
+ /// type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires
+ /// a list of vector store IDs.
+ ///
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ ///
+ public virtual Response CreateThread(IEnumerable messages = null, ToolResources toolResources = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ CreateThreadRequest createThreadRequest = new CreateThreadRequest(messages?.ToList() as IReadOnlyList ?? new ChangeTrackingList(), toolResources, metadata ?? new ChangeTrackingDictionary(), null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = CreateThread(createThreadRequest.ToRequestContent(), context);
+ return Response.FromValue(AgentThread.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Creates a new thread. Threads contain messages and can be run by agents.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task CreateThreadAsync(RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.CreateThread");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCreateThreadRequest(content, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Creates a new thread. Threads contain messages and can be run by agents.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response CreateThread(RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.CreateThread");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCreateThreadRequest(content, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Gets information about an existing thread.
+ /// Identifier of the thread.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> GetThreadAsync(string threadId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await GetThreadAsync(threadId, context).ConfigureAwait(false);
+ return Response.FromValue(AgentThread.FromResponse(response), response);
+ }
+
+ /// Gets information about an existing thread.
+ /// Identifier of the thread.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response GetThread(string threadId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = GetThread(threadId, context);
+ return Response.FromValue(AgentThread.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Gets information about an existing thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task GetThreadAsync(string threadId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetThread");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetThreadRequest(threadId, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Gets information about an existing thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response GetThread(string threadId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetThread");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetThreadRequest(threadId, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Modifies an existing thread.
+ /// The ID of the thread to modify.
+ ///
+ /// A set of resources that are made available to the agent's tools in this thread. The resources are specific to the
+ /// type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires
+ /// a list of vector store IDs
+ ///
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> UpdateThreadAsync(string threadId, ToolResources toolResources = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ UpdateThreadRequest updateThreadRequest = new UpdateThreadRequest(toolResources, metadata ?? new ChangeTrackingDictionary(), null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await UpdateThreadAsync(threadId, updateThreadRequest.ToRequestContent(), context).ConfigureAwait(false);
+ return Response.FromValue(AgentThread.FromResponse(response), response);
+ }
+
+ /// Modifies an existing thread.
+ /// The ID of the thread to modify.
+ ///
+ /// A set of resources that are made available to the agent's tools in this thread. The resources are specific to the
+ /// type of tool. For example, the `code_interpreter` tool requires a list of file IDs, while the `file_search` tool requires
+ /// a list of vector store IDs
+ ///
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response UpdateThread(string threadId, ToolResources toolResources = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ UpdateThreadRequest updateThreadRequest = new UpdateThreadRequest(toolResources, metadata ?? new ChangeTrackingDictionary(), null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = UpdateThread(threadId, updateThreadRequest.ToRequestContent(), context);
+ return Response.FromValue(AgentThread.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Modifies an existing thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The ID of the thread to modify.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task UpdateThreadAsync(string threadId, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.UpdateThread");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateUpdateThreadRequest(threadId, content, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Modifies an existing thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The ID of the thread to modify.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response UpdateThread(string threadId, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.UpdateThread");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateUpdateThreadRequest(threadId, content, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Deletes an existing thread.
+ /// Identifier of the thread.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ internal virtual async Task> InternalDeleteThreadAsync(string threadId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await InternalDeleteThreadAsync(threadId, context).ConfigureAwait(false);
+ return Response.FromValue(ThreadDeletionStatus.FromResponse(response), response);
+ }
+
+ /// Deletes an existing thread.
+ /// Identifier of the thread.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ internal virtual Response InternalDeleteThread(string threadId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = InternalDeleteThread(threadId, context);
+ return Response.FromValue(ThreadDeletionStatus.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Deletes an existing thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual async Task InternalDeleteThreadAsync(string threadId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalDeleteThread");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalDeleteThreadRequest(threadId, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Deletes an existing thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual Response InternalDeleteThread(string threadId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalDeleteThread");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalDeleteThreadRequest(threadId, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Creates a new message on a specified thread.
+ /// Identifier of the thread.
+ ///
+ /// The role of the entity that is creating the message. Allowed values include:
+ /// - `user`: Indicates the message is sent by an actual user and should be used in most cases to represent user-generated messages.
+ /// - `assistant`: Indicates the message is generated by the agent. Use this value to insert messages from the agent into
+ /// the conversation.
+ ///
+ ///
+ /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via
+ /// a separate call to the create message API.
+ ///
+ /// A list of files attached to the message, and the tools they should be added to.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> CreateMessageAsync(string threadId, MessageRole role, string content, IEnumerable attachments = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ CreateMessageRequest createMessageRequest = new CreateMessageRequest(role, content, attachments?.ToList() as IReadOnlyList ?? new ChangeTrackingList(), metadata ?? new ChangeTrackingDictionary(), null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await CreateMessageAsync(threadId, createMessageRequest.ToRequestContent(), context).ConfigureAwait(false);
+ return Response.FromValue(ThreadMessage.FromResponse(response), response);
+ }
+
+ /// Creates a new message on a specified thread.
+ /// Identifier of the thread.
+ ///
+ /// The role of the entity that is creating the message. Allowed values include:
+ /// - `user`: Indicates the message is sent by an actual user and should be used in most cases to represent user-generated messages.
+ /// - `assistant`: Indicates the message is generated by the agent. Use this value to insert messages from the agent into
+ /// the conversation.
+ ///
+ ///
+ /// The textual content of the initial message. Currently, robust input including images and annotated text may only be provided via
+ /// a separate call to the create message API.
+ ///
+ /// A list of files attached to the message, and the tools they should be added to.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response CreateMessage(string threadId, MessageRole role, string content, IEnumerable attachments = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ CreateMessageRequest createMessageRequest = new CreateMessageRequest(role, content, attachments?.ToList() as IReadOnlyList ?? new ChangeTrackingList(), metadata ?? new ChangeTrackingDictionary(), null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = CreateMessage(threadId, createMessageRequest.ToRequestContent(), context);
+ return Response.FromValue(ThreadMessage.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Creates a new message on a specified thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task CreateMessageAsync(string threadId, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.CreateMessage");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCreateMessageRequest(threadId, content, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Creates a new message on a specified thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response CreateMessage(string threadId, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.CreateMessage");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCreateMessageRequest(threadId, content, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Gets a list of messages that exist on a thread.
+ /// Identifier of the thread.
+ /// Filter messages by the run ID that generated them.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ internal virtual async Task> InternalGetMessagesAsync(string threadId, string runId = null, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await InternalGetMessagesAsync(threadId, runId, limit, order?.ToString(), after, before, context).ConfigureAwait(false);
+ return Response.FromValue(OpenAIPageableListOfThreadMessage.FromResponse(response), response);
+ }
+
+ /// Gets a list of messages that exist on a thread.
+ /// Identifier of the thread.
+ /// Filter messages by the run ID that generated them.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ internal virtual Response InternalGetMessages(string threadId, string runId = null, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = InternalGetMessages(threadId, runId, limit, order?.ToString(), after, before, context);
+ return Response.FromValue(OpenAIPageableListOfThreadMessage.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Gets a list of messages that exist on a thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Filter messages by the run ID that generated them.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc".
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual async Task InternalGetMessagesAsync(string threadId, string runId, int? limit, string order, string after, string before, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalGetMessages");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalGetMessagesRequest(threadId, runId, limit, order, after, before, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Gets a list of messages that exist on a thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Filter messages by the run ID that generated them.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc".
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual Response InternalGetMessages(string threadId, string runId, int? limit, string order, string after, string before, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalGetMessages");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalGetMessagesRequest(threadId, runId, limit, order, after, before, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Gets an existing message from an existing thread.
+ /// Identifier of the thread.
+ /// Identifier of the message.
+ /// The cancellation token to use.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> GetMessageAsync(string threadId, string messageId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await GetMessageAsync(threadId, messageId, context).ConfigureAwait(false);
+ return Response.FromValue(ThreadMessage.FromResponse(response), response);
+ }
+
+ /// Gets an existing message from an existing thread.
+ /// Identifier of the thread.
+ /// Identifier of the message.
+ /// The cancellation token to use.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response GetMessage(string threadId, string messageId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = GetMessage(threadId, messageId, context);
+ return Response.FromValue(ThreadMessage.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Gets an existing message from an existing thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the message.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task GetMessageAsync(string threadId, string messageId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetMessage");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetMessageRequest(threadId, messageId, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Gets an existing message from an existing thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the message.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response GetMessage(string threadId, string messageId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetMessage");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetMessageRequest(threadId, messageId, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Modifies an existing message on an existing thread.
+ /// Identifier of the thread.
+ /// Identifier of the message.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> UpdateMessageAsync(string threadId, string messageId, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));
+
+ UpdateMessageRequest updateMessageRequest = new UpdateMessageRequest(metadata ?? new ChangeTrackingDictionary(), null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await UpdateMessageAsync(threadId, messageId, updateMessageRequest.ToRequestContent(), context).ConfigureAwait(false);
+ return Response.FromValue(ThreadMessage.FromResponse(response), response);
+ }
+
+ /// Modifies an existing message on an existing thread.
+ /// Identifier of the thread.
+ /// Identifier of the message.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response UpdateMessage(string threadId, string messageId, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));
+
+ UpdateMessageRequest updateMessageRequest = new UpdateMessageRequest(metadata ?? new ChangeTrackingDictionary(), null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = UpdateMessage(threadId, messageId, updateMessageRequest.ToRequestContent(), context);
+ return Response.FromValue(ThreadMessage.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Modifies an existing message on an existing thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the message.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// , or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task UpdateMessageAsync(string threadId, string messageId, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.UpdateMessage");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateUpdateMessageRequest(threadId, messageId, content, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Modifies an existing message on an existing thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the message.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// , or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response UpdateMessage(string threadId, string messageId, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(messageId, nameof(messageId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.UpdateMessage");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateUpdateMessageRequest(threadId, messageId, content, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Creates a new run for an agent thread.
+ /// Identifier of the thread.
+ /// The ID of the agent that should run the thread.
+ /// The overridden model name that the agent should use to run the thread.
+ /// The overridden system instructions that the agent should use to run the thread.
+ ///
+ /// Additional instructions to append at the end of the instructions for the run. This is useful for modifying the behavior
+ /// on a per-run basis without overriding other instructions.
+ ///
+ /// Adds additional messages to the thread before creating the run.
+ /// The overridden list of enabled tools that the agent should use to run the thread.
+ ///
+ /// If `true`, returns a stream of events that happen during the Run as server-sent events,
+ /// terminating when the Run enters a terminal state with a `data: [DONE]` message.
+ ///
+ ///
+ /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output
+ /// more random, while lower values like 0.2 will make it more focused and deterministic.
+ ///
+ ///
+ /// An alternative to sampling with temperature, called nucleus sampling, where the model
+ /// considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens
+ /// comprising the top 10% probability mass are considered.
+ ///
+ /// We generally recommend altering this or temperature but not both.
+ ///
+ ///
+ /// The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only
+ /// the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified,
+ /// the run will end with status `incomplete`. See `incomplete_details` for more info.
+ ///
+ ///
+ /// The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort
+ /// to use only the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of
+ /// completion tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info.
+ ///
+ /// The strategy to use for dropping messages as the context windows moves forward.
+ /// Controls whether or not and which tool is called by the model.
+ /// Specifies the format that the model must output.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> CreateRunAsync(string threadId, string assistantId, string overrideModelName = null, string overrideInstructions = null, string additionalInstructions = null, IEnumerable additionalMessages = null, IEnumerable overrideTools = null, bool? stream = null, float? temperature = null, float? topP = null, int? maxPromptTokens = null, int? maxCompletionTokens = null, TruncationObject truncationStrategy = null, BinaryData toolChoice = null, BinaryData responseFormat = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNull(assistantId, nameof(assistantId));
+
+ CreateRunRequest createRunRequest = new CreateRunRequest(
+ assistantId,
+ overrideModelName,
+ overrideInstructions,
+ additionalInstructions,
+ additionalMessages?.ToList() as IReadOnlyList ?? new ChangeTrackingList(),
+ overrideTools?.ToList() as IReadOnlyList ?? new ChangeTrackingList(),
+ stream,
+ temperature,
+ topP,
+ maxPromptTokens,
+ maxCompletionTokens,
+ truncationStrategy,
+ toolChoice,
+ responseFormat,
+ metadata ?? new ChangeTrackingDictionary(),
+ null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await CreateRunAsync(threadId, createRunRequest.ToRequestContent(), context).ConfigureAwait(false);
+ return Response.FromValue(ThreadRun.FromResponse(response), response);
+ }
+
+ /// Creates a new run for an agent thread.
+ /// Identifier of the thread.
+ /// The ID of the agent that should run the thread.
+ /// The overridden model name that the agent should use to run the thread.
+ /// The overridden system instructions that the agent should use to run the thread.
+ ///
+ /// Additional instructions to append at the end of the instructions for the run. This is useful for modifying the behavior
+ /// on a per-run basis without overriding other instructions.
+ ///
+ /// Adds additional messages to the thread before creating the run.
+ /// The overridden list of enabled tools that the agent should use to run the thread.
+ ///
+ /// If `true`, returns a stream of events that happen during the Run as server-sent events,
+ /// terminating when the Run enters a terminal state with a `data: [DONE]` message.
+ ///
+ ///
+ /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output
+ /// more random, while lower values like 0.2 will make it more focused and deterministic.
+ ///
+ ///
+ /// An alternative to sampling with temperature, called nucleus sampling, where the model
+ /// considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens
+ /// comprising the top 10% probability mass are considered.
+ ///
+ /// We generally recommend altering this or temperature but not both.
+ ///
+ ///
+ /// The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only
+ /// the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified,
+ /// the run will end with status `incomplete`. See `incomplete_details` for more info.
+ ///
+ ///
+ /// The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort
+ /// to use only the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of
+ /// completion tokens specified, the run will end with status `incomplete`. See `incomplete_details` for more info.
+ ///
+ /// The strategy to use for dropping messages as the context windows moves forward.
+ /// Controls whether or not and which tool is called by the model.
+ /// Specifies the format that the model must output.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response CreateRun(string threadId, string assistantId, string overrideModelName = null, string overrideInstructions = null, string additionalInstructions = null, IEnumerable additionalMessages = null, IEnumerable overrideTools = null, bool? stream = null, float? temperature = null, float? topP = null, int? maxPromptTokens = null, int? maxCompletionTokens = null, TruncationObject truncationStrategy = null, BinaryData toolChoice = null, BinaryData responseFormat = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNull(assistantId, nameof(assistantId));
+
+ CreateRunRequest createRunRequest = new CreateRunRequest(
+ assistantId,
+ overrideModelName,
+ overrideInstructions,
+ additionalInstructions,
+ additionalMessages?.ToList() as IReadOnlyList ?? new ChangeTrackingList(),
+ overrideTools?.ToList() as IReadOnlyList ?? new ChangeTrackingList(),
+ stream,
+ temperature,
+ topP,
+ maxPromptTokens,
+ maxCompletionTokens,
+ truncationStrategy,
+ toolChoice,
+ responseFormat,
+ metadata ?? new ChangeTrackingDictionary(),
+ null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = CreateRun(threadId, createRunRequest.ToRequestContent(), context);
+ return Response.FromValue(ThreadRun.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Creates a new run for an agent thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task CreateRunAsync(string threadId, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.CreateRun");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCreateRunRequest(threadId, content, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Creates a new run for an agent thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response CreateRun(string threadId, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.CreateRun");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCreateRunRequest(threadId, content, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Gets a list of runs for a specified thread.
+ /// Identifier of the thread.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ internal virtual async Task> InternalGetRunsAsync(string threadId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await InternalGetRunsAsync(threadId, limit, order?.ToString(), after, before, context).ConfigureAwait(false);
+ return Response.FromValue(OpenAIPageableListOfThreadRun.FromResponse(response), response);
+ }
+
+ /// Gets a list of runs for a specified thread.
+ /// Identifier of the thread.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ internal virtual Response InternalGetRuns(string threadId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = InternalGetRuns(threadId, limit, order?.ToString(), after, before, context);
+ return Response.FromValue(OpenAIPageableListOfThreadRun.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Gets a list of runs for a specified thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc".
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual async Task InternalGetRunsAsync(string threadId, int? limit, string order, string after, string before, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalGetRuns");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalGetRunsRequest(threadId, limit, order, after, before, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Gets a list of runs for a specified thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc".
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual Response InternalGetRuns(string threadId, int? limit, string order, string after, string before, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalGetRuns");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalGetRunsRequest(threadId, limit, order, after, before, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Gets an existing run from an existing thread.
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// The cancellation token to use.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> GetRunAsync(string threadId, string runId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await GetRunAsync(threadId, runId, context).ConfigureAwait(false);
+ return Response.FromValue(ThreadRun.FromResponse(response), response);
+ }
+
+ /// Gets an existing run from an existing thread.
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// The cancellation token to use.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response GetRun(string threadId, string runId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = GetRun(threadId, runId, context);
+ return Response.FromValue(ThreadRun.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Gets an existing run from an existing thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task GetRunAsync(string threadId, string runId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetRun");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetRunRequest(threadId, runId, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Gets an existing run from an existing thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response GetRun(string threadId, string runId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetRun");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetRunRequest(threadId, runId, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Modifies an existing thread run.
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> UpdateRunAsync(string threadId, string runId, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+
+ UpdateRunRequest updateRunRequest = new UpdateRunRequest(metadata ?? new ChangeTrackingDictionary(), null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await UpdateRunAsync(threadId, runId, updateRunRequest.ToRequestContent(), context).ConfigureAwait(false);
+ return Response.FromValue(ThreadRun.FromResponse(response), response);
+ }
+
+ /// Modifies an existing thread run.
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response UpdateRun(string threadId, string runId, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+
+ UpdateRunRequest updateRunRequest = new UpdateRunRequest(metadata ?? new ChangeTrackingDictionary(), null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = UpdateRun(threadId, runId, updateRunRequest.ToRequestContent(), context);
+ return Response.FromValue(ThreadRun.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Modifies an existing thread run.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// , or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task UpdateRunAsync(string threadId, string runId, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.UpdateRun");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateUpdateRunRequest(threadId, runId, content, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Modifies an existing thread run.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// , or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response UpdateRun(string threadId, string runId, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.UpdateRun");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateUpdateRunRequest(threadId, runId, content, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'.
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// A list of tools for which the outputs are being submitted.
+ /// If true, returns a stream of events that happen during the Run as server-sent events, terminating when the run enters a terminal state.
+ /// The cancellation token to use.
+ /// , or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> SubmitToolOutputsToRunAsync(string threadId, string runId, IEnumerable toolOutputs, bool? stream = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+ Argument.AssertNotNull(toolOutputs, nameof(toolOutputs));
+
+ SubmitToolOutputsToRunRequest submitToolOutputsToRunRequest = new SubmitToolOutputsToRunRequest(toolOutputs.ToList(), stream, null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await SubmitToolOutputsToRunAsync(threadId, runId, submitToolOutputsToRunRequest.ToRequestContent(), context).ConfigureAwait(false);
+ return Response.FromValue(ThreadRun.FromResponse(response), response);
+ }
+
+ /// Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'.
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// A list of tools for which the outputs are being submitted.
+ /// If true, returns a stream of events that happen during the Run as server-sent events, terminating when the run enters a terminal state.
+ /// The cancellation token to use.
+ /// , or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response SubmitToolOutputsToRun(string threadId, string runId, IEnumerable toolOutputs, bool? stream = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+ Argument.AssertNotNull(toolOutputs, nameof(toolOutputs));
+
+ SubmitToolOutputsToRunRequest submitToolOutputsToRunRequest = new SubmitToolOutputsToRunRequest(toolOutputs.ToList(), stream, null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = SubmitToolOutputsToRun(threadId, runId, submitToolOutputsToRunRequest.ToRequestContent(), context);
+ return Response.FromValue(ThreadRun.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// , or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task SubmitToolOutputsToRunAsync(string threadId, string runId, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.SubmitToolOutputsToRun");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateSubmitToolOutputsToRunRequest(threadId, runId, content, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool outputs will have a status of 'requires_action' with a required_action.type of 'submit_tool_outputs'.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// , or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response SubmitToolOutputsToRun(string threadId, string runId, RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.SubmitToolOutputsToRun");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateSubmitToolOutputsToRunRequest(threadId, runId, content, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Cancels a run of an in progress thread.
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// The cancellation token to use.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> CancelRunAsync(string threadId, string runId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await CancelRunAsync(threadId, runId, context).ConfigureAwait(false);
+ return Response.FromValue(ThreadRun.FromResponse(response), response);
+ }
+
+ /// Cancels a run of an in progress thread.
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// The cancellation token to use.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response CancelRun(string threadId, string runId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = CancelRun(threadId, runId, context);
+ return Response.FromValue(ThreadRun.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Cancels a run of an in progress thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task CancelRunAsync(string threadId, string runId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.CancelRun");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCancelRunRequest(threadId, runId, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Cancels a run of an in progress thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response CancelRun(string threadId, string runId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.CancelRun");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCancelRunRequest(threadId, runId, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Creates a new agent thread and immediately starts a run using that new thread.
+ /// The ID of the agent for which the thread should be created.
+ /// The details used to create the new thread. If no thread is provided, an empty one will be created.
+ /// The overridden model that the agent should use to run the thread.
+ /// The overridden system instructions the agent should use to run the thread.
+ /// The overridden list of enabled tools the agent should use to run the thread.
+ /// Override the tools the agent can use for this run. This is useful for modifying the behavior on a per-run basis.
+ ///
+ /// If `true`, returns a stream of events that happen during the Run as server-sent events,
+ /// terminating when the Run enters a terminal state with a `data: [DONE]` message.
+ ///
+ ///
+ /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output
+ /// more random, while lower values like 0.2 will make it more focused and deterministic.
+ ///
+ ///
+ /// An alternative to sampling with temperature, called nucleus sampling, where the model
+ /// considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens
+ /// comprising the top 10% probability mass are considered.
+ ///
+ /// We generally recommend altering this or temperature but not both.
+ ///
+ ///
+ /// The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only
+ /// the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified,
+ /// the run will end with status `incomplete`. See `incomplete_details` for more info.
+ ///
+ ///
+ /// The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort to use only
+ /// the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of completion tokens
+ /// specified, the run will end with status `incomplete`. See `incomplete_details` for more info.
+ ///
+ /// The strategy to use for dropping messages as the context windows moves forward.
+ /// Controls whether or not and which tool is called by the model.
+ /// Specifies the format that the model must output.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// is null.
+ ///
+ public virtual async Task> CreateThreadAndRunAsync(string assistantId, AgentThreadCreationOptions thread = null, string overrideModelName = null, string overrideInstructions = null, IEnumerable overrideTools = null, UpdateToolResourcesOptions toolResources = null, bool? stream = null, float? temperature = null, float? topP = null, int? maxPromptTokens = null, int? maxCompletionTokens = null, TruncationObject truncationStrategy = null, BinaryData toolChoice = null, BinaryData responseFormat = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNull(assistantId, nameof(assistantId));
+
+ CreateThreadAndRunRequest createThreadAndRunRequest = new CreateThreadAndRunRequest(
+ assistantId,
+ thread,
+ overrideModelName,
+ overrideInstructions,
+ overrideTools?.ToList() as IReadOnlyList ?? new ChangeTrackingList(),
+ toolResources,
+ stream,
+ temperature,
+ topP,
+ maxPromptTokens,
+ maxCompletionTokens,
+ truncationStrategy,
+ toolChoice,
+ responseFormat,
+ metadata ?? new ChangeTrackingDictionary(),
+ null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await CreateThreadAndRunAsync(createThreadAndRunRequest.ToRequestContent(), context).ConfigureAwait(false);
+ return Response.FromValue(ThreadRun.FromResponse(response), response);
+ }
+
+ /// Creates a new agent thread and immediately starts a run using that new thread.
+ /// The ID of the agent for which the thread should be created.
+ /// The details used to create the new thread. If no thread is provided, an empty one will be created.
+ /// The overridden model that the agent should use to run the thread.
+ /// The overridden system instructions the agent should use to run the thread.
+ /// The overridden list of enabled tools the agent should use to run the thread.
+ /// Override the tools the agent can use for this run. This is useful for modifying the behavior on a per-run basis.
+ ///
+ /// If `true`, returns a stream of events that happen during the Run as server-sent events,
+ /// terminating when the Run enters a terminal state with a `data: [DONE]` message.
+ ///
+ ///
+ /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output
+ /// more random, while lower values like 0.2 will make it more focused and deterministic.
+ ///
+ ///
+ /// An alternative to sampling with temperature, called nucleus sampling, where the model
+ /// considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens
+ /// comprising the top 10% probability mass are considered.
+ ///
+ /// We generally recommend altering this or temperature but not both.
+ ///
+ ///
+ /// The maximum number of prompt tokens that may be used over the course of the run. The run will make a best effort to use only
+ /// the number of prompt tokens specified, across multiple turns of the run. If the run exceeds the number of prompt tokens specified,
+ /// the run will end with status `incomplete`. See `incomplete_details` for more info.
+ ///
+ ///
+ /// The maximum number of completion tokens that may be used over the course of the run. The run will make a best effort to use only
+ /// the number of completion tokens specified, across multiple turns of the run. If the run exceeds the number of completion tokens
+ /// specified, the run will end with status `incomplete`. See `incomplete_details` for more info.
+ ///
+ /// The strategy to use for dropping messages as the context windows moves forward.
+ /// Controls whether or not and which tool is called by the model.
+ /// Specifies the format that the model must output.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ /// is null.
+ ///
+ public virtual Response CreateThreadAndRun(string assistantId, AgentThreadCreationOptions thread = null, string overrideModelName = null, string overrideInstructions = null, IEnumerable overrideTools = null, UpdateToolResourcesOptions toolResources = null, bool? stream = null, float? temperature = null, float? topP = null, int? maxPromptTokens = null, int? maxCompletionTokens = null, TruncationObject truncationStrategy = null, BinaryData toolChoice = null, BinaryData responseFormat = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNull(assistantId, nameof(assistantId));
+
+ CreateThreadAndRunRequest createThreadAndRunRequest = new CreateThreadAndRunRequest(
+ assistantId,
+ thread,
+ overrideModelName,
+ overrideInstructions,
+ overrideTools?.ToList() as IReadOnlyList ?? new ChangeTrackingList(),
+ toolResources,
+ stream,
+ temperature,
+ topP,
+ maxPromptTokens,
+ maxCompletionTokens,
+ truncationStrategy,
+ toolChoice,
+ responseFormat,
+ metadata ?? new ChangeTrackingDictionary(),
+ null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = CreateThreadAndRun(createThreadAndRunRequest.ToRequestContent(), context);
+ return Response.FromValue(ThreadRun.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Creates a new agent thread and immediately starts a run using that new thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task CreateThreadAndRunAsync(RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.CreateThreadAndRun");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCreateThreadAndRunRequest(content, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Creates a new agent thread and immediately starts a run using that new thread.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The content to send as the body of the request.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response CreateThreadAndRun(RequestContent content, RequestContext context = null)
+ {
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.CreateThreadAndRun");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateCreateThreadAndRunRequest(content, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Gets a single run step from a thread run.
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// Identifier of the run step.
+ /// The cancellation token to use.
+ /// , or is null.
+ /// , or is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> GetRunStepAsync(string threadId, string runId, string stepId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+ Argument.AssertNotNullOrEmpty(stepId, nameof(stepId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await GetRunStepAsync(threadId, runId, stepId, context).ConfigureAwait(false);
+ return Response.FromValue(RunStep.FromResponse(response), response);
+ }
+
+ /// Gets a single run step from a thread run.
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// Identifier of the run step.
+ /// The cancellation token to use.
+ /// , or is null.
+ /// , or is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response GetRunStep(string threadId, string runId, string stepId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+ Argument.AssertNotNullOrEmpty(stepId, nameof(stepId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = GetRunStep(threadId, runId, stepId, context);
+ return Response.FromValue(RunStep.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Gets a single run step from a thread run.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// Identifier of the run step.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// , or is null.
+ /// , or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task GetRunStepAsync(string threadId, string runId, string stepId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+ Argument.AssertNotNullOrEmpty(stepId, nameof(stepId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetRunStep");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetRunStepRequest(threadId, runId, stepId, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Gets a single run step from a thread run.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// Identifier of the run step.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// , or is null.
+ /// , or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response GetRunStep(string threadId, string runId, string stepId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+ Argument.AssertNotNullOrEmpty(stepId, nameof(stepId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetRunStep");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetRunStepRequest(threadId, runId, stepId, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Gets a list of run steps from a thread run.
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The cancellation token to use.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ internal virtual async Task> InternalGetRunStepsAsync(string threadId, string runId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await InternalGetRunStepsAsync(threadId, runId, limit, order?.ToString(), after, before, context).ConfigureAwait(false);
+ return Response.FromValue(OpenAIPageableListOfRunStep.FromResponse(response), response);
+ }
+
+ /// Gets a list of run steps from a thread run.
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The cancellation token to use.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ internal virtual Response InternalGetRunSteps(string threadId, string runId, int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = InternalGetRunSteps(threadId, runId, limit, order?.ToString(), after, before, context);
+ return Response.FromValue(OpenAIPageableListOfRunStep.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Gets a list of run steps from a thread run.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc".
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual async Task InternalGetRunStepsAsync(string threadId, string runId, int? limit, string order, string after, string before, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalGetRunSteps");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalGetRunStepsRequest(threadId, runId, limit, order, after, before, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Gets a list of run steps from a thread run.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// Identifier of the thread.
+ /// Identifier of the run.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc".
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// or is null.
+ /// or is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual Response InternalGetRunSteps(string threadId, string runId, int? limit, string order, string after, string before, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
+ Argument.AssertNotNullOrEmpty(runId, nameof(runId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalGetRunSteps");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalGetRunStepsRequest(threadId, runId, limit, order, after, before, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Gets a list of previously uploaded files.
+ /// The purpose of the file.
+ /// The cancellation token to use.
+ internal virtual async Task> InternalListFilesAsync(OpenAIFilePurpose? purpose = null, CancellationToken cancellationToken = default)
+ {
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await InternalListFilesAsync(purpose?.ToString(), context).ConfigureAwait(false);
+ return Response.FromValue(InternalFileListResponse.FromResponse(response), response);
+ }
+
+ /// Gets a list of previously uploaded files.
+ /// The purpose of the file.
+ /// The cancellation token to use.
+ internal virtual Response InternalListFiles(OpenAIFilePurpose? purpose = null, CancellationToken cancellationToken = default)
+ {
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = InternalListFiles(purpose?.ToString(), context);
+ return Response.FromValue(InternalFileListResponse.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Gets a list of previously uploaded files.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The purpose of the file. Allowed values: "fine-tune" | "fine-tune-results" | "assistants" | "assistants_output" | "batch" | "batch_output" | "vision".
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual async Task InternalListFilesAsync(string purpose, RequestContext context)
+ {
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalListFiles");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalListFilesRequest(purpose, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Gets a list of previously uploaded files.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The purpose of the file. Allowed values: "fine-tune" | "fine-tune-results" | "assistants" | "assistants_output" | "batch" | "batch_output" | "vision".
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual Response InternalListFiles(string purpose, RequestContext context)
+ {
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalListFiles");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalListFilesRequest(purpose, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Uploads a file for use by other operations.
+ /// The file data, in bytes.
+ /// The intended purpose of the uploaded file. Use `assistants` for Agents and Message files, `vision` for Agents image file inputs, `batch` for Batch API, and `fine-tune` for Fine-tuning.
+ /// The name of the file.
+ /// The cancellation token to use.
+ /// is null.
+ ///
+ public virtual async Task> UploadFileAsync(Stream data, OpenAIFilePurpose purpose, string filename = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNull(data, nameof(data));
+
+ UploadFileRequest uploadFileRequest = new UploadFileRequest(data, purpose, filename, null);
+ using MultipartFormDataRequestContent content = uploadFileRequest.ToMultipartRequestContent();
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await UploadFileAsync(content, content.ContentType, context).ConfigureAwait(false);
+ return Response.FromValue(OpenAIFile.FromResponse(response), response);
+ }
+
+ /// Uploads a file for use by other operations.
+ /// The file data, in bytes.
+ /// The intended purpose of the uploaded file. Use `assistants` for Agents and Message files, `vision` for Agents image file inputs, `batch` for Batch API, and `fine-tune` for Fine-tuning.
+ /// The name of the file.
+ /// The cancellation token to use.
+ /// is null.
+ ///
+ public virtual Response UploadFile(Stream data, OpenAIFilePurpose purpose, string filename = null, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNull(data, nameof(data));
+
+ UploadFileRequest uploadFileRequest = new UploadFileRequest(data, purpose, filename, null);
+ using MultipartFormDataRequestContent content = uploadFileRequest.ToMultipartRequestContent();
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = UploadFile(content, content.ContentType, context);
+ return Response.FromValue(OpenAIFile.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Uploads a file for use by other operations.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The content to send as the body of the request.
+ /// The name of the file to upload. Allowed values: "multipart/form-data".
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task UploadFileAsync(RequestContent content, string contentType, RequestContext context = null)
+ {
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.UploadFile");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateUploadFileRequest(content, contentType, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Uploads a file for use by other operations.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The content to send as the body of the request.
+ /// The name of the file to upload. Allowed values: "multipart/form-data".
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response UploadFile(RequestContent content, string contentType, RequestContext context = null)
+ {
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.UploadFile");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateUploadFileRequest(content, contentType, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Delete a previously uploaded file.
+ /// The ID of the file to delete.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ internal virtual async Task> InternalDeleteFileAsync(string fileId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await InternalDeleteFileAsync(fileId, context).ConfigureAwait(false);
+ return Response.FromValue(InternalFileDeletionStatus.FromResponse(response), response);
+ }
+
+ /// Delete a previously uploaded file.
+ /// The ID of the file to delete.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ internal virtual Response InternalDeleteFile(string fileId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = InternalDeleteFile(fileId, context);
+ return Response.FromValue(InternalFileDeletionStatus.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Delete a previously uploaded file.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The ID of the file to delete.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual async Task InternalDeleteFileAsync(string fileId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalDeleteFile");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalDeleteFileRequest(fileId, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Delete a previously uploaded file.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The ID of the file to delete.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ internal virtual Response InternalDeleteFile(string fileId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.InternalDeleteFile");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateInternalDeleteFileRequest(fileId, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Returns information about a specific file. Does not retrieve file content.
+ /// The ID of the file to retrieve.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> GetFileAsync(string fileId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await GetFileAsync(fileId, context).ConfigureAwait(false);
+ return Response.FromValue(OpenAIFile.FromResponse(response), response);
+ }
+
+ /// Returns information about a specific file. Does not retrieve file content.
+ /// The ID of the file to retrieve.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response GetFile(string fileId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = GetFile(fileId, context);
+ return Response.FromValue(OpenAIFile.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Returns information about a specific file. Does not retrieve file content.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The ID of the file to retrieve.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task GetFileAsync(string fileId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetFile");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetFileRequest(fileId, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Returns information about a specific file. Does not retrieve file content.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The ID of the file to retrieve.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response GetFile(string fileId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetFile");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetFileRequest(fileId, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Returns information about a specific file. Does not retrieve file content.
+ /// The ID of the file to retrieve.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual async Task> GetFileContentAsync(string fileId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await GetFileContentAsync(fileId, context).ConfigureAwait(false);
+ return Response.FromValue(FileContentResponse.FromResponse(response), response);
+ }
+
+ /// Returns information about a specific file. Does not retrieve file content.
+ /// The ID of the file to retrieve.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ ///
+ public virtual Response GetFileContent(string fileId, CancellationToken cancellationToken = default)
+ {
+ Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
+
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = GetFileContent(fileId, context);
+ return Response.FromValue(FileContentResponse.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Returns information about a specific file. Does not retrieve file content.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The ID of the file to retrieve.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task GetFileContentAsync(string fileId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetFileContent");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetFileContentRequest(fileId, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Returns information about a specific file. Does not retrieve file content.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// The ID of the file to retrieve.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response GetFileContent(string fileId, RequestContext context)
+ {
+ Argument.AssertNotNullOrEmpty(fileId, nameof(fileId));
+
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetFileContent");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetFileContentRequest(fileId, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Returns a list of vector stores.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The cancellation token to use.
+ ///
+ public virtual async Task> GetVectorStoresAsync(int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default)
+ {
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await GetVectorStoresAsync(limit, order?.ToString(), after, before, context).ConfigureAwait(false);
+ return Response.FromValue(OpenAIPageableListOfVectorStore.FromResponse(response), response);
+ }
+
+ /// Returns a list of vector stores.
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The cancellation token to use.
+ ///
+ public virtual Response GetVectorStores(int? limit = null, ListSortOrder? order = null, string after = null, string before = null, CancellationToken cancellationToken = default)
+ {
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = GetVectorStores(limit, order?.ToString(), after, before, context);
+ return Response.FromValue(OpenAIPageableListOfVectorStore.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Returns a list of vector stores.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc".
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual async Task GetVectorStoresAsync(int? limit, string order, string after, string before, RequestContext context)
+ {
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetVectorStores");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetVectorStoresRequest(limit, order, after, before, context);
+ return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// [Protocol Method] Returns a list of vector stores.
+ ///
+ /// -
+ ///
+ /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
+ ///
+ ///
+ /// -
+ ///
+ /// Please try the simpler convenience overload with strongly typed models first.
+ ///
+ ///
+ ///
+ ///
+ /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
+ /// Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order. Allowed values: "asc" | "desc".
+ /// A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
+ /// A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
+ /// The request context, which can override default behaviors of the client pipeline on a per-call basis.
+ /// Service returned a non-success status code.
+ /// The response returned from the service.
+ ///
+ public virtual Response GetVectorStores(int? limit, string order, string after, string before, RequestContext context)
+ {
+ using var scope = ClientDiagnostics.CreateScope("Agents.GetVectorStores");
+ scope.Start();
+ try
+ {
+ using HttpMessage message = CreateGetVectorStoresRequest(limit, order, after, before, context);
+ return _pipeline.ProcessMessage(message, context);
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ /// Creates a vector store.
+ /// A list of file IDs that the vector store should use. Useful for tools like `file_search` that can access files.
+ /// The name of the vector store.
+ /// Details on when this vector store expires.
+ /// The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. Only applicable if file_ids is non-empty.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ ///
+ public virtual async Task> CreateVectorStoreAsync(IEnumerable fileIds = null, string name = null, VectorStoreExpirationPolicy expiresAfter = null, VectorStoreChunkingStrategyRequest chunkingStrategy = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ CreateVectorStoreRequest createVectorStoreRequest = new CreateVectorStoreRequest(
+ fileIds?.ToList() as IReadOnlyList ?? new ChangeTrackingList(),
+ name,
+ expiresAfter,
+ chunkingStrategy,
+ metadata ?? new ChangeTrackingDictionary(),
+ null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = await CreateVectorStoreAsync(createVectorStoreRequest.ToRequestContent(), context).ConfigureAwait(false);
+ return Response.FromValue(VectorStore.FromResponse(response), response);
+ }
+
+ /// Creates a vector store.
+ /// A list of file IDs that the vector store should use. Useful for tools like `file_search` that can access files.
+ /// The name of the vector store.
+ /// Details on when this vector store expires.
+ /// The chunking strategy used to chunk the file(s). If not set, will use the auto strategy. Only applicable if file_ids is non-empty.
+ /// A set of up to 16 key/value pairs that can be attached to an object, used for storing additional information about that object in a structured format. Keys may be up to 64 characters in length and values may be up to 512 characters in length.
+ /// The cancellation token to use.
+ ///
+ public virtual Response CreateVectorStore(IEnumerable fileIds = null, string name = null, VectorStoreExpirationPolicy expiresAfter = null, VectorStoreChunkingStrategyRequest chunkingStrategy = null, IReadOnlyDictionary metadata = null, CancellationToken cancellationToken = default)
+ {
+ CreateVectorStoreRequest createVectorStoreRequest = new CreateVectorStoreRequest(
+ fileIds?.ToList() as IReadOnlyList ?? new ChangeTrackingList(),
+ name,
+ expiresAfter,
+ chunkingStrategy,
+ metadata ?? new ChangeTrackingDictionary(),
+ null);
+ RequestContext context = FromCancellationToken(cancellationToken);
+ Response response = CreateVectorStore(createVectorStoreRequest.ToRequestContent(), context);
+ return Response.FromValue(VectorStore.FromResponse(response), response);
+ }
+
+ ///
+ /// [Protocol Method] Creates a vector store.
+ ///
+ ///