Programmatic
DelegationManager with NameBasedDelegationRouter or your own logic. Explicit, deterministic.
Sometimes a single agent is the right tool. Often a generalist should hand off to a specialist: the writer asks the researcher, the supervisor delegates to a worker, the planner picks an executor. LM-Kit ships two complementary paths: programmatic delegation with explicit routing, and model-driven delegation where the LLM picks a worker via a tool call.
DelegationManager with NameBasedDelegationRouter or your own logic. Explicit, deterministic.
SupervisorOrchestrator auto-injects a delegate_to_agent tool. The supervisor picks workers by reasoning.
BeforeDelegation, AfterDelegation, WorkerTextCompletion events.
Delegation is not one pattern. Some workflows want explicit routing ("this customer is a B2B account, send to the enterprise agent"). Others want the supervisor to reason about the task and choose ("this email is a refund request, delegate to the refund agent"). LM-Kit supports both without forcing you to pick.
Routing rules are deterministic, regulatory, or testable in isolation. The supervisor would add cost without adding value.
The task description is fuzzy and the supervisor needs to reason about which specialist fits. Worker count is moderate so the prompt stays small.
A first-pass classifier deterministically routes between supervisor pools, and each pool has model-driven delegation inside.
using LMKit.Agents; using LMKit.Agents.Delegation; // Register specialised agents by name. var registry = new AgentRegistry(); registry.Register("refunds", AgentTemplates.Assistant(model).WithSystemPrompt("...").Build()); registry.Register("technical", AgentTemplates.Debugger(model).Build()); registry.Register("enterprise", AgentTemplates.Assistant(model).WithFormality(FormalityLevel.Formal).Build()); var delegator = new DelegationManager(registry, router: new NameBasedDelegationRouter()); // Deterministic routing based on metadata your code already knows. string target = ticket.Topic switch { "refund" => "refunds", "bug" => "technical", _ => "enterprise" }; var result = await delegator.DelegateAsync(new DelegationRequest(target, ticket.Body));
SupervisorOrchestrator auto-discovers a delegate_to_agent
tool inside the supervisor's tool set. The supervisor reads the task,
picks a worker, and calls the delegation tool. The orchestrator routes
the call, streams the worker's output back, and resumes.
using LMKit.Agents.Orchestration; var classifier = AgentTemplates.Classifier(model).Build(); var drafter = AgentTemplates.Creative(model).Build(); var reviewer = AgentTemplates.Reviewer(model).Build(); // One supervisor, three workers. The supervisor decides who handles what. var supervisor = new SupervisorOrchestrator( boss: AgentTemplates.Assistant(model).Build(), workers: new[] { classifier, drafter, reviewer }); // Observe delegation lifecycle. supervisor.BeforeDelegation += (s, e) => log.Info($"-> {e.ToAgent}: {e.Task}"); supervisor.AfterDelegation += (s, e) => log.Info($"<- {e.FromAgent} done"); // Stream the entire run, including worker output token-by-token. await foreach (var token in supervisor.StreamAsync("Process this incoming email")) { Console.Write(token.Text); }
Pipeline, Parallel, Router, Supervisor patterns explained side by side.
When delegation is one node in a larger graph.
Delegation tokens identify which worker is talking in a multi-agent UI.
Specialised templates make natural workers: Classifier, Reviewer, Extractor.
Working console demos on GitHub, step-by-step how-to guides on the docs site, and the API reference for the classes used on this page.