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.user
Build a `user` message.
M.system
Build a `system` message.
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 `
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.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.
raises — When `msg` is malformed.