Message

a single chat message in a conversation.

  • role: who the message is from
  • content: the text content
  • tool-calls: non-empty for assistant messages that invoke tools
  • tool-call-id: non-empty for tool result messages (role = Tool)

Use the constructors in the Message module instead of Message.init directly.

assistant

defn

(Fn [(Ref String a)] Message)

                        (assistant s)
                    

creates an assistant message.

content

instantiate

(Fn [(Ref Message a)] (Ref String a))

gets the content property of a Message.

copy

instantiate

(Fn [(Ref Message a)] Message)

copies a Message.

delete

instantiate

(Fn [Message] ())

deletes a Message. Should usually not be called manually.

from-response

defn

(Fn [(Ref LLMResponse a)] Message)

                        (from-response r)
                    

converts an LLMResponse into an assistant message, preserving any tool calls for conversation history.

init

instantiate

(Fn [Role, String, (Array ToolCall), String] Message)

creates a Message.

prn

instantiate

(Fn [(Ref Message a)] String)

converts a Message to a string.

role

instantiate

(Fn [(Ref Message a)] (Ref Role a))

gets the role property of a Message.

set-content

instantiate

(Fn [Message, String] Message)

sets the content property of a Message.

set-content!

instantiate

(Fn [(Ref Message a), String] ())

sets the content property of a Message in place.

set-role

instantiate

(Fn [Message, Role] Message)

sets the role property of a Message.

set-role!

instantiate

(Fn [(Ref Message a), Role] ())

sets the role property of a Message in place.

set-tool-call-id

instantiate

(Fn [Message, String] Message)

sets the tool-call-id property of a Message.

set-tool-call-id!

instantiate

(Fn [(Ref Message a), String] ())

sets the tool-call-id property of a Message in place.

set-tool-calls

instantiate

(Fn [Message, (Array ToolCall)] Message)

sets the tool-calls property of a Message.

set-tool-calls!

instantiate

(Fn [(Ref Message a), (Array ToolCall)] ())

sets the tool-calls property of a Message in place.

str

instantiate

(Fn [(Ref Message a)] String)

converts a Message to a string.

system

defn

(Fn [(Ref String a)] Message)

                        (system s)
                    

creates a system message.

to-json

defn

(Fn [(Ref Message a)] JSON)

                        (to-json m)
                    

converts a message to a JSON object with role and content keys. Includes tool_calls for assistant tool call messages, and tool_call_id for tool result messages.

tool-call-id

instantiate

(Fn [(Ref Message a)] (Ref String a))

gets the tool-call-id property of a Message.

tool-calls

instantiate

(Fn [(Ref Message a)] (Ref (Array ToolCall) a))

gets the tool-calls property of a Message.

tool-result

defn

(Fn [(Ref String a), (Ref String b)] Message)

                        (tool-result call-id content)
                    

creates a tool result message for the given tool call ID.

update-content

instantiate

(Fn [Message, (Ref (Fn [String] String a) b)] Message)

updates the content property of a Message using a function f.

update-role

instantiate

(Fn [Message, (Ref (Fn [Role] Role a) b)] Message)

updates the role property of a Message using a function f.

update-tool-call-id

instantiate

(Fn [Message, (Ref (Fn [String] String a) b)] Message)

updates the tool-call-id property of a Message using a function f.

update-tool-calls

instantiate

(Fn [Message, (Ref (Fn [(Array ToolCall)] (Array ToolCall) a) b)] Message)

updates the tool-calls property of a Message using a function f.

user

defn

(Fn [(Ref String a)] Message)

                        (user s)
                    

creates a user message.