Table of Contents

Method WithTools

Namespace
LMKit.Agents
Assembly
LM-Kit.NET.dll

WithTools(ToolRegistry)

Sets the tool registry for the agent.

public AgentBuilder WithTools(ToolRegistry tools)

Parameters

tools ToolRegistry

The tool registry containing available tools.

Returns

AgentBuilder

This builder instance for method chaining.

Examples

Using a shared tool registry:

using LMKit.Model;
using LMKit.Agents;
using LMKit.Agents.Tools;

// Create a shared tool registry
var sharedTools = new ToolRegistry();
sharedTools.Register(new CalculatorTool());
sharedTools.Register(new DateTimeTool());

using var model = new LM("path/to/model.gguf");

// Multiple agents can share the same tools
var agent1 = new AgentBuilder()
    .WithModel(model)
    .WithTools(sharedTools)
    .Build();

var agent2 = new AgentBuilder()
    .WithModel(model)
    .WithTools(sharedTools)
    .Build();

Remarks

Use this overload when you have a pre-configured tool registry. For inline tool registration, use WithTools(Action<ToolRegistry>).

WithTools(Action<ToolRegistry>)

Configures tools using a setup action.

public AgentBuilder WithTools(Action<ToolRegistry> configure)

Parameters

configure Action<ToolRegistry>

An action to configure the tool registry.

Returns

AgentBuilder

This builder instance for method chaining.

Examples

Registering tools inline:

using LMKit.Model;
using LMKit.Agents;
using LMKit.Agents.Tools;

using var model = new LM("path/to/model.gguf");

var agent = new AgentBuilder()
    .WithModel(model)
    .WithPersona("Multi-Tool Assistant")
    .WithPlanning(PlanningStrategy.ReAct)
    .WithTools(tools =>
    {
        // Register individual tools
        tools.Register(new WeatherTool());
        tools.Register(new CalculatorTool());

        // Register tools from a class with [LMFunction] attributes
        tools.Register(new MyToolService());
    })
    .Build();

var result = await agent.RunAsync(
    "What's the weather in Tokyo, and convert 25 Celsius to Fahrenheit?"
);

Remarks

Creates a new tool registry if one hasn't been set. The action receives the registry for inline configuration.

Exceptions

ArgumentNullException

Thrown when configure is null.