Table of Contents

Class AgentExecutionResult

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

Represents the outcome of an agent task execution.

public sealed class AgentExecutionResult
Inheritance
AgentExecutionResult
Inherited Members

Examples

Processing an execution result:

using LMKit.Model;
using LMKit.Agents;

using var model = new LM("path/to/model.gguf");
var agent = new Agent(model);
agent.Identity = new AgentIdentity("Assistant", "Help with questions.");

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

if (result.IsSuccess)
{
    Console.WriteLine($"Response: {result.Content}");
    Console.WriteLine($"Completed in {result.Duration.TotalMilliseconds:F0}ms");
    Console.WriteLine($"Inference calls: {result.InferenceCount}");
}
else if (result.IsFailed)
{
    Console.WriteLine($"Error: {result.Error.Message}");
}
else if (result.IsCancelled)
{
    Console.WriteLine("Task was cancelled.");
}

Inspecting tool calls:

using LMKit.Model;
using LMKit.Agents;

using var model = new LM("path/to/model.gguf");
var agent = Agent.CreateBuilder(model)
    .WithPersona("Research Assistant")
    .WithPlanning(PlanningStrategy.ReAct)
    .WithTools(t => t.Register(new SearchTool()))
    .Build();

var result = await agent.RunAsync("Find recent news about AI.");

Console.WriteLine($"Response: {result.Content}");
Console.WriteLine($"Tool calls made: {result.ToolCalls.Count}");

foreach (var toolCall in result.ToolCalls)
{
    Console.WriteLine($"  Tool: {toolCall.ToolName}");
    Console.WriteLine($"  Status: {toolCall.ResultType}");
}

Remarks

The execution result contains everything you need to understand what happened during agent execution: the final response, any tool calls made, reasoning traces, timing information, and error details if something went wrong.

Result Components

  • Content: The final text response from the agent.
  • ToolCalls: A record of all tool invocations during execution.
  • ReasoningTrace: Internal reasoning steps if a planning strategy produced them.
  • Status: The terminal state indicating success, failure, or cancellation.
  • Duration: Total execution time.
  • InferenceCount: Number of LLM inference calls made.

Checking Results

Use the convenience properties IsSuccess, IsFailed, and IsCancelled to quickly check the outcome.

Properties

Content

Gets the final text content produced by the agent.

Duration

Gets the total execution duration.

Error

Gets the exception that caused execution to fail, if applicable.

InferenceCount

Gets the number of LLM inference calls made during execution.

IsCancelled

Gets a value indicating whether the execution was cancelled.

IsFailed

Gets a value indicating whether the execution failed.

IsSuccess

Gets a value indicating whether the execution completed successfully.

ReasoningTrace

Gets the reasoning trace produced during execution, if any.

Status

Gets the execution status indicating how the task completed.

ToolCalls

Gets the list of tool calls made during execution, in order of invocation.

Methods

Cancelled(string, IReadOnlyList<ToolCallResult>, TimeSpan, int)

Creates a cancelled execution result.

Failure(Exception, string, IReadOnlyList<ToolCallResult>, TimeSpan, int)

Creates a failed execution result.

Success(string, IReadOnlyList<ToolCallResult>, string, TimeSpan, int)

Creates a successful execution result.