Method BuildAndValidate
BuildAndValidate(out IReadOnlyList<string>)
Builds the agent and validates its configuration.
public Agent BuildAndValidate(out IReadOnlyList<string> errors)
Parameters
errorsIReadOnlyList<string>When this method returns, contains validation errors if any were found.
Returns
Examples
Building with validation:
using LMKit.Model;
using LMKit.Agents;
using var model = new LM("path/to/model.gguf");
var agent = new AgentBuilder()
.WithModel(model)
.WithPersona("Assistant")
.WithTools(t => t.Register(new MyTool()))
.BuildAndValidate(out var errors);
if (errors.Count == 0)
{
Console.WriteLine("Agent is ready!");
var result = agent.Run("Test the agent.");
Console.WriteLine(result.Content);
}
else
{
Console.WriteLine("Validation failed:");
foreach (var error in errors)
{
Console.WriteLine($" - {error}");
}
}
Handling missing model error:
using LMKit.Agents;
// Forgot to set the model
var agent = new AgentBuilder()
.WithPersona("Assistant")
.BuildAndValidate(out var errors);
// agent is returned but errors will contain "Agent requires a language model."
if (errors.Count > 0)
{
Console.WriteLine($"Cannot create agent: {string.Join(", ", errors)}");
}
Remarks
This method combines Build() and Validate(out IReadOnlyList<string>)
in a single operation. The agent is always returned, even when validation
fails, so callers can inspect the configuration. Check
errors to determine whether the agent is ready for use.