Table of Contents

Method TryGet

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

TryGet(string, out ITool)

Attempts to retrieve a tool by its name.

public bool TryGet(string name, out ITool tool)

Parameters

name string

The exact tool name to look up (case-sensitive).

tool ITool

When this method returns true, contains the tool with the specified name. When this method returns false, contains null.

Returns

bool

true if 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.