Table of Contents

Constructor ConditionalNode

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

ConditionalNode(string, Func<NodeContext, CancellationToken, Task<string>>, IReadOnlyDictionary<string, IOrchestrationNode>, IOrchestrationNode)

Initializes a new ConditionalNode.

public ConditionalNode(string name, Func<NodeContext, CancellationToken, Task<string>> selector, IReadOnlyDictionary<string, IOrchestrationNode> branches, IOrchestrationNode defaultBranch = null)

Parameters

name string

Stable trace name for this node.

selector Func<NodeContext, CancellationToken, Task<string>>

Async function that returns the route name for the current context.

branches IReadOnlyDictionary<string, IOrchestrationNode>

Map of route name to node.

defaultBranch IOrchestrationNode

Optional fallback when the selector returns an unknown route.

Examples

Route a request to the technical or business expert based on a keyword:

using LMKit.Model;
using LMKit.Agents;
using LMKit.Agents.Orchestration.Nodes;

using var model = LM.LoadFromModelID("qwen3:8b"); var techExpert = Agent.CreateBuilder(model).WithPersona("TechExpert").Build(); var bizExpert = Agent.CreateBuilder(model).WithPersona("BizExpert").Build();

var router = new ConditionalNode("route", ctx => ctx.Input.Contains("api", StringComparison.OrdinalIgnoreCase) ? "tech" : "biz", new Dictionary<string, IOrchestrationNode> { ["tech"] = new AgentNode("tech", techExpert), ["biz"] = new AgentNode("biz", bizExpert) });

var orchestrator = new GraphOrchestrator(router); var result = await orchestrator.ExecuteAsync("How do I version a public API?");

ConditionalNode(string, Func<NodeContext, string>, IReadOnlyDictionary<string, IOrchestrationNode>, IOrchestrationNode)

Convenience overload for synchronous selectors.

public ConditionalNode(string name, Func<NodeContext, string> selector, IReadOnlyDictionary<string, IOrchestrationNode> branches, IOrchestrationNode defaultBranch = null)

Parameters

name string
selector Func<NodeContext, string>
branches IReadOnlyDictionary<string, IOrchestrationNode>
defaultBranch IOrchestrationNode
Share