Method EnsureValid
EnsureValid(ToolCallPolicy)
Validates the registry contents and optionally a ToolCallPolicy.
public void EnsureValid(ToolCallPolicy toolCallPolicy = null)
Parameters
toolCallPolicyToolCallPolicyOptional policy to validate against the registry. Pass
nullto validate only the registry contents.
Examples
Example: Validating registry before use
using LMKit.Agents.Tools;
var registry = new ToolRegistry();
registry.Register(new SearchTool());
var policy = new ToolCallPolicy
{
Choice = ToolChoice.Required,
MaxCallsPerTurn = 5
};
try
{
registry.EnsureValid(policy);
Console.WriteLine("Registry and policy are valid");
}
catch (InvalidOperationException ex)
{
Console.WriteLine($"Validation failed: {ex.Message}");
}
Remarks
Call this method before using the registry with an agent to catch configuration errors early. Validation checks:
- All registered tools are non-null with valid names
- All tool input schemas are valid JSON objects
- Policy requirements are satisfiable (e.g., required tools exist)
Exceptions
- InvalidOperationException
Thrown when validation fails (null tools, name mismatches, invalid schemas, missing required tools for the policy).
- ArgumentOutOfRangeException
Thrown when MaxCallsPerTurn is negative.