Tool calling for AntRunner
$ dotnet add package AntRunner.ToolCallingThe AntRunner.ToolCalling library provides a fully decoupled framework for defining and executing tool calls within AI assistant workflows. It separates assistant definitions and tool calling logic from the Assistants API, enabling flexible integration with any .NET library that supports the OpenAI Chat Completions API.
This library enables assistants to dynamically invoke external tools or functions during conversations. Tools can be defined using OpenAPI specifications or as local functions, and the library manages the execution of these tools, including handling web API requests and processing responses.
[Tool], [Parameter], and related attributes to declaratively register tools, eliminating the need for hardcoded schema generators.ToolContractRegistry automatically generates OpenAPI schemas from method signatures and attributes at runtime.CrewBridgeSchemaGenerator enables multi-agent workflows by exposing crew member assistants as callable tools.Tools can be registered using attributes instead of static JSON schema files:
[Tool(OperationId = "search_documents", Summary = "Search for documents by query")]
public static async Task<string> SearchDocuments(
[Parameter(Description = "The search query")] string query,
[Parameter(Description = "Maximum results to return")] int maxResults = 10)
{
// Implementation
}
| Attribute | Target | Description |
|---|---|---|
[Tool] | Method | Marks a method as a callable tool with OperationId and Summary |
[Parameter] | Parameter | Provides description, default value, and visibility for parameters |
[RequiresNotebookContext] | Method | Indicates the tool needs notebook context injection |
[OAuth] | Method | Specifies OAuth token handling policy (None, Forward, Required) |
The CrewBridgeSchemaGenerator generates OpenAPI schemas for multi-agent orchestration, allowing a lead assistant to delegate tasks to crew member assistants:
var schema = CrewBridgeSchemaGenerator.GetSchema(new[] { "ResearchAgent", "WriterAgent", "ReviewerAgent" });
This creates tool definitions that route through Agent.Invoke for assistant-to-assistant communication.
The AntRunner.Chat.ChatRunner class illustrates how to use the AntRunner.ToolCalling library in practice. It demonstrates:

This sequence diagram illustrates the interaction between the ChatRunner class and the AntRunner.ToolCalling library during a chat run, highlighting tool calling lifecycle and execution.
For detailed implementation and usage, see the source code in \AntRunner\AntRunner.Chat\AntRunner.Chat\ChatRunner.cs.