Chat message types for LLM interactions.
Provides struct-based message types and a reducer for accumulating messages in graph state.
Summary
Functions
Reducer that folds a list of instructions onto the existing history.
Create an AI message.
Create a human message.
Create a RemoveMessage targeting a single message by its :id.
Create a RemoveMessage that clears the entire prior history.
Create a system message.
Create a tool result message.
Types
@type instruction() :: t() | LangEx.Message.RemoveMessage.t()
@type t() :: LangEx.Message.Human.t() | LangEx.Message.AI.t() | LangEx.Message.System.t() | LangEx.Message.Tool.t()
Functions
@spec add_messages([t()], [instruction()] | instruction()) :: [t()]
Reducer that folds a list of instructions onto the existing history.
Instructions are applied left to right:
- a plain message is appended, or replaces an existing one when their
:idvalues match (corrections/updates) - a
RemoveMessagewith a matching:iddeletes that message - the
remove_all/0sentinel clears everything accumulated so far, so a node can replace the whole history in a single update
Order matters: [remove_all(), summary] clears the history and keeps
summary, while [summary, remove_all()] would discard summary too.
@spec ai( String.t(), keyword() ) :: LangEx.Message.AI.t()
Create an AI message.
@spec human( String.t(), keyword() ) :: LangEx.Message.Human.t()
Create a human message.
@spec remove(String.t()) :: LangEx.Message.RemoveMessage.t()
Create a RemoveMessage targeting a single message by its :id.
@spec remove_all() :: LangEx.Message.RemoveMessage.t()
Create a RemoveMessage that clears the entire prior history.
@spec system( String.t(), keyword() ) :: LangEx.Message.System.t()
Create a system message.
@spec tool(String.t(), String.t(), keyword()) :: LangEx.Message.Tool.t()
Create a tool result message.