ion7-llm / util.messages

module

util.messages

Functions

M.is_valid_role

True when `role` is one of the four canonical roles the chat template knows how to render.

M.is_valid_role(role)
rolestring
→ boolean

M.user

Build a `user` message.

M.user(text)
textstring
→ table{ role = "user", content = text }

M.system

Build a `system` message.

M.system(text)
textstring
→ table

M.assistant

Build an `assistant` message. Optional `thinking` and `tool_calls` fields are passed through to the chat template — the template decides how to render them (Qwen3 wraps them in ``, Claude-style chats serialise tool_calls to a tool_use block, etc.).

M.assistant(text, extras)
textstring
extrastable?{ thinking?, tool_calls? }
→ table

M.tool_result

Build a `tool` message — the result of executing a tool call. The `tool_call_id` ties the result back to the assistant's call so the model can reason about which result corresponds to which call.

M.tool_result(tool_call_id, content)
tool_call_idstring
contentstring|tableStringified result, or a table —
→ table

M.validate

Validate a message shape. Raises on a malformed entry so a stray `nil` content or a typoed role surfaces at append time, not silently at apply_template time.

M.validate(msg)
msgtable

raises — When `msg` is malformed.