Message
Object Hierarchy:
Description:
public class Message : Object, Serializable
Message class for chat conversations with role-based behavior.
Messages have different roles that control their behavior and visibility: * "user" / "user-sent": User messages (user-sent is visible in
UI) * "assistant": LLM response (not directly visible, use content-stream instead) * "content-stream" / "content-non-stream": Visible
assistant content * "think-stream": Thinking output (for models that support it) * "tool": Tool execution results * "ui": UI messages
displayed in chat * "ui-warning": User-friendly warning in chat (e.g. "we couldn't use that model, using default") * "ui-waiting":
Transient placeholder shown while waiting for response (e.g. "waiting for a reply", "Refining..."); content is the label; animated dots;
cleared when content arrives * "system": System prompts * "end-stream": Stream end marker (not displayed) * "done": Completion marker (not
displayed)
Role changes automatically set flags (is_user, is_llm, is_content, etc.) for easy filtering and UI display decisions.
Example
// Create a user message
var msg = new Message("user-sent", "Hello!");
// Check message type
if (msg.is_user && msg.is_ui_visible) {
// Display in UI
}
// Create streaming content message
var content_msg = new Message("content-stream", "");
content_msg.chat_content = "Partial response...";
Content:
Properties:
Creation methods:
- public Message (string role, string content, string thinking = "")
- public Message.tool_call_fail (ToolCall tool_call, Error e)
Constructor for tool call failure messages. Used when tool execution
fails with an error.
- public Message.tool_call_invalid (ToolCall tool_call, string err_message)
Constructor for invalid tool call messages. Used when a tool is not
found or not available.
- public Message.tool_reply (string tool_call_id, string name, string content)
Constructor for tool response messages. Used to send tool execution
results back to OLLMchat.
- public Message.with_tools (ArrayList<ToolCall> tool_calls)
Constructor for assistant messages with tool calls. Used when Ollama
requests tool execution (tool call request from Ollama).
Methods:
- public override bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Node property_node)
- public string? extract_last_code ()
Extracts code content from markdown code block syntax in this
message's content. Handles both `language and ` formats. Returns the last code block if multiple exist.
- public void serialize_images (Object message_obj)
Writes base64-encoded images onto the serialized message object at
send time. Uses this.images (paths only). Updates message_obj in place; does not mutate the Message. Validates: file exists, MIME type
is image. Skips invalid paths.
- public override Node serialize_property (string property_name, Value value, ParamSpec pspec)
Fields:
Inherited Members:
All known members inherited from class GLib.Object
- @get
- @new
- @ref
- @set
- add_toggle_ref
- add_weak_pointer
- bind_property
- connect
- constructed
- disconnect
- dispose
- dup_data
- dup_qdata
- force_floating
- freeze_notify
- get_class
- get_data
- get_property
- get_qdata
- get_type
- getv
- interface_find_property
- interface_install_property
- interface_list_properties
- is_floating
- new_valist
- new_with_properties
- newv
- notify
- notify_property
- ref_count
- ref_sink
- remove_toggle_ref
- remove_weak_pointer
- replace_data
- replace_qdata
- set_data
- set_data_full
- set_property
- set_qdata
- set_qdata_full
- set_valist
- setv
- steal_data
- steal_qdata
- thaw_notify
- unref
- watch_closure
- weak_ref
- weak_unref
All known members inherited from interface Json.Serializable
- default_deserialize_property
- default_serialize_property
- deserialize_property
- find_property
- get_property
- list_properties
- serialize_property
- set_property