Skip to content

AgentPrismGeneratedToolArguments

Namespace AgentPrism · Assembly AgentPrism.Abstractions.dll

The helper methods called by tool wrappers produced by the source generator while converting JSON arguments to CLR types.

public static class AgentPrismGeneratedToolArguments

objectAgentPrismGeneratedToolArguments

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

This class is designed to be called only by code generated by the [AgentPrismTool] generator; calling it by hand is not a supported scenario. The only reason it is public is that the generated code lives in the consumer’s own assembly and therefore needs to reach this type from outside this compilation.

No conversion uses reflection: everything works through JsonElement’s type-specific Get* methods or through the converter delegate the caller supplies.

GetArray<T>(AIFunctionArguments, string, Func<JsonElement, T>, bool, IReadOnlyList<T>?)

Section titled “ GetArray<T>(AIFunctionArguments, string, Func<JsonElement, T>, bool, IReadOnlyList<T>?)”

Reads an array argument; each element is converted with the same converter.

public static IReadOnlyList<T> GetArray<T>(AIFunctionArguments arguments, string name, Func<JsonElement, T> convert, bool required, IReadOnlyList<T>? defaultValue)

arguments AIFunctionArguments

The call’s arguments.

name string

The argument’s JSON key.

convert Func<JsonElement, T>

The converter that converts each element.

required bool

Whether to throw if the argument is missing.

defaultValue IReadOnlyList<T>?

The value to use if required is false and the argument is missing. An empty list is used if null.

IReadOnlyList<T>

The converted array.

T

The array element type.

AgentPrismException

The argument is required but missing, or the given value is not a JSON array.

GetOptional<T>(AIFunctionArguments, string, Func<JsonElement, T>, T)

Section titled “ GetOptional<T>(AIFunctionArguments, string, Func<JsonElement, T>, T)”

Reads an optional argument; returns the given default if missing.

public static T GetOptional<T>(AIFunctionArguments arguments, string name, Func<JsonElement, T> convert, T defaultValue)

arguments AIFunctionArguments

The call’s arguments.

name string

The argument’s JSON key.

convert Func<JsonElement, T>

The converter that turns a JsonElement into T.

defaultValue T

The value to use if the argument is missing.

T

The converted value, or defaultValue.

T

The target CLR type.

AgentPrismException

The argument was given but is an unexpected CLR type.

GetRequired<T>(AIFunctionArguments, string, Func<JsonElement, T>)

Section titled “ GetRequired<T>(AIFunctionArguments, string, Func<JsonElement, T>)”

Reads a required argument; throws if missing.

public static T GetRequired<T>(AIFunctionArguments arguments, string name, Func<JsonElement, T> convert)

arguments AIFunctionArguments

The call’s arguments.

name string

The argument’s JSON key.

convert Func<JsonElement, T>

The converter that turns a JsonElement into T.

T

The converted value.

T

The target CLR type.

AgentPrismException

The argument is missing, or is an unexpected CLR type.