Current section
Files
Jump to
Current section
Files
priv/templates/sagents.gen.persistence/agent_state.ex.eex
defmodule <%= @context_module %>.AgentState do
@moduledoc """
Schema for agent state persistence.
Stores the complete serialized state of an agent for a conversation.
This includes messages, todos, metadata, and agent configuration.
"""
use Ecto.Schema
import Ecto.Changeset
alias <%= @context_module %>.Conversation
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "<%= @table_prefix %>agent_states" do
belongs_to :conversation, Conversation
field :state_data, :map
field :version, :integer
timestamps(type: :utc_datetime_usec)
end
@doc false
def changeset(agent_state, attrs) do
agent_state
|> cast(attrs, [:conversation_id, :state_data, :version])
|> validate_required([:conversation_id, :state_data, :version])
|> foreign_key_constraint(:conversation_id)
|> unique_constraint(:conversation_id)
end
end