LearnedToolRouter

Models & Types ยท AiDotNet.Agentic.Tools

Learns which tools tend to help for which kinds of request, so an agent can be biased toward tools that worked well on similar past requests instead of relying only on static tool descriptions.

For Beginners

The agent remembers which tools were useful for questions like this one before, and gently prefers them next time โ€” so it gets better at picking the right tool with experience.

How It Works

This is a lightweight average-reward bandit over the toolset, keyed by request similarity (token overlap). Each run records an outcome per tool used (Record); RankTools orders the available tools by their mean reward on similar past requests (unseen tools are ranked optimistically so they still get tried), and BuildHint turns that ranking into a system-prompt nudge.

The reward table is exposed via Export / Import so it can be persisted across sessions.

Constructors

Constructor Summary
LearnedToolRouter()

Methods

Method Summary
IReadOnlyDictionary<string, IReadOnlyDictionary<string, ValueTuple<double, int>>> Export() Exports the learned reward table for persistence.
IReadOnlyList<string> RankTools(string request, IEnumerable<string> availableToolNames) Orders the available tools by learned preference for the request (highest mean reward first).
double ScoreFor(string request, string toolName) Gets the mean reward observed for a tool on requests similar to request.
string BuildHint(string request, IEnumerable<string> availableToolNames) Builds a short system-prompt hint that nudges the model toward the tools that worked best for similar requests, or null when there is no signal yet (nothing to nudge with).
void Import(IReadOnlyDictionary<string, IReadOnlyDictionary<string, ValueTuple<double, int>>> table) Imports a previously exported reward table, replacing any current state.
void Record(string request, string toolName, double reward) Records the outcome of using a tool for a request.