Method WithToolPolicy
WithToolPolicy(ToolCallPolicy)
Sets the tool call policy for the agent.
public AgentBuilder WithToolPolicy(ToolCallPolicy policy)
Parameters
policyToolCallPolicyThe policy governing tool usage.
Returns
- AgentBuilder
This builder instance for method chaining.
Examples
Setting a tool policy:
using LMKit.Model;
using LMKit.Agents;
using LMKit.Agents.Tools;
using var model = new LM("path/to/model.gguf");
var policy = new ToolCallPolicy
{
Choice = ToolChoice.Required
};
var agent = new AgentBuilder()
.WithModel(model)
.WithTools(t => t.Register(new SearchTool()))
.WithToolPolicy(policy)
.Build();
Remarks
The policy controls when and how tools are used during execution.
WithToolPolicy(Action<ToolCallPolicy>)
Configures the tool call policy using a setup action.
public AgentBuilder WithToolPolicy(Action<ToolCallPolicy> configure)
Parameters
configureAction<ToolCallPolicy>An action to configure the tool policy.
Returns
- AgentBuilder
This builder instance for method chaining.
Examples
Configuring tool policy inline:
using LMKit.Model;
using LMKit.Agents;
using LMKit.Agents.Tools;
using var model = new LM("path/to/model.gguf");
var agent = new AgentBuilder()
.WithModel(model)
.WithTools(t =>
{
t.Register(new DatabaseQueryTool());
t.Register(new ReportGeneratorTool());
})
.WithToolPolicy(policy =>
{
// Force the agent to use a specific tool
policy.Choice = ToolChoice.Specific;
policy.ForcedToolName = "database_query";
})
.Build();
Remarks
Creates a new policy if one hasn't been set. The action receives the policy for inline configuration.
Exceptions
- ArgumentNullException
Thrown when
configureis null.