adk_graph (erlang_adk v0.9.0)

View Source

Fluent compatibility builder for the canonical workflow graph.

The original adk_graph API returns {ok, State} and accepts atom node names. Compilation now lowers that representation into a canonical adk_workflow graph while preserving those public result forms. run/3 keeps the old term-friendly executor by default and accepts runtime => workflow as an explicit JSON-safe migration boundary. New applications which need typed nodes, fork/join, pause or durable invocation should build a kind => graph workflow specification directly; the inspection functions work for either compiled form.

Summary

Functions

Add or replace a state-dependent edge.

Add or replace a deterministic edge.

Add or replace a computation node.

Compile into a compatibility handle backed by adk_workflow.

Return a deterministic JSON-safe descriptor without callbacks or args.

Initialize a new, empty graph.

Execute with the legacy result form and term-compatible default.

Execute with a positive max_steps bound. Set runtime => workflow to use the supervised JSON-safe workflow engine.

Set the starting node.

Render the graph as deterministic Graphviz DOT.

Render the graph as deterministic Mermaid flowchart source.

Return the canonical compiled workflow behind a compatibility 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(),
                          workflow :: map()}.

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()) -> term()).

node_name/0

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

Functions

add_conditional_edge(Graph, From, ConditionFn)

-spec add_conditional_edge(graph(), node_name(), edge_condition()) -> graph().

Add or replace a state-dependent edge.

add_edge(Graph, From, To)

-spec add_edge(graph(), node_name(), node_name() | end_node) -> graph().

Add or replace a deterministic edge.

add_node(Graph, Name, NodeFn)

-spec add_node(graph(), node_name(), node_fn()) -> graph().

Add or replace a computation node.

compile(Graph)

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

Compile into a compatibility handle backed by adk_workflow.

describe(Value)

-spec describe(graph() | compiled_graph() | map()) -> {ok, map()} | {error, term()}.

Return a deterministic JSON-safe descriptor without callbacks or args.

new()

-spec new() -> graph().

Initialize a new, empty graph.

run(CompiledGraph, InitialState)

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

Execute with the legacy result form and term-compatible default.

run(Compiled_graph, InitialState, Opts)

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

Execute with a positive max_steps bound. Set runtime => workflow to use the supervised JSON-safe workflow engine.

set_entry_point(Graph, Entry)

-spec set_entry_point(graph(), node_name()) -> graph().

Set the starting node.

to_dot(Value)

-spec to_dot(graph() | compiled_graph() | map()) -> {ok, binary()} | {error, term()}.

Render the graph as deterministic Graphviz DOT.

to_mermaid(Value)

-spec to_mermaid(graph() | compiled_graph() | map()) -> {ok, binary()} | {error, term()}.

Render the graph as deterministic Mermaid flowchart source.

to_workflow(Compiled_graph)

-spec to_workflow(graph() | compiled_graph() | map()) -> {ok, map()} | {error, term()}.

Return the canonical compiled workflow behind a compatibility graph.