pub struct Graph { /* private fields */ }Expand description
Builds a pipeline of agents and tool fns that run one after another. Each node reads the output of the node before it, the first reads the input; the last node’s output is the answer. Fan-out, routers and human nodes stay in workflow TOML.
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Starts a graph builder called name, 1 to 64 of [a-z0-9-].
build checks the name with the workflow rules.
Every setting starts at its documented default.
Sourcepub fn agent(self, id: impl Into<String>, agent: Agent) -> Self
pub fn agent(self, id: impl Into<String>, agent: Agent) -> Self
Adds agent node id running agent on the previous node’s output.
The agent keeps its own model binding; its tools and evals join the
graph, and its storage, retries and events are the graph’s. An agent
with its own limits, laws or ledger fails build: set them on the
graph, so no spend cap or counter is dropped.
Sourcepub fn step(self, id: impl Into<String>, step: impl AsTool) -> Self
pub fn step(self, id: impl Into<String>, step: impl AsTool) -> Self
Adds fn node id calling step, a #[tool] fn or tool(..).
Its argument names must equal the ids of the nodes that feed it
(input for the first node); build checks this.
Sourcepub fn edge(self, from: impl Into<String>, to: impl Into<String>) -> Self
pub fn edge(self, from: impl Into<String>, to: impl Into<String>) -> Self
Adds an edge from node from to node to.
Edges must form one chain; with no edges the nodes run in the
order they were added.
Sourcepub fn checkpoints(self, storage: Storage) -> Self
pub fn checkpoints(self, storage: Storage) -> Self
Sets where graph checkpoints live.
Defaults to Storage::memory(), fresh per run.
Returns the builder.
Sourcepub fn limits(self, limits: Limits) -> Self
pub fn limits(self, limits: Limits) -> Self
Sets the spend limits for the whole graph run.
Defaults to Limits::default(), no limit.
Returns the builder.
Sourcepub fn ledger(self, ledger: Arc<dyn UsageLedger>) -> Self
pub fn ledger(self, ledger: Arc<dyn UsageLedger>) -> Self
Sets the usage ledger that period limits (scope, user) and the
agent nodes’ route daily cloud spend count in. Defaults to a fresh
in-memory ledger per build; pass a durable one so caps survive
rebuilds and restarts.
Sourcepub fn max_steps(self, steps: u32) -> Self
pub fn max_steps(self, steps: u32) -> Self
Caps graph steps per run; 1 to 10000, checked at build.
Defaults to the workflow default.
Returns the builder.
Sourcepub fn retries(self, retries: u32) -> Self
pub fn retries(self, retries: u32) -> Self
Sets how often a transient failure is retried per run.
At most 50, checked at build; defaults to 3.
Returns the builder.
Sourcepub fn laws(self, path: impl AsRef<Path>) -> Self
pub fn laws(self, path: impl AsRef<Path>) -> Self
Adds a .bend law file, checked at build.
0.2 stores laws; no run proves them yet.
Returns the builder.
Sourcepub fn law(self, law: impl Into<String>) -> Self
pub fn law(self, law: impl Into<String>) -> Self
Adds one inline law, checked at build.
0.2 stores laws; no run proves them yet.
Returns the builder.
Sourcepub fn auto_laws(self, on: bool) -> Self
pub fn auto_laws(self, on: bool) -> Self
Asks for laws derived from the code as well. Defaults to true.
0.2 records the choice only.
Returns the builder.
Sourcepub async fn build(self) -> Result<BuiltGraph, KitError>
pub async fn build(self) -> Result<BuiltGraph, KitError>
Checks the nodes, edges, workflow, every agent and tool, and the storage, then returns a ready graph. Makes no model call. Fails with the first problem found.
Source§impl Graph
impl Graph
Sourcepub fn tracing(self, on: bool) -> Self
pub fn tracing(self, on: bool) -> Self
Turns tracing on with every category, or off. Default off.
Covers build, every run and every agent node; spans go to
trace_to, trace_file or ./traces/<name>-<trace id>.jsonl.
Sourcepub fn trace(self, categories: impl IntoIterator<Item = Trace>) -> Self
pub fn trace(self, categories: impl IntoIterator<Item = Trace>) -> Self
Turns tracing on for the listed categories only. An empty list turns tracing off. Returns the builder.
Sourcepub fn trace_content(self, on: bool) -> Self
pub fn trace_content(self, on: bool) -> Self
Keeps prompt, reply, tool argument, query and document text in spans. Default off: spans then hold only byte counts. Secrets are scrubbed either way.
Sourcepub fn trace_to(self, sink: Arc<dyn TraceSink>) -> Self
pub fn trace_to(self, sink: Arc<dyn TraceSink>) -> Self
Sends trace records to sink instead of a file.
Takes effect only with tracing on; replaces trace_file.
Returns the builder.
Sourcepub fn trace_file(self, path: impl AsRef<Path>) -> Self
pub fn trace_file(self, path: impl AsRef<Path>) -> Self
Writes trace records to the new file path; an existing file is
refused at build. Takes effect only with tracing on; replaces
trace_to.