defmodule <%= module %> do @moduledoc """ Implements `Sagents.AgentPersistence` for state snapshots. Persists full agent state (messages, todos, metadata) to the database via `<%= conversations_module %>.save_agent_state/2`. """ @behaviour Sagents.AgentPersistence require Logger @impl true def persist_state(agent_id, state_data, context) do conversation_id = extract_conversation_id(agent_id) case <%= conversations_module %>.save_agent_state(conversation_id, state_data) do {:ok, _} -> Logger.debug("Persisted agent state for #{agent_id} (#{context})") :ok {:error, reason} -> {:error, reason} end end @impl true def load_state(agent_id) do conversation_id = extract_conversation_id(agent_id) <%= conversations_module %>.load_agent_state(conversation_id) end defp extract_conversation_id(agent_id) do String.replace_prefix(agent_id, "conversation-", "") end end