GenAI.Graph.NodeProtocol protocol (GenAI Core v0.2.0)
Protocol for managing Graph Nodes.
Link to this section Summary
Functions
build handle lookup table for graph root, including local handles that can override standard handles based on scope.
build Graph Root node lookup allowing nodes to link across descendents/siblings to far away elements.
Obtain the description of a graph node.
Obtain the description of a graph node, or return a default value if the description is nil.
Obtain the handle of a graph node.
Obtain the handle of a graph node, or return a default value if the handle is nil.
Return full handle record not just the handle name.
Obtain the id of a graph node.
Obtain inbound links of a graph node.
Obtain the name of a graph node.
Obtain the name of a graph node, or return a default value if the name is nil.
Obtain a node nested under current node,
Obtain the node type for a graph node.
Obtain direct children node of current node.
Obtain outbound links of a graph node.
Process graph to execute tasks or run inference.
Register a link with the graph node.
Ensure the graph node has an id, generating one if necessary.
Link to this section Types
@type t() :: term()
All the types that implement this protocol.
Link to this section Functions
build_handle_lookup(graph_node, options \\ nil)
build handle lookup table for graph root, including local handles that can override standard handles based on scope.
build_node_lookup(graph_node, options \\ nil)
build Graph Root node lookup allowing nodes to link across descendents/siblings to far away elements.
description(graph_node)
@spec description(graph_node :: GenAI.Types.Graph.graph_node()) :: GenAI.Types.result(GenAI.Types.description(), GenAI.Types.details())
Obtain the description of a graph node.
examples
Examples
when-set
When Set
iex> node = %GenAI.Graph.Node{description: "B"}
...> GenAI.Graph.NodeProtocol.description(node)
{:ok, "B"}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{description: nil}
...> GenAI.Graph.NodeProtocol.description(node)
{:error, {:description, :is_nil}}
description(graph_node, default)
@spec description( graph_node :: GenAI.Types.Graph.graph_node(), default :: GenAI.Types.description() ) :: GenAI.Types.result(GenAI.Types.description(), GenAI.Types.details())
Obtain the description of a graph node, or return a default value if the description is nil.
examples
Examples
when-set
When Set
iex> node = %GenAI.Graph.Node{description: "B"}
...> GenAI.Graph.NodeProtocol.description(node, "default")
{:ok, "B"}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{description: nil}
...> GenAI.Graph.NodeProtocol.description(node, "default")
{:ok, "default"}
handle(graph_node)
@spec handle(graph_node :: GenAI.Types.Graph.graph_node()) :: GenAI.Types.result(GenAI.Types.handle(), GenAI.Types.details())
Obtain the handle of a graph node.
examples
Examples
when-set
When Set
iex> node = %GenAI.Graph.Node{handle: :foo}
...> GenAI.Graph.NodeProtocol.handle(node)
{:ok, :foo}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{handle: nil}
...> GenAI.Graph.NodeProtocol.handle(node)
{:error, {:handle, :is_nil}}
handle(graph_node, default)
@spec handle( graph_node :: GenAI.Types.Graph.graph_node(), default :: GenAI.Types.handle() ) :: GenAI.Types.result(GenAI.Types.handle(), GenAI.Types.details())
Obtain the handle of a graph node, or return a default value if the handle is nil.
examples
Examples
when-set
When Set
iex> node = %GenAI.Graph.Node{handle: :foo}
...> GenAI.Graph.NodeProtocol.handle(node, :default)
{:ok, :foo}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{handle: nil}
...> GenAI.Graph.NodeProtocol.handle(node, :default)
{:ok, :default}
handle_record(graph_node)
Return full handle record not just the handle name.
id(graph_node)
@spec id(graph_node :: GenAI.Types.Graph.graph_node()) :: GenAI.Types.result(GenAI.Types.Graph.graph_node_id(), GenAI.Types.details())
Obtain the id of a graph node.
examples
Examples
when-set
When Set
iex> node = %GenAI.Graph.Node{id: UUID.uuid4()}
...> GenAI.Graph.NodeProtocol.id(node)
{:ok, node.id}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{id: nil}
...> GenAI.Graph.NodeProtocol.id(node)
{:error, {:id, :is_nil}}
inbound_links(graph_node, graph, options)
@spec inbound_links( graph_node :: GenAI.Types.Graph.graph_node(), graph :: GenAI.Types.Graph.graph(), options :: map() ) :: {:ok, [GenAI.Types.Graph.graph_link_id()]} | {:error, term()}
Obtain inbound links of a graph node.
name(graph_node)
@spec name(graph_node :: GenAI.Types.Graph.graph_node()) :: GenAI.Types.result(GenAI.Types.name(), GenAI.Types.details())
Obtain the name of a graph node.
examples
Examples
when-set
When Set
iex> node = %GenAI.Graph.Node{name: "A"}
...> GenAI.Graph.NodeProtocol.name(node)
{:ok, "A"}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{name: nil}
...> GenAI.Graph.NodeProtocol.name(node)
{:error, {:name, :is_nil}}
name(graph_node, default)
@spec name( graph_node :: GenAI.Types.Graph.graph_node(), default :: GenAI.Types.name() ) :: GenAI.Types.result(GenAI.Types.name(), GenAI.Types.details())
Obtain the name of a graph node, or return a default value if the name is nil.
examples
Examples
when-set
When Set
iex> node = %GenAI.Graph.Node{name: "A"}
...> GenAI.Graph.NodeProtocol.name(node, "default")
{:ok, "A"}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{name: nil}
...> GenAI.Graph.NodeProtocol.name(node, "default")
{:ok, "default"}
node(graph_node, id)
Obtain a node nested under current node,
node_type(graph_node)
@spec node_type(graph_node :: GenAI.Types.Graph.graph_node()) :: GenAI.Types.result(GenAI.Types.Graph.graph_node_id(), GenAI.Types.details())
Obtain the node type for a graph node.
example
Example
iex> node = %GenAI.Graph.Node{id: UUID.uuid4()}
...> GenAI.Graph.NodeProtocol.node_type(node)
{:ok, GenAI.Graph.Node}
nodes(graph_node, options \\ nil)
Obtain direct children node of current node.
outbound_links(graph_node, graph, options)
@spec outbound_links( graph_node :: GenAI.Types.Graph.graph_node(), graph :: GenAI.Types.Graph.graph(), options :: map() ) :: {:ok, [GenAI.Types.Graph.graph_link_id()]} | {:error, term()}
Obtain outbound links of a graph node.
process_node(graph_node, graph_link, graph_container, session, context, options)
Process graph to execute tasks or run inference.
register_link(graph_node, graph, link, options)
@spec register_link( graph_node :: GenAI.Types.Graph.graph_node(), graph :: GenAI.Types.Graph.graph(), link :: GenAI.Types.Graph.graph_link(), options :: map() ) :: GenAI.Types.result(GenAI.Types.Graph.graph_node(), GenAI.Types.details())
Register a link with the graph node.
examples
Examples
iex> n1 = UUID.uuid5(:oid, "node-1")
...> n2 = UUID.uuid5(:oid, "node-2")
...> n = %GenAI.Graph.Node{id: n1}
...> link = GenAI.Graph.Link.new(n1, n2)
...> link_id = link.id
...> {:ok, updated} = GenAI.Graph.NodeProtocol.register_link(n, %{}, link, nil)
...> updated
%GenAI.Graph.Node{outbound_links: %{default: [^link_id]}} = updated
with_id(graph_node)
@spec with_id(graph_node :: GenAI.Types.Graph.graph_node()) :: GenAI.Types.result(GenAI.Types.Graph.graph_node(), GenAI.Types.details())
Ensure the graph node has an id, generating one if necessary.
examples
Examples
when-already-set
When Already Set
iex> node = %GenAI.Graph.Node{id: UUID.uuid4()}
...> {:ok, node2} = GenAI.Graph.NodeProtocol.with_id(node)
...> %{was_nil: is_nil(node.id), is_nil: is_nil(node2.id), id_change: node.id != node2.id}
%{was_nil: false, is_nil: false, id_change: false}
when-not-set
When Not Set
iex> node = %GenAI.Graph.Node{id: nil}
...> {:ok, node2} = GenAI.Graph.NodeProtocol.with_id(node)
...> %{was_nil: is_nil(node.id), is_nil: is_nil(node2.id), id_change: node.id != node2.id}
%{was_nil: true, is_nil: false, id_change: true}