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
- The supervisor receives the task and the list of available workers.
- The supervisor decides which worker(s) to delegate to via the
delegate_to_agenttool. - Worker results are returned to the supervisor.
- 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:
- ToolCall for
delegate_to_agent(supervisor-scope; requires StreamToolCalls) - Delegation (semantic signal with
from_agent,to_agent,taskmetadata) - AgentStarted for the worker
- Worker Content / Thinking / nested ToolCall / ToolResult
- AgentCompleted for the worker
- 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
nullto 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_agenttool. 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.