Table of Contents

Class QuickTool

Namespace
GenerativeAI.Tools
Assembly
GenerativeAI.Tools.dll

Quick Function Tool,

public class QuickTool : GoogleFunctionTool, IFunctionTool
Inheritance
QuickTool
Implements
Inherited Members
Extension Methods

Remarks

This class usages reflection and is not compatible with AOT

Constructors

QuickTool(Delegate, string?, string?, JsonSerializerOptions?)

Represents a tool capable of wrapping a delegate function and exposing it as an interactive tool.

public QuickTool(Delegate func, string? name = null, string? description = null, JsonSerializerOptions? options = null)

Parameters

func Delegate

The delegate function to be wrapped by the tool.

name string

The name of the function for identification. Optional.

description string

A description of the function for metadata purposes. Optional.

options JsonSerializerOptions

The JSON serializer options for serialization and deserialization. If not provided, GenerateObjectJsonOptions will be used, including any custom type resolvers added to it. This can also be ignored if not using NativeAOT or Trimming

Remarks

QuickTool enables the use of delegate-based functions as tools by utilizing runtime reflection for schema generation and invocation. It is incompatible with Ahead-Of-Time (AOT) compilation scenarios and environments that require trimming support.

Properties

FunctionDeclaration

Represents the declaration of a function used within the tool.

public FunctionDeclaration FunctionDeclaration { get; }

Property Value

FunctionDeclaration

Remarks

This property contains metadata about a function, such as its name, description, and parameter schema. It's primarily used for defining and managing functions available to tools in the framework.

Methods

AsMeaiTool()

Converts the current QuickTool instance into a MeaiFunction representation.

public AITool AsMeaiTool()

Returns

AITool

A MeaiFunction instance populated with properties from the current QuickTool, including the defined function name, description, parameters, and invocation logic.

AsTool()

Converts the current instance to a Tool object.

public override Tool AsTool()

Returns

Tool

A Tool representation of the current instance.

CallAsync(FunctionCall, CancellationToken)

Executes the specified FunctionCall asynchronously and retrieves the resulting FunctionResponse containing any output from the function execution.

public override Task<FunctionResponse?> CallAsync(FunctionCall functionCall, CancellationToken cancellationToken = default)

Parameters

functionCall FunctionCall

The FunctionCall instance containing the name and arguments required for the function execution.

cancellationToken CancellationToken

Token to monitor for cancellation requests.

Returns

Task<FunctionResponse>

A task representing the asynchronous operation, which, upon completion, provides a FunctionResponse with the execution results.

IsContainFunction(string)

Determines whether the specified function name matches the name of the function declared in the tool's FunctionDeclaration property.

public override bool IsContainFunction(string name)

Parameters

name string

The name of the function to check for existence within the tool's declaration.

Returns

bool

A boolean value indicating whether the specified function name is contained within the FunctionDeclaration.