Method EnableDelegation
EnableDelegation()
Registers a DelegateTool for this agent, or returns the existing instance if one has already been registered.
public DelegateTool EnableDelegation()
Returns
- DelegateTool
The delegate tool, or null if no delegates are configured.
Examples
Enabling delegation for a coordinator agent:
using LMKit.Model;
using LMKit.Agents;
using var model = new LM("path/to/model.gguf");
// Create specialist agents
var codeAgent = new Agent(
new AgentIdentity("Coder", "Write clean, efficient code."),
model
);
var reviewAgent = new Agent(
new AgentIdentity("Reviewer", "Review code for bugs and improvements."),
model
);
// Create coordinator with delegation
var coordinator = new Agent(model);
coordinator.Identity = new AgentIdentity(
"Project Lead",
"Coordinate coding and review tasks."
);
coordinator.Delegates = new AgentRegistry();
coordinator.Delegates.Register("coder", codeAgent);
coordinator.Delegates.Register("reviewer", reviewAgent);
// Enable the delegation tool
var delegateTool = coordinator.EnableDelegation();
if (delegateTool != null)
{
Console.WriteLine("Delegation enabled!");
}
// Now the coordinator can delegate tasks
var result = await coordinator.RunAsync(
"Write a function to sort a list, then review it."
);
Remarks
The delegation tool allows this agent to hand off subtasks to agents in its Delegates registry. The tool is automatically registered in the agent's tool registry.
Call this method after configuring the Delegates registry.
Idempotent. Repeated calls return the same DelegateTool instance, so event subscriptions (BeforeDelegation, AfterDelegation, AfterTextCompletion) survive subsequent calls, including the internal call made by SupervisorOrchestrator.
Tip. If you are wrapping this agent in a
SupervisorOrchestrator, prefer subscribing to the
orchestrator's BeforeDelegation, AfterDelegation, and
WorkerTextCompletion events instead. They are the canonical surface for
observing orchestration-driven delegation and do not require calling this method.