Tool Basics
A tool is a Kotlin class that implementsTool<TArgs, TResult> with:
- Arguments (
TArgs): Parameters the LLM provides when calling the tool - Result (
TResult): What the tool returns to the LLM - Annotations: Descriptions that help the LLM understand when and how to use the tool
Creating Custom Tools
Using ToolSet and Annotations
The easiest way to create tools is with the@Tool annotation and ToolSet:
WeatherTools.kt
Registering Tools from ToolSet
Convert yourToolSet to tools and register them:
Built-in Tools
Koog provides ready-to-use tools for common operations:File Tools
Shell Tools
User Interaction Tools
Advanced Tool Implementation
Manual Tool Implementation
For more control, implement theTool interface directly:
Stateful Tools
Tools can maintain state for tracking operations:Tool Best Practices
Clear Descriptions
Provide detailed descriptions to help the LLM understand when to use each tool:Error Handling
Handle errors gracefully and return meaningful messages:Type Safety
Use serializable data classes for complex arguments:Structured Outputs
Return structured data when useful:Merging Tool Registries
Combine multiple tool registries:Next Steps
- Graph Workflows — Create multi-step workflows with tools
- Testing Agents — Mock and test tool behavior
- Streaming — Handle streaming with tool calls