Method EnsureTools
EnsureTools()
Ensures the tool registry is initialized and returns it.
public ToolRegistry EnsureTools()
Returns
- ToolRegistry
The tool registry for this agent.
Examples
Using EnsureTools to register tools safely:
using LMKit.Model;
using LMKit.Agents;
using LMKit.Agents.Tools;
using var model = new LM("path/to/model.gguf");
var agent = new Agent(model);
// EnsureTools creates the registry if needed
var tools = agent.Capabilities.EnsureTools();
tools.Register(new WeatherTool());
tools.Register(new SearchTool());
// Can also chain
agent.Capabilities.EnsureTools().Register(new CalculatorTool());
Console.WriteLine($"Total tools: {agent.Capabilities.Tools.Count}");
Remarks
If no tool registry has been set, a new empty registry is created. Use this method when you want to register tools without checking if the registry exists.