Class LMFunctionToolBinder
Discovers methods annotated with LMFunctionAttribute and binds them to ITool adapters.
This type is stateless: each call inspects the provided instance/type/assembly via reflection, validates parameter types, and returns newly constructed ITool instances.
public static class LMFunctionToolBinder
- Inheritance
-
LMFunctionToolBinder
- Inherited Members
Examples
Binding annotated methods on an instance to ITool adapters:
using LMKit.Agents.Tools;
public sealed class MathTools
{
[LMFunction("add", "Adds two integers and returns the sum.")]
public int Add(int a, int b) => a + b;
}
var tools = LMFunctionToolBinder.Bind(new MathTools());
foreach (ITool tool in tools)
Console.WriteLine(tool.Name);
Remarks
- Only instance, public, non-abstract, non-generic methods are considered.
- Parameters must use types supported by LM-Kit tool arguments (e.g., string, enums, and primitive numeric/boolean types). Unsupported types trigger ArgumentException.
- If present, DescriptionAttribute on parameters is surfaced into the generated JSON schema.
- Tool names and descriptions are taken from Name and Description.
Methods
- FromAssembly(Assembly)
Creates ITool instances from all types in the given
assemblythat expose instance methods annotated with LMFunctionAttribute.
- FromInstance(object)
Creates ITool instances from all LMFunctionAttribute methods on the given
instance.
- FromMethod(object, MethodInfo)
Creates a single ITool from a specific
methodon the suppliedinstance.
- FromType(Type)
Creates ITool instances from all LMFunctionAttribute methods on the specified
type.
- FromType<T>()
Creates ITool instances from all LMFunctionAttribute methods on
T.