Interface IAgentExecutor
Defines the contract for executing agent tasks.
An executor is responsible for running an agent against input prompts, managing the execution loop, handling tool calls, and producing results.
public interface IAgentExecutor
Examples
Example: Use IAgentExecutor to run an agent
using LMKit.Model;
using LMKit.Agents;
using System;
using System.Threading.Tasks;
async Task RunAgentAsync(IAgentExecutor executor, Agent agent, string userInput)
{
AgentExecutionResult result = await executor.ExecuteAsync(agent, userInput);
if (result.Status == AgentExecutionStatus.Completed)
{
Console.WriteLine($"Agent response: {result.Content}");
}
else
{
Console.WriteLine($"Execution failed: {result.Status}");
}
}
// Usage
LM model = LM.LoadFromModelID("llama-3.2-3b");
Agent agent = new AgentBuilder()
.WithModel(model)
.WithPersona("Assistant")
.Build();
IAgentExecutor executor = new AgentExecutor();
await RunAgentAsync(executor, agent, "Hello!");
Remarks
Executor Responsibilities
- Inject the agent's identity (persona/instruction) into the conversation context.
- Apply the configured planning strategy during generation.
- Handle tool call loops according to the agent's tool policy.
- Manage memory recall and context injection.
- Enforce iteration limits and cancellation.
Implementation Notes
Implementations should be stateless regarding the task being executed.
All state should be contained in the Agent instance and any
underlying conversation context.
Methods
- Execute(Agent, string, CancellationToken)
Executes a single task synchronously with the specified agent.
- ExecuteAsync(Agent, string, CancellationToken)
Executes a single task with the specified agent.