Class DefaultToolRouter
Embedding-based tool router.
Flow: ToolRegistry (full tool list) ??embed each tool's description text ??ToolEmbeddingIndex (in-memory) ??embed user message ??cosine similarity search ??pass only top-K tools to the LLM (reduces prompt token count)
If total tool count is ??topK, the full list is returned without filtering. Falls back to the full list if embedding fails.
Implements
Inherited Members
Namespace: Glitch9.AIDevKit.Agents
Assembly: Glitch9.AIDevKit.dll
Syntax
public class DefaultToolRouter : IToolRouter
Constructors
| Edit this page View SourceDefaultToolRouter(Model)
Declaration
public DefaultToolRouter(Model embeddingModel)
Parameters
| Type | Name | Description |
|---|---|---|
| Model | embeddingModel |
Methods
| Edit this page View SourceInitialize(ToolRegistry, ILogger)
Declaration
public void Initialize(ToolRegistry registry, ILogger logger)
Parameters
| Type | Name | Description |
|---|---|---|
| ToolRegistry | registry | |
| ILogger | logger |
Invalidate()
Marks the index as stale so it is rebuilt on the next route request.
Declaration
public void Invalidate()
RouteAsync(string, int, CancellationToken)
Returns the top-K tools most relevant to the user message. Returns the full list if there is no embedding model or the total tool count is ??topK.
Declaration
public UniTask<List<Tool>> RouteAsync(string userMessage, int topK = 12, CancellationToken ct = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userMessage | |
| int | topK | |
| CancellationToken | ct |
Returns
| Type | Description |
|---|---|
| UniTask<List<Tool>> |
SetEmbeddingModel(Model)
Declaration
public void SetEmbeddingModel(Model model)
Parameters
| Type | Name | Description |
|---|---|---|
| Model | model |