adk_graph (erlang_adk v0.2.1)

View Source

adk_graph - Graph-based workflow engine for ADK 2.0.

This module allows constructing stateful execution graphs where nodes can be agents, functions, or sub-graphs, and edges define the conditional routing.

Summary

Functions

Add a conditional edge that decides the next node based on state.

Add a deterministic edge from one node to another.

Add a computation node to the graph.

Compile the graph, verifying it is well-formed.

Initialize a new, empty graph.

Execute the compiled graph with an initial state.

Set the entry point (starting node) of the graph.

Types

compiled_graph/0

-type compiled_graph() ::
          #compiled_graph{nodes :: #{node_name() => node_fn()},
                          edges :: #{node_name() => node_name() | edge_condition()},
                          entry_point :: node_name()}.

edge_condition/0

-type edge_condition() :: fun((map()) -> node_name() | end_node).

graph/0

-type graph() ::
          #graph{nodes :: #{node_name() => node_fn()},
                 edges :: #{node_name() => node_name() | edge_condition()},
                 entry_point :: node_name() | undefined}.

node_fn/0

-type node_fn() :: fun((map()) -> map()).

node_name/0

-type node_name() :: atom() | binary().

Functions

add_conditional_edge(Graph, From, ConditionFn)

-spec add_conditional_edge(Graph :: graph(), From :: node_name(), ConditionFn :: edge_condition()) ->
                              graph().

Add a conditional edge that decides the next node based on state.

add_edge(Graph, From, To)

-spec add_edge(Graph :: graph(), From :: node_name(), To :: node_name() | end_node) -> graph().

Add a deterministic edge from one node to another.

add_node(Graph, Name, NodeFn)

-spec add_node(Graph :: graph(), Name :: node_name(), NodeFn :: node_fn()) -> graph().

Add a computation node to the graph.

compile(Graph)

-spec compile(Graph :: graph()) -> {ok, compiled_graph()} | {error, term()}.

Compile the graph, verifying it is well-formed.

new()

-spec new() -> graph().

Initialize a new, empty graph.

run(CompiledGraph, InitialState)

-spec run(CompiledGraph :: compiled_graph(), InitialState :: map()) -> {ok, map()} | {error, term()}.

Execute the compiled graph with an initial state.

set_entry_point(Graph, Entry)

-spec set_entry_point(Graph :: graph(), Entry :: node_name()) -> graph().

Set the entry point (starting node) of the graph.