Table of Contents

Class SupervisorOrchestrator

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

Orchestrator where a supervisor agent dynamically coordinates worker agents.

The supervisor agent decides which worker agents to invoke and how to combine their outputs to accomplish the task. This enables flexible, adaptive workflows.

public sealed class SupervisorOrchestrator : OrchestratorBase, IOrchestrator
Inheritance
SupervisorOrchestrator
Implements
Inherited Members
Extension Methods

Examples

var supervisor = new SupervisorOrchestrator(coordinatorAgent)
    .AddWorker("research", researchAgent)
    .AddWorker("code", codeAgent)
    .AddWorker("review", reviewAgent);

supervisor.BeforeDelegation += (_, e) => Console.WriteLine($"-> {e.Request.TargetAgentName}");
supervisor.AfterDelegation  += (_, e) => Console.WriteLine($"<- {e.Result.AgentName}");

var result = await supervisor.ExecuteAsync("Build a REST API for user management");

Remarks

How It Works

  1. The supervisor receives the task and the list of available workers.
  2. The supervisor decides which worker(s) to delegate to via the delegate_to_agent tool.
  3. Worker results are returned to the supervisor.
  4. The supervisor continues until it produces a final answer.

Use Cases

  • Complex tasks requiring dynamic agent selection
  • Tasks where the execution path isn't known in advance
  • Collaborative problem-solving with specialized agents

Model Requirement
Reliable delegation depends on the supervisor model being able to emit real tool-call tokens for the delegate_to_agent tool. Small general-purpose models (under the ~4B parameter class) may instead emit pseudo tool tags (e.g. literal <tool_call> text) which the runtime does not interpret as delegation. Use a tool-calling capable model such as Qwen3 ≥4B, Gemma 4 E4B, or Phi-4 for production supervisors.

Worker Registration
When the supervisor prompt refers to a worker by a specific name, always use AddWorker(string, Agent) with the exact name. Passing only an Agent registers it under the agent's persona, which can desynchronize from the name the supervisor emits in tool-call arguments.

Observing Delegation
Subscribe to BeforeDelegation, AfterDelegation, and WorkerTextCompletion directly on the orchestrator. These fire for every delegate_to_agent invocation in both streaming and non-streaming modes and do not require calling EnableDelegation(). The separate DelegationManager events are for programmatic delegation via DelegationManager.DelegateAsync and will not fire during orchestration.

Streaming Token Contract
When an IOrchestrationStreamHandler is attached, each delegation produces tokens in this canonical order:

  1. ToolCall for delegate_to_agent (supervisor-scope; requires StreamToolCalls)
  2. Delegation (semantic signal with from_agent, to_agent, task metadata)
  3. AgentStarted for the worker
  4. Worker Content / Thinking / nested ToolCall / ToolResult
  5. AgentCompleted for the worker
  6. ToolResult for delegate_to_agent

UI code should route on Delegation rather than parsing tool-call metadata.

Constructors

SupervisorOrchestrator(Agent)

Initializes a new instance of the SupervisorOrchestrator class.

Fields

DefaultSupervisorPrompt

The default supervisor prompt template.

Properties

Name

Gets the name of this orchestrator.

Supervisor

Gets the supervisor agent.

SupervisorPromptTemplate

Gets or sets the system prompt template for the supervisor.

Use {workers} as a placeholder for the worker descriptions. Set to null to use the supervisor's existing prompt.

Workers

Gets the registered worker agents.

Methods

AddWorker(Agent)

Adds a worker agent, registered under its default identity name.

AddWorker(string, Agent)

Adds a named worker agent. Recommended over AddWorker(Agent).

ExecuteCoreAsync(OrchestrationContext, OrchestrationOptions, CancellationToken)

Executes the supervisor orchestration.

Events

AfterDelegation

Fired after a delegation completes, with the worker's result attached.

BeforeDelegation

Fired before the supervisor delegates a task to a worker agent via the delegate_to_agent tool. Handlers can inspect or cancel the request.

WorkerTextCompletion

Fired for each text segment produced by a worker agent during delegation. Subscribe to observe worker output in real time without configuring a stream handler.

Share