Table of Contents

Class OpenAIChatAgent

Namespace
AutoGen.OpenAI
Assembly
AutoGen.OpenAI.dll

OpenAI client agent. This agent is a thin wrapper around OpenAI.OpenAIClient to provide a simple interface for chat completions.

OpenAIChatAgent supports the following message types:

OpenAIChatAgent returns the following message types:

  • MessageEnvelope<T> where T is OpenAI.Chat.ChatCompletion: chat response message. MessageEnvelope<T> where T is OpenAI.Chat.StreamingChatCompletionUpdate: streaming chat completions update.
public class OpenAIChatAgent : IStreamingAgent, IAgent, IAgentMetaInformation
Inheritance
OpenAIChatAgent
Implements
Inherited Members
Extension Methods

Constructors

OpenAIChatAgent(ChatClient, string, ChatCompletionOptions, string?)

Create a new instance of OpenAIChatAgent.

public OpenAIChatAgent(ChatClient chatClient, string name, ChatCompletionOptions options, string? systemMessage = "You are a helpful AI assistant")

Parameters

chatClient ChatClient

openai chat client

name string

agent name

options ChatCompletionOptions

chat completion option. The option can't contain messages

systemMessage string

system message

OpenAIChatAgent(ChatClient, string, string?, float?, int?, int?, ChatResponseFormat?, IEnumerable<ChatTool>?)

Create a new instance of OpenAIChatAgent.

public OpenAIChatAgent(ChatClient chatClient, string name, string? systemMessage = "You are a helpful AI assistant", float? temperature = null, int? maxTokens = null, int? seed = null, ChatResponseFormat? responseFormat = null, IEnumerable<ChatTool>? functions = null)

Parameters

chatClient ChatClient

openai client

name string

agent name

systemMessage string

system message

temperature float?

temperature

maxTokens int?

max tokens to generated

seed int?

seed to use, set it to enable deterministic output

responseFormat ChatResponseFormat

response format, set it to OpenAI.Chat.ChatResponseFormat.JsonObject to enable json mode.

functions IEnumerable<ChatTool>

functions

Properties

Name

public string Name { get; }

Property Value

string

Methods

GenerateReplyAsync(IEnumerable<IMessage>, GenerateReplyOptions?, CancellationToken)

Generate reply

public Task<IMessage> GenerateReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, CancellationToken cancellationToken = default)

Parameters

messages IEnumerable<IMessage>

conversation history

options GenerateReplyOptions

completion option. If provided, it should override existing option if there's any

cancellationToken CancellationToken

Returns

Task<IMessage>

GenerateStreamingReplyAsync(IEnumerable<IMessage>, GenerateReplyOptions?, CancellationToken)

public IAsyncEnumerable<IMessage> GenerateStreamingReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, CancellationToken cancellationToken = default)

Parameters

messages IEnumerable<IMessage>
options GenerateReplyOptions
cancellationToken CancellationToken

Returns

IAsyncEnumerable<IMessage>