Table of Contents

Class OpenAIChatAgent

Namespace
AutoGen.OpenAI.V1
Assembly
AutoGen.OpenAI.V1.dll

OpenAI client agent. This agent is a thin wrapper around OpenAIClient to provide a simple interface for chat completions. To better work with other agents, it's recommended to use GPTAgent which supports more message types and have a better compatibility with other agents.

OpenAIChatAgent supports the following message types:

OpenAIChatAgent returns the following message types:

public class OpenAIChatAgent : IStreamingAgent, IAgent, IAgentMetaInformation
Inheritance
OpenAIChatAgent
Implements
Inherited Members
Extension Methods

Constructors

OpenAIChatAgent(OpenAIClient, string, ChatCompletionsOptions, string)

Create a new instance of OpenAIChatAgent.

public OpenAIChatAgent(OpenAIClient openAIClient, string name, ChatCompletionsOptions options, string systemMessage = "You are a helpful AI assistant")

Parameters

openAIClient OpenAIClient

openai client

name string

agent name

options ChatCompletionsOptions

chat completion option. The option can't contain messages

systemMessage string

system message

OpenAIChatAgent(OpenAIClient, string, string, string, float, int, int?, ChatCompletionsResponseFormat?, IEnumerable<FunctionDefinition>?)

Create a new instance of OpenAIChatAgent.

public OpenAIChatAgent(OpenAIClient openAIClient, string name, string modelName, string systemMessage = "You are a helpful AI assistant", float temperature = 0.7, int maxTokens = 1024, int? seed = null, ChatCompletionsResponseFormat? responseFormat = null, IEnumerable<FunctionDefinition>? functions = null)

Parameters

openAIClient OpenAIClient

openai client

name string

agent name

modelName string

model name. e.g. gpt-turbo-3.5

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 ChatCompletionsResponseFormat

response format, set it to JsonObject to enable json mode.

functions IEnumerable<FunctionDefinition>

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>