LangEx.Message (LangEx v0.11.3)

Copy Markdown View Source

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

Functions

add_messages(existing, new)

@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 :id values match (corrections/updates)
  • a RemoveMessage with a matching :id deletes that message
  • the remove_all/0 sentinel 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.

ai(content, opts \\ [])

@spec ai(
  String.t(),
  keyword()
) :: LangEx.Message.AI.t()

Create an AI message.

human(content, opts \\ [])

@spec human(
  String.t(),
  keyword()
) :: LangEx.Message.Human.t()

Create a human message.

remove(id)

Create a RemoveMessage targeting a single message by its :id.

remove_all()

@spec remove_all() :: LangEx.Message.RemoveMessage.t()

Create a RemoveMessage that clears the entire prior history.

system(content, opts \\ [])

@spec system(
  String.t(),
  keyword()
) :: LangEx.Message.System.t()

Create a system message.

tool(content, tool_call_id, opts \\ [])

@spec tool(String.t(), String.t(), keyword()) :: LangEx.Message.Tool.t()

Create a tool result message.