Solutions · AI agents · Delegation

One agent asks another.

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.

Programmatic + model-driven Custom routers Streaming worker output

Programmatic

DelegationManager with NameBasedDelegationRouter or your own logic. Explicit, deterministic.

Model-driven

SupervisorOrchestrator auto-injects a delegate_to_agent tool. The supervisor picks workers by reasoning.

Observable

BeforeDelegation, AfterDelegation, WorkerTextCompletion events.

Pick the right path

Programmatic vs model-driven delegation.

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.

Use programmatic when...

Routing rules are deterministic, regulatory, or testable in isolation. The supervisor would add cost without adding value.

Use model-driven when...

The task description is fuzzy and the supervisor needs to reason about which specialist fits. Worker count is moderate so the prompt stays small.

Use both when...

A first-pass classifier deterministically routes between supervisor pools, and each pool has model-driven delegation inside.

Programmatic delegation

Explicit routing, full control.

DelegationManager.cs
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));
Model-driven delegation

The supervisor picks the worker.

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.

SupervisorOrchestrator.cs
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);
}
Related capabilities

Pair with orchestration and streaming.

Multi-agent workflows

Pipeline, Parallel, Router, Supervisor patterns explained side by side.

Multi-agent page

Graph orchestration

When delegation is one node in a larger graph.

Graph page

Streaming

Delegation tokens identify which worker is talking in a multi-agent UI.

Streaming page

Templates

Specialised templates make natural workers: Classifier, Reviewer, Extractor.

Templates page

Demos & docs

Build it. Read it. Try it.

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.

Generalist plus specialists.

Get Community Edition Download