ToolRegistry

A registry that manages a collection of tools for use by agents.

ToolRegistry serves as a central repository for all tools available to an agent. It provides functionality to register tools and retrieve them by name or type.

Key features:

  • Maintains a unique collection of named tools

  • Provides methods to retrieve tools by name or type

  • Supports merging multiple registries

Usage examples:

  1. Creating a registry:

     val registry = ToolRegistry {
    tool(MyCustomTool())
    tool(AnotherTool())
    }
  2. Merging registries:

     val combinedRegistry = registry1 + registry2

Constructors

Link copied to clipboard
constructor(init: ToolRegistryBuilder.() -> Unit)

Creates a new ToolRegistry using the provided builder initialization block.

Types

Link copied to clipboard
object Companion

Companion object providing factory methods and constants for ToolRegistry.

Properties

Link copied to clipboard
val tools: List<ToolBase<*, *>>

Provides an immutable list of tools currently available in the registry.

Functions

Link copied to clipboard
fun add(tool: ToolBase<*, *>)

Adds a tool to the registry if it is not already present.

Link copied to clipboard
fun addAll(vararg tools: ToolBase<*, *>)

Adds multiple tools to the registry.

Link copied to clipboard
inline fun <T : ToolBase<*, *>> getTool(): T

Retrieves a tool by its type from registry.

fun getTool(toolName: String): ToolBase<*, *>

Retrieves a tool by its name from the registry.

Link copied to clipboard
fun getToolOrNull(toolName: String): ToolBase<*, *>?

Retrieves a tool by its name from the registry, or null if not found.

Link copied to clipboard
operator fun plus(toolRegistry: ToolRegistry): ToolRegistry

Combines the tools from this registry and the provided registry into a new ToolRegistry.