ToolCollection

Models & Types · AiDotNet.Agentic.Tools

A named set of executable tools: registers IAgentTool instances, exposes their AiToolDefinitions for a chat request, and dispatches model tool-calls to the right tool.

For Beginners

Think of this as the labeled toolbox you give the model. It can list what’s inside (so the model knows its options) and, when the model asks to use a specific tool, it finds that tool, runs it, and packages the answer to hand back to the model.

How It Works

This is the bridge between the model and your code during a tool-calling turn. Register tools, hand GetDefinitions to Tools, and when the model replies with ToolCallContent, call InvokeToToolMessageAsync to run the tool and produce the Tool message to append before the next model call.

Constructors

Constructor Summary
ToolCollection()

Properties

Property Summary
IReadOnlyList<IAgentTool> Tools { get; } Gets the registered tools.
int Count { get; } Gets the number of registered tools.

Methods

Method Summary
IAgentTool Get(string name) Gets a tool by name.
IReadOnlyList<AiToolDefinition> GetDefinitions() Produces the provider-facing definitions for all registered tools, for use as Tools.
Task<ChatMessage> InvokeToToolMessageAsync(ToolCallContent call, CancellationToken cancellationToken) Executes a model-emitted tool call and wraps the result in a Tool message ready to append to the conversation before the next model call.
Task<ToolInvocationResult> InvokeAsync(ToolCallContent call, CancellationToken cancellationToken) Executes a model-emitted tool call and returns the raw result.
ToolCollection Add(IAgentTool tool) Registers a tool.
ToolCollection AddDelegate(string name, string description, Delegate function) Creates a tool from a delegate and registers it.
ToolCollection AddFrom(object target) Scans an object for AgentToolAttribute-annotated methods and registers each as a tool.
bool Contains(string name) Determines whether a tool with the given name is registered.