ToolCapable

interface ToolCapable

Interface for chat clients that support automatic tool execution in a loop.

When the model requests a tool call, the client can automatically:

  1. Parse the tool call arguments.

  2. Find and execute the matching KoryTool.

  3. Send the tool result back to the model.

  4. Repeat until the model produces a text response.

This loop can be disabled with autoExecute = false, and callbacks are provided for monitoring tool calls.

Types

Link copied to clipboard
typealias ToolCallCallback = suspend (choiceIndex: Int, toolName: String, argsJson: String) -> Unit?

Callback invoked when a tool is called. Parameters: (toolName, argsJson).

Link copied to clipboard

Functions

Link copied to clipboard
abstract fun chatStreamWithTools(request: ChatRequest, autoExecute: Boolean = true, maxSteps: Int? = null, currentStep: Int = 0, onFullToolCollected: ToolCapable.ToolCallCallback = null, onToolCall: ToolCapable.ToolCallCallback = null, onToolExecutionFailed: ToolCapable.ToolExecutionFailedCallback = null): Flow<ChatChunk>

Streams a chat with automatic tool execution.

abstract fun chatStreamWithTools(autoExecute: Boolean = true, maxSteps: Int? = null, currentStep: Int = 0, onFullToolCollected: ToolCapable.ToolCallCallback = null, onToolCall: ToolCapable.ToolCallCallback = null, onToolExecutionFailed: ToolCapable.ToolExecutionFailedCallback = null, block: ChatRequestBuilder.() -> Unit): Flow<ChatChunk>

Streams a chat with tools using full DSL configuration.

Link copied to clipboard
abstract suspend fun chatWithTools(request: ChatRequest, autoExecute: Boolean = true, maxSteps: Int? = null, currentStep: Int = 0, onToolCall: ToolCapable.ToolCallCallback = null, onToolExecutionFailed: ToolCapable.ToolExecutionFailedCallback = null): ChatResponse

Sends a chat request with automatic tool execution.

abstract suspend fun chatWithTools(autoExecute: Boolean = true, maxSteps: Int? = null, currentStep: Int = 0, onToolCall: ToolCapable.ToolCallCallback = null, onToolExecutionFailed: ToolCapable.ToolExecutionFailedCallback = null, block: ChatRequestBuilder.() -> Unit): ChatResponse

Sends a chat request with tools using full DSL configuration.

Link copied to clipboard
inline suspend fun ToolCapable.chatWithToolsCatching(request: ChatRequest, autoExecute: Boolean = true, maxSteps: Int? = null, currentStep: Int = 0, noinline onToolCall: ERROR CLASS: Symbol not found for ToolCapable.ToolCallCallback = null, noinline onToolExecutionFailed: ERROR CLASS: Symbol not found for ToolCapable.ToolExecutionFailedCallback = null): Result<ChatResponse>

Sends a chat request with tool support and wraps the result in a Result.

inline suspend fun ToolCapable.chatWithToolsCatching(autoExecute: Boolean = true, maxSteps: Int? = null, currentStep: Int = 0, noinline onToolCall: ERROR CLASS: Symbol not found for ToolCapable.ToolCallCallback = null, noinline onToolExecutionFailed: ERROR CLASS: Symbol not found for ToolCapable.ToolExecutionFailedCallback = null, noinline block: ChatRequestBuilder.() -> Unit): Result<ChatResponse>

Sends a chat request with tool support using the request DSL and wraps the result in a Result.

Link copied to clipboard
abstract suspend fun executeTool(toolCall: Content.ToolCall, toolMap: Map<String, KoryTool<*, *>>): String

Executes a tool call by finding the matching tool and running it.