Defining tools
Create a complete C# tool with metadata, input validation, and structured output.
This example counts text locally. It introduces the tool contract without depending on a remote API or database.
Install the package
The tool types use the Runiq.AI.Agents.Tools namespace.
Implement the tool
Create Tools/TextStatsTool.cs in your application:
For Hello Runiq, the result is 11 characters and 2 words. Character count follows .NET string.Length; it is not a count of visible Unicode characters. Word count is a whitespace split, not linguistic tokenization.
Name and describe the operation
The runtime name is text_stats, not the C# class name. Reference that name in instructions.
Describe what the operation returns and which input it needs. Prefer “Counts characters and whitespace-separated words in supplied text” over “Text helper.”
Registration requirements
| Requirement | Reason |
|---|---|
| A concrete tool class | The runtime creates an instance. |
Exactly one IRuniqTool<TInput, TOutput> contract | Input and output types must be unambiguous. |
[RuniqTool] metadata | The runtime needs a name and description. |
A public ExecuteAsync method with input and cancellation parameters | The current invoker locates this method through reflection. |
| Distinct names for different registered tool types | The host rejects name collisions. |
The same tool type can be shared by multiple agents. Attach it only once to each agent.
Design input and output
Use explicit properties rather than a generic JSON string inside the input. Deserialization provides a typed value, but does not replace business validation. Check required values, ranges, and permissions in your implementation.
Return the data the caller needs. In an agent run, this output is returned to the model; in direct Studio testing, it is shown as the tool result.
For an operation with no arguments, use EmptyToolInput. It still needs the metadata attribute and the same execution signature.
Use application services
Tools can constructor-inject registered services. Runiq creates the tool with ActivatorUtilities, resolving constructor dependencies from the invocation's service provider. Register those dependencies before building the host.
Keep data access and business logic in those services. See Patterns for organization and lifetime considerations.