The tools namespace
Defining a tool
Controlling the loop
tools.register are offered to every generation. Tools passed in
options.tools apply to that call alone.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Let the model call your functions
RunAnywhere.llm.tools.register(weatherTool) { args ->
val city = args["city"]?.stringValue ?: ""
mapOf("tempC" to ToolValue.of(fetchTemp(city)))
}
val result = RunAnywhere.llm.generate("What is the weather in Lisbon?")
suspend fun register(
tool: ToolDefinition,
executor: suspend (Map<String, ToolValue>) -> Map<String, ToolValue>
)
suspend fun unregister(name: String)
suspend fun list(): List<ToolDefinition>
val weatherTool = ToolDefinition(
name = "get_weather",
description = "Get the current temperature for a city",
parameters = listOf(
ToolParameter(
name = "city",
type = ParameterType.String,
description = "City name",
required = true
)
)
)
| Field | Default | Meaning |
|---|---|---|
tools | empty | Tools for this call only |
toolChoice | Auto | Whether the model may call a tool |
maxToolCalls | 5 | Cap on calls in one exchange |
val result = RunAnywhere.llm.generate(
"Weather in Lisbon and Porto?",
LlmOptions(toolChoice = ToolChoice.Auto, maxToolCalls = 3)
)
tools.register are offered to every generation. Tools passed in
options.tools apply to that call alone.
RunAnywhere.llm.tools.unregister("get_weather")
val registered = RunAnywhere.llm.tools.list()