Method WithMaxIterations
WithMaxIterations(int)
Sets the maximum number of iterations allowed during task execution.
public AgentBuilder WithMaxIterations(int maxIterations)
Parameters
maxIterationsintThe maximum iteration count. Must be at least 1.
Returns
- AgentBuilder
This builder instance for method chaining.
Examples
Configuring iteration limits for different use cases:
using LMKit.Model;
using LMKit.Agents;
using var model = new LM("path/to/model.gguf");
// Simple Q&A agent with few iterations
var qaAgent = new AgentBuilder()
.WithModel(model)
.WithPersona("FAQ Bot")
.WithMaxIterations(3)
.Build();
// Complex research agent with many iterations
var researchAgent = new AgentBuilder()
.WithModel(model)
.WithPersona("Research Assistant")
.WithPlanning(PlanningStrategy.PlanAndExecute)
.WithMaxIterations(25)
.Build();
Remarks
Iterations count tool-call and reasoning cycles. Increase for complex tasks that need many tool calls; decrease for simple tasks or to reduce latency. The default is 10.
Exceptions
- ArgumentOutOfRangeException
Thrown when
maxIterationsis less than 1.