Interface IFunctionTool
- Namespace
- AiDotNet.Interfaces
- Assembly
- AiDotNet.dll
Defines the contract for tools (functions) that language models can invoke.
public interface IFunctionTool
Remarks
A function tool represents an external capability that a language model can use to accomplish tasks beyond text generation. Tools provide structured interfaces for actions like searching databases, performing calculations, fetching web content, or executing code.
For Beginners: A function tool is like giving the AI a superpower or tool to use.
Think of tools like apps on a smartphone:
- The phone (LLM) is powerful on its own
- Apps (tools) extend its capabilities
- The phone decides which app to use based on what you need
- Each app has specific inputs and outputs
Example tools:
- Calculator: Perform complex math
- Web Search: Find current information
- Database Query: Retrieve stored data
- Weather API: Get current weather
- Code Executor: Run programming code
How tools work with LLMs:
- User: "What's 15% of 2,847?"
- LLM: "I need to calculate this" → Calls Calculator tool
- Calculator: Executes calculation → Returns 427.05
- LLM: Uses result → "15% of 2,847 is 427.05"
Without tools, the LLM could only estimate. With tools, it gets exact answers.
Properties
Description
Gets the description of what the function does.
string Description { get; }
Property Value
Remarks
The description helps the language model understand when and how to use the tool. It should clearly explain the tool's purpose, capabilities, and limitations.
For Beginners: This explains what the tool does, like an app description.
Example: Name: "get_current_weather" Description: "Retrieves the current weather conditions for a specified location. Provides temperature, conditions, humidity, and wind speed. Works for cities worldwide."
The description helps the LLM decide:
- WHEN to use the tool: "User asked about weather? Use this tool!"
- WHAT it returns: "It gives temperature and conditions"
- LIMITATIONS: "Only current weather, not forecasts"
Good descriptions:
- Clear purpose: What the tool does
- Expected output: What it returns
- Limitations: What it can't do
- Use cases: When to use it
Name
Gets the name of the function tool.
string Name { get; }
Property Value
Remarks
The name should be descriptive and follow standard naming conventions (e.g., snake_case). This name is used by the language model to identify and invoke the tool.
For Beginners: This is the tool's identifier, like an app name.
Examples:
- "get_current_weather"
- "search_database"
- "calculate"
- "fetch_web_page"
Good names are:
- Descriptive: Clearly indicates what the tool does
- Concise: Not too long or complex
- Consistent: Follow a naming pattern (verb_noun)
- Unambiguous: Distinct from other tool names
ParameterSchema
Gets the JSON schema describing the function's parameters.
JObject ParameterSchema { get; }
Property Value
- JObject
Remarks
The schema defines what arguments the function accepts, their types, whether they're required, and validation rules. This follows the JSON Schema specification to enable structured function calling.
For Beginners: This is like a form that defines what information the tool needs.
Example for "get_current_weather": Schema: { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g., San Francisco, CA" }, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"], "description": "The temperature unit" } }, "required": ["location"] }
This tells the LLM:
- "location" is required (must provide)
- "unit" is optional (has default)
- "unit" must be either "celsius" or "fahrenheit"
- What each parameter means
The LLM uses this to generate valid function calls: get_current_weather(location="Paris, France", unit="celsius")
Methods
Execute(JObject)
string Execute(JObject arguments)
Parameters
argumentsJObject
Returns
ValidateArguments(JObject)
Validates that the provided arguments match the parameter schema.
bool ValidateArguments(JObject arguments)
Parameters
argumentsJObjectThe function arguments to validate.
Returns
- bool
True if arguments are valid; otherwise, false.
Remarks
Checks whether the provided arguments conform to the parameter schema, including type validation, required field presence, and constraint checking.
For Beginners: This checks if the arguments are correct before executing.
Example: Schema requires: location (required string), unit (optional, must be "celsius" or "fahrenheit")
Arguments: {"location": "Paris"} Validate() → True (location present, unit optional)
Arguments: {"unit": "celsius"} Validate() → False (missing required "location")
Arguments: {"location": "Paris", "unit": "kelvin"} Validate() → False ("kelvin" not in allowed values)
This helps:
- Catch errors early
- Provide clear error messages
- Prevent invalid operations
- Ensure data quality