Table of Contents

Enum AgentExecutionStatus

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

Represents the terminal status of an agent task execution.

public enum AgentExecutionStatus

Fields

Completed = 0

The task completed successfully.

This status indicates the agent produced a complete response and any tool calls executed without errors. The response content is available in Content.

What to do: Process the result content as normal. Review ToolCalls if you need to inspect which tools were invoked.

Failed = 1

The task failed due to an error.

This status indicates an exception occurred during execution. The exception is available in Error. Partial results may still be available in Content if some processing completed before the error.

Common Causes:

  • Model inference errors (out of memory, corrupted model)
  • Tool execution failures (network errors, invalid parameters)
  • Validation errors (invalid agent configuration)
  • Resource exhaustion (context window overflow)

What to do: Log the error, notify the user, and consider retry logic for transient failures.

Cancelled = 2

The task was cancelled before completion.

This status indicates the execution was stopped early, typically because a CancellationToken was triggered. This is not an error condition; it represents intentional termination of the task.

Partial results may be available if some processing completed before cancellation.

Common Causes:

  • User requested cancellation
  • Application shutdown
  • Timeout from a CancellationTokenSource

What to do: Inform the user the task was cancelled. Do not treat this as an error unless cancellation was unexpected.

MaxIterationsReached = 3

The task exceeded the maximum allowed iterations or tool calls.

This status indicates the agent was stopped to prevent runaway execution. This can occur when the agent enters a loop of tool calls without converging on a final answer, or when the task genuinely requires more iterations than allowed.

Partial results from completed iterations are typically available.

Common Causes:

  • Complex tasks requiring many tool interactions
  • Model confusion leading to repetitive tool calls
  • Ambiguous user requests causing exploration loops
  • MaxIterations set too low for the task

What to do: Review partial results, consider increasing MaxIterations, or break the task into smaller subtasks.

Delegated = 4

The task was delegated to another agent.

This status indicates the current agent determined the task should be handled by a different, specialized agent and initiated delegation. The delegating agent should track the delegated task separately through the delegation system.

Delegation typically occurs in multi-agent systems where agents have specialized capabilities and can route tasks to the most appropriate handler.

What to do: The delegation result contains information about which agent received the task. Monitor the delegated execution through the delegation manager or wait for the delegate agent's response.

Examples

Example: Handling different execution outcomes

using LMKit.Agents;
using LMKit.Model;

using var model = new LM("path/to/model.gguf");
var agent = Agent.CreateBuilder()
    .WithModel(model)
    .WithPersona("Assistant")
    .Build();

var result = await agent.RunAsync("Analyze this data set.");

switch (result.Status)
{
    case AgentExecutionStatus.Completed:
        Console.WriteLine("Success!");
        Console.WriteLine(result.Content);
        break;

    case AgentExecutionStatus.Failed:
        Console.WriteLine($"Error: {result.Error?.Message}");
        break;

    case AgentExecutionStatus.Cancelled:
        Console.WriteLine("Task was cancelled by user.");
        break;

    case AgentExecutionStatus.MaxIterationsReached:
        Console.WriteLine("Task exceeded iteration limit.");
        Console.WriteLine($"Partial result: {result.Content}");
        break;

    case AgentExecutionStatus.Delegated:
        Console.WriteLine("Task was delegated to another agent.");
        break;
}

Remarks

AgentExecutionStatus indicates how an agent execution concluded. Check this status after calling Run(string, CancellationToken) or RunAsync(string, CancellationToken) to determine whether the task completed successfully and to handle different outcomes appropriately.

The AgentExecutionResult class provides convenience properties (IsSuccess, IsFailed, IsCancelled) that wrap common status checks.