LangEx — LangGraph for Elixir.
A graph-based agent orchestration library inspired by LangGraph. Build stateful, multi-step LLM workflows using nodes, edges, conditional routing, and composable state reducers.
Quick Start
alias LangEx.Graph
alias LangEx.Message
graph =
Graph.new(messages: {[], &Message.add_messages/2})
|> Graph.add_node(:greet, fn state ->
name = hd(state.messages).content
%{messages: [Message.ai("Hello, #{name}!")]}
end)
|> Graph.add_edge(:__start__, :greet)
|> Graph.add_edge(:greet, :__end__)
|> Graph.compile()
{:ok, result} = LangEx.invoke(graph, %{messages: [Message.human("World")]})
Summary
Functions
Deletes every checkpoint for the thread in the config.
Returns the latest (or a specific) checkpoint for a thread.
Returns the checkpoint history for a thread, most recent first.
Executes a compiled graph with the given input state.
Returns a lazy stream of execution events from the compiled graph.
Applies an update to checkpointed state, saving a new forked checkpoint.
Functions
@spec delete_thread( LangEx.Graph.Compiled.t(), keyword() ) :: :ok | {:error, term()}
Deletes every checkpoint for the thread in the config.
@spec get_state( LangEx.Graph.Compiled.t(), keyword() ) :: {:ok, LangEx.Checkpoint.t()} | :none | {:error, term()}
Returns the latest (or a specific) checkpoint for a thread.
@spec get_state_history( LangEx.Graph.Compiled.t(), keyword() ) :: [LangEx.Checkpoint.t()]
Returns the checkpoint history for a thread, most recent first.
@spec invoke(LangEx.Graph.Compiled.t(), map() | LangEx.Command.t(), keyword()) :: {:ok, map()} | {:interrupt, term(), map()} | {:error, term()}
Executes a compiled graph with the given input state.
Returns a lazy stream of execution events from the compiled graph.
@spec update_state(LangEx.Graph.Compiled.t(), map(), keyword()) :: {:ok, LangEx.Checkpoint.t()} | {:error, term()}
Applies an update to checkpointed state, saving a new forked checkpoint.