Table of Contents

Method Run

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

Run(string, CancellationToken)

Executes the agent with the given input synchronously.

public AgentExecutionResult Run(string input, CancellationToken cancellationToken = default)

Parameters

input string

The user input or task prompt.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

AgentExecutionResult

The execution result containing the agent's response and metadata.

Examples

Running a simple task:

using LMKit.Model;
using LMKit.Agents;

using var model = new LM("path/to/model.gguf");
var agent = new Agent(
    new AgentIdentity("Assistant", "Be helpful and concise."),
    model
);

var result = agent.Run("What is the capital of France?");

if (result.IsSuccess)
{
    Console.WriteLine(result.Content);
    Console.WriteLine($"Completed in {result.Duration.TotalSeconds:F2}s");
}
else if (result.IsFailed)
{
    Console.WriteLine($"Error: {result.Error.Message}");
}

Remarks

Creates a temporary AgentExecutor for this execution. For multi-turn conversations or repeated executions, create and reuse an executor directly for better performance.

Exceptions

ArgumentNullException

Thrown when input is null or empty.

InvalidOperationException

Thrown when the agent is not properly configured.

Run(string, AgentExecutionOptions, CancellationToken)

Executes the agent with the given input synchronously using the specified options.

public AgentExecutionResult Run(string input, AgentExecutionOptions options, CancellationToken cancellationToken = default)

Parameters

input string

The user input or task prompt.

options AgentExecutionOptions

Execution options, or null to use defaults.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

AgentExecutionResult

The execution result containing the agent's response and metadata.

Examples

Running with custom options:

using LMKit.Model;
using LMKit.Agents;

using var model = new LM("path/to/model.gguf");
var agent = new Agent(model);

var options = new AgentExecutionOptions
{
    Timeout = TimeSpan.FromSeconds(30),
    MaxIterations = 5,
    MaxCompletionTokens = 500
};

var result = agent.Run("Summarize quantum computing in one paragraph.", options);
Console.WriteLine(result.Content);