ion7-llm / tools.spec

module

tools.spec

ion7.llm.tools.Tool

name string
description string
schema table JSON Schema for the arguments object.
handler function? Optional `(args) -> result` dispatcher.

ion7.llm.tools.ToolSet

_by_name table ion7.llm.tools.Tool>
_list ion7.llm.tools.Tool[]

Functions

Tool.new

Build a tool definition.

Tool.new(fields)
fieldstable
→ ion7.llm.tools.Tool

Tool:to_template_entry

Render a single tool to the `{ type = "function", function = … }` shape modern chat templates expect when tool definitions are injected into the system message.

Tool:to_template_entry()
→ table

Tool:dispatch

Execute the tool locally. Raises if the tool has no handler. Wraps the user's handler in `pcall` so a Lua error becomes a structured error result instead of poisoning the engine loop.

Tool:dispatch(args)
argstable
→ any|tableresult OR `{ error = "..." }` on handler failure.

ToolSet.new

Build a tool set.

ToolSet.new(tools)
toolsion7.llm.tools.Tool[]?Optional initial population.
→ ion7.llm.tools.ToolSet

ToolSet:add

Add a tool to the set. Names must be unique.

ToolSet:add(tool)
toolion7.llm.tools.Tool
→ ion7.llm.tools.ToolSetself

ToolSet:find

Look up a tool by name. Returns nil when unknown.

ToolSet:find(name)
namestring
→ ion7.llm.tools.Tool?

ToolSet:count

Number of registered tools.

ToolSet:count()
→ integer

ToolSet:iter

Iterate over the tools in registration order.

ToolSet:iter()
→ function

ToolSet:to_json

Render every tool to a JSON string usable in a system prompt or chat-template `tools` parameter. Format follows the OpenAI / modern chat-template convention : [{ "type": "function", "function": { name, description, parameters } }, ...]

ToolSet:to_json()
→ string