Table of Contents

Class GeminiChatAgent

Namespace
AutoGen.Gemini
Assembly
AutoGen.Gemini.dll
public class GeminiChatAgent : IStreamingAgent, IAgent, IAgentMetaInformation
Inheritance
GeminiChatAgent
Implements
Inherited Members
Extension Methods

Constructors

GeminiChatAgent(IGeminiClient, string, string, string?, ToolConfig?, Tool[]?, RepeatedField<SafetySetting>?, string)

Create GeminiChatAgent that connects to Gemini.

public GeminiChatAgent(IGeminiClient client, string name, string model, string? systemMessage = null, ToolConfig? toolConfig = null, Tool[]? tools = null, RepeatedField<SafetySetting>? safetySettings = null, string responseMimeType = "text/plain")

Parameters

client IGeminiClient

the gemini client to use. e.g. VertexGeminiClient

name string

agent name

model string

the model id. It needs to be in the format of 'projects/{project}/locations/{location}/publishers/{provider}/models/{model}' if the client is VertexGeminiClient

systemMessage string

system message

toolConfig ToolConfig

tool config

tools Tool[]

tools

safetySettings RepeatedField<SafetySetting>

safety settings

responseMimeType string

response mime type, available values are ['application/json', 'text/plain'], default is 'text/plain'

GeminiChatAgent(string, string, string, string, ToolConfig?, Tool[]?, RepeatedField<SafetySetting>?, string)

Create GeminiChatAgent that connects to Gemini using GoogleGeminiClient

public GeminiChatAgent(string name, string model, string apiKey, string systemMessage = "You are a helpful AI assistant", ToolConfig? toolConfig = null, Tool[]? tools = null, RepeatedField<SafetySetting>? safetySettings = null, string responseMimeType = "text/plain")

Parameters

name string

agent name

model string

the name of gemini model, e.g. gemini-1.5-flash-001

apiKey string

google gemini api key

systemMessage string

system message

toolConfig ToolConfig

tool config

tools Tool[]

tools

safetySettings RepeatedField<SafetySetting>
responseMimeType string

response mime type, available values are ['application/json', 'text/plain'], default is 'text/plain'

Examples

var apiKey = Environment.GetEnvironmentVariable("GOOGLE_GEMINI_API_KEY");

if (apiKey is null)
{
    Console.WriteLine("Please set GOOGLE_GEMINI_API_KEY environment variable.");
    return;
}

var geminiAgent = new GeminiChatAgent(
        name: "gemini",
        model: "gemini-1.5-flash-001",
        apiKey: apiKey,
        systemMessage: "You are a helpful C# engineer, put your code between ```csharp and ```, don't explain the code")
    .RegisterMessageConnector()
    .RegisterPrintMessage();

GeminiChatAgent(string, string, string, string, string, string?, ToolConfig?, Tool[]?, RepeatedField<SafetySetting>?, string)

Create GeminiChatAgent that connects to Vertex AI.

public GeminiChatAgent(string name, string model, string project, string location, string provider = "google", string? systemMessage = null, ToolConfig? toolConfig = null, Tool[]? tools = null, RepeatedField<SafetySetting>? safetySettings = null, string responseMimeType = "text/plain")

Parameters

name string

agent name

model string

the name of gemini model, e.g. gemini-1.5-flash-001

project string

project id

location string

model location

provider string

model provider, default is 'google'

systemMessage string

system message

toolConfig ToolConfig

tool config

tools Tool[]

tools

safetySettings RepeatedField<SafetySetting>
responseMimeType string

response mime type, available values are ['application/json', 'text/plain'], default is 'text/plain'

Examples

var projectID = Environment.GetEnvironmentVariable("GCP_VERTEX_PROJECT_ID");

if (projectID is null)
{
    Console.WriteLine("Please set GCP_VERTEX_PROJECT_ID environment variable.");
    return;
}

var geminiAgent = new GeminiChatAgent(
        name: "gemini",
        model: "gemini-1.5-flash-001",
        location: "us-east1",
        project: projectID,
        systemMessage: "You are a helpful C# engineer, put your code between ```csharp and ```, don't explain the code")
    .RegisterMessageConnector()
    .RegisterPrintMessage();

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>