GraphBuilder

org.llm4s.agent.graph.GraphBuilder
See theGraphBuilder companion object
final class GraphBuilder

Builds a typed graph. The builder issues every handle - nodes, joins - and validates the whole graph in compile, reporting every problem at once.

Nodes that route to each other in a cycle are declared first and implemented afterwards:

val b      = GraphBuilder("counter", "v1")
val count  = StateKey.replace[Int]("count", 0)
val tick   = b.declare[Unit]("tick")
b.implement(tick, writes = Set(count)) { (_, state, _) =>
 NodeResult.fromResult(state.get(count).map { n =>
   val next = Command.empty.update(count, n + 1)
   if n + 1 < 3 then next.goto(tick) else next
 })
}
val graph = b.compile(tick)(_.get(count))

The builder is mutable and meant to be used from one thread while the graph is assembled; the CompiledGraph it produces is immutable.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def compile[I, O](entry: NodeRef[I], maxSupersteps: Int)(output: ThreadState => Result[O]): Result[CompiledGraph[I, O]]

Validates the graph and compiles it. output projects the final committed state when the run goes quiescent.

Validates the graph and compiles it. output projects the final committed state when the run goes quiescent.

Attributes

def declare[I](nodeId: String, inputVersion: SchemaVersion)(using codec: ReadWriter[I]): NodeRef[I]

Issues a handle for a node consuming I; implement it before compiling. inputVersion is the version of I's JSON shape in checkpoints, with migrations from earlier versions.

Issues a handle for a node consuming I; implement it before compiling. inputVersion is the version of I's JSON shape in checkpoints, with migrations from earlier versions.

Attributes

def dynamicJoin(joinId: String, target: NodeRef[Unit]): DynamicJoin

A barrier released when every child of a fan-out has completed; see DynamicJoin.

A barrier released when every child of a fan-out has completed; see DynamicJoin.

Attributes

def edge(from: NodeRef[_], to: NodeRef[Unit]): Unit

A static edge: every completed task of from also schedules to, before the routes in its command. Edges from one node are scheduled in declaration order.

A static edge: every completed task of from also schedules to, before the routes in its command. Edges from one node are scheduled in declaration order.

Attributes

def implement[I](ref: NodeRef[I], writes: Set[StateKey[_, _]])(node: GraphNode[I]): Unit

Gives a declared node its behaviour and the state keys it may update or remove.

Gives a declared node its behaviour and the state keys it may update or remove.

Attributes

def node[I](nodeId: String, writes: Set[StateKey[_, _]], inputVersion: SchemaVersion)(node: GraphNode[I])(using codec: ReadWriter[I]): NodeRef[I]

Declares and implements a node in one step.

Declares and implements a node in one step.

Attributes

def stateKey(key: StateKey[_, _]): Unit

Registers a key that nodes read but none writes, such as one seeded by a restored snapshot.

Registers a key that nodes read but none writes, such as one seeded by a restored snapshot.

Attributes

def staticJoin(joinId: String, sources: Set[NodeRef[_]], target: NodeRef[Unit]): StaticJoin

A barrier that runs target after every node in sources has completed; see StaticJoin.

A barrier that runs target after every node in sources has completed; see StaticJoin.

Attributes

Concrete fields

val id: String
val version: String