asTool

fun <R> KFunction<R>.asTool(thisRef: Any? = null, name: String? = null, description: String? = null): ToolFromCallable<R>(source)

Converts KFunction to ToolFromCallable.

The function can be annotated with Tool annotation where the name of the tool can be overridden. If the custom name is not provided, the name of the function is used.

The function can be annotated with LLMDescription annotation to provide a description of the tool. If not provided, the name of the function is used as a description.

The callable parameters can be annotated with LLMDescription annotation to provide a description of the parameter. If not provided, the name of the parameter is used.

If the function is a method that overrides or implements another method from a base class or an interface, Tool annotation can be extracted from one of the base methods in the case when it's missing on this method. In this case LLMDescription` annotation will be also extracted from the base method where Tool annotation was found.

Both suspend and non-suspend functions are supported

Default parameters are supported (calling site can omit them in the argument Json)

Parameters

thisRef

The object instance to use as the 'this' object for the callable.

name

The name of the tool. If not provided, the name will be obtained from Tool.customName property. In the case of the missing attribute or empty name the name of the function is used.

description

The description of the tool. If not provided, the description will be obtained from LLMDescription.description property. In the case of the missing attribute or empty description the name of the function is used as a description.