Method TryGet
TryGet(string, out ITool)
Attempts to retrieve a tool by its name.
public bool TryGet(string name, out ITool tool)
Parameters
namestringThe exact tool name to look up (case-sensitive).
toolIToolWhen this method returns
true, contains the tool with the specified name. When this method returnsfalse, containsnull.
Returns
- bool
trueif the tool was found; otherwise,false.
Examples
Example: Looking up and invoking a tool
using LMKit.Agents.Tools;
var registry = new ToolRegistry();
registry.Register(new WeatherTool());
// Simulating a tool call from the model
string toolName = "get_weather";
string args = "{\"location\": \"Paris, FR\"}";
if (registry.TryGet(toolName, out ITool tool))
{
string result = await tool.InvokeAsync(args);
Console.WriteLine($"Tool result: {result}");
}
else
{
Console.WriteLine($"Unknown tool: {toolName}");
}
Remarks
Use this method when handling tool calls from the model to locate the tool for invocation.