Table of Contents

Class AgentRouter

Namespace
JD.AI.Gateway.Services
Assembly
JD.AI.Gateway.dll

Routes inbound channel messages to agents in the agent pool. Supports routing strategies: round-robin, dedicated (1:1 channel:agent), or tag-based.

public sealed class AgentRouter
Inheritance
AgentRouter
Inherited Members

Constructors

AgentRouter(AgentPoolService, IChannelRegistry, IEventBus, ILogger<AgentRouter>)

public AgentRouter(AgentPoolService pool, IChannelRegistry channels, IEventBus events, ILogger<AgentRouter> logger)

Parameters

pool AgentPoolService
channels IChannelRegistry
events IEventBus
logger ILogger<AgentRouter>

Fields

ChannelTypeMetadataKey

public const string ChannelTypeMetadataKey = "gateway.channelType"

Field Value

string

RouteKeyMetadataKey

public const string RouteKeyMetadataKey = "gateway.routeKey"

Field Value

string

Methods

GetAgentForChannel(string)

Get the agent ID currently mapped to a channel, or null.

public string? GetAgentForChannel(string channelId)

Parameters

channelId string

Returns

string

GetMappings()

Get all current channel-to-agent mappings.

public IReadOnlyDictionary<string, string> GetMappings()

Returns

IReadOnlyDictionary<string, string>

MapChannel(string, string)

Map a channel to a specific agent ID.

public void MapChannel(string channelId, string agentId)

Parameters

channelId string
agentId string

RouteAsync(ChannelMessage, IChannel?, CancellationToken)

Route an inbound message to the mapped agent and send the response via the provided source channel.

public Task<string?> RouteAsync(ChannelMessage message, IChannel? sourceChannel, CancellationToken ct = default)

Parameters

message ChannelMessage
sourceChannel IChannel
ct CancellationToken

Returns

Task<string>

RouteAsync(ChannelMessage, CancellationToken)

Route an inbound message to the mapped agent and return the response.

public Task<string?> RouteAsync(ChannelMessage message, CancellationToken ct = default)

Parameters

message ChannelMessage
ct CancellationToken

Returns

Task<string>