Поделиться через


ThreadMessageOptions Class

Definition

Represents the options for creating or adding a message in an agent thread. This class provides convenient ways to specify the message role (e.g., user or assistant) and the message content, which can be either plain text or one or more structured content blocks (e.g., text, images).

public class ThreadMessageOptions : System.ClientModel.Primitives.IJsonModel<Azure.AI.Agents.Persistent.ThreadMessageOptions>, System.ClientModel.Primitives.IPersistableModel<Azure.AI.Agents.Persistent.ThreadMessageOptions>
type ThreadMessageOptions = class
    interface IJsonModel<ThreadMessageOptions>
    interface IPersistableModel<ThreadMessageOptions>
Public Class ThreadMessageOptions
Implements IJsonModel(Of ThreadMessageOptions), IPersistableModel(Of ThreadMessageOptions)
Inheritance
ThreadMessageOptions
Implements

Remarks

This partial class builds on the generated code, offering two primary ways to define a message:

  • A single string for simple textual content.
  • A list of MessageInputContentBlock items for more advanced scenarios, such as including multiple blocks of text, images, or other media.

Constructors

ThreadMessageOptions(MessageRole, BinaryData)

Initializes a new instance of ThreadMessageOptions.

ThreadMessageOptions(MessageRole, IEnumerable<MessageInputContentBlock>)

Initializes a new instance of the ThreadMessageOptions class, converting one or more structured blocks into JSON and storing them as Content.

ThreadMessageOptions(MessageRole, String)

Initializes a new instance of the ThreadMessageOptions class, setting the message content to a single, plain-text string.

Properties

Attachments

A list of files attached to the message, and the tools they should be added to.

Content

The content of the initial message. This may be a basic string (if you only need text) or an array of typed content blocks (for example, text, image_file, image_url, and so on).

To assign an object to this property use FromObjectAsJson<T>(T, JsonSerializerOptions).

To assign an already formatted json string to this property use FromString(String).

Examples:

  • BinaryData.FromObjectAsJson("foo"): Creates a payload of "foo".
  • BinaryData.FromString("\"foo\""): Creates a payload of "foo".
  • BinaryData.FromObjectAsJson(new { key = "value" }): Creates a payload of { "key": "value" }.
  • BinaryData.FromString("{\"key\": \"value\"}"): Creates a payload of { "key": "value" }.

Metadata

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.

Role

The role of the entity that is creating the message. Allowed values include: user, which indicates the message is sent by an actual user (and should be used in most cases to represent user-generated messages), and assistant, which indicates the message is generated by the agent (use this value to insert messages from the agent into the conversation).

Methods

GetContentBlocks()

Deserializes the underlying message content (stored as BinaryData) into a collection of MessageInputContentBlock objects.

GetTextContent()

Deserializes the underlying message content (stored as BinaryData) into a plain string.

JsonModelWriteCore(Utf8JsonWriter, ModelReaderWriterOptions)

Explicit Interface Implementations

IJsonModel<ThreadMessageOptions>.Create(Utf8JsonReader, ModelReaderWriterOptions)

Reads one JSON value (including objects or arrays) from the provided reader and converts it to a model.

IJsonModel<ThreadMessageOptions>.Write(Utf8JsonWriter, ModelReaderWriterOptions)

Writes the model to the provided Utf8JsonWriter.

IPersistableModel<ThreadMessageOptions>.Create(BinaryData, ModelReaderWriterOptions)

Converts the provided BinaryData into a model.

IPersistableModel<ThreadMessageOptions>.GetFormatFromOptions(ModelReaderWriterOptions)

Gets the data interchange format (JSON, Xml, etc) that the model uses when communicating with the service.

IPersistableModel<ThreadMessageOptions>.Write(ModelReaderWriterOptions)

Writes the model into a BinaryData.

Applies to