Jido.Thread.Agent
(Jido v2.0.0-rc.4)
View Source
Helper for managing Thread in agent state.
Thread is stored at the reserved key :__thread__ in agent.state.
This follows the same pattern as :__strategy__ for strategy state.
Example
alias Jido.Thread.Agent, as: ThreadAgent
# Ensure agent has a thread
agent = ThreadAgent.ensure(agent, metadata: %{user_id: "u1"})
# Append an entry
agent = ThreadAgent.append(agent, %{kind: :message, payload: %{text: "hi"}})
# Get the thread
thread = ThreadAgent.get(agent)
Summary
Functions
Append entry to agent's thread (ensures thread exists)
Ensure agent has a thread (initialize if missing)
Get thread from agent state
Check if agent has a thread
Returns the reserved key for thread storage
Put thread into agent state
Update thread using a function
Functions
@spec append(Jido.Agent.t(), term(), keyword()) :: Jido.Agent.t()
Append entry to agent's thread (ensures thread exists)
@spec ensure( Jido.Agent.t(), keyword() ) :: Jido.Agent.t()
Ensure agent has a thread (initialize if missing)
@spec get(Jido.Agent.t(), Jido.Thread.t() | nil) :: Jido.Thread.t() | nil
Get thread from agent state
@spec has_thread?(Jido.Agent.t()) :: boolean()
Check if agent has a thread
@spec key() :: atom()
Returns the reserved key for thread storage
@spec put(Jido.Agent.t(), Jido.Thread.t()) :: Jido.Agent.t()
Put thread into agent state
@spec update(Jido.Agent.t(), (Jido.Thread.t() | nil -> Jido.Thread.t())) :: Jido.Agent.t()
Update thread using a function