Skip to main content

Graph

Struct Graph 

Source
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

Source

pub fn events(self, sink: Arc<dyn EventSink>) -> Self

Sends every event of the graph and of its agent nodes to sink. Agent nodes run under their own run ids, so order by seq only within one run id. Defaults to a sink that drops events.

Source

pub async fn stream( self, input: impl Into<String>, ) -> Result<RunStream<GraphReport>, KitError>

Builds the graph and starts a streamed run on input. Output: the stream once the run id is known, or the first build or setup error. Keep a BuiltGraph to run many times.

Source§

impl Graph

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn checkpoints(self, storage: Storage) -> Self

Sets where graph checkpoints live. Defaults to Storage::memory(), fresh per run. Returns the builder.

Source

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.

Source

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. Default: limits count in memory per build; route spend goes to the Storage::sqlite file, else in memory per build.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

pub async fn run(self, input: impl Into<String>) -> Result<Value, KitError>

Builds the graph and runs it once on input. Returns the last node’s output. Fails like build, then like BuiltGraph::run.

Source

pub async fn run_with( self, input: impl Into<String>, ) -> Result<GraphReport, KitError>

Builds the graph and runs it once on input. Returns the full report. Fails like build, then like BuiltGraph::run_with.

Source§

impl Graph

Source

pub fn private(self, on: bool) -> Self

Makes every agent node private, as Agent::private(true) does. Default false. Routes, local models and tiers stay per agent, since a graph has no model of its own.

Source§

impl Graph

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Graph

§

impl !UnwindSafe for Graph

§

impl Forget for Graph

§

impl Freeze for Graph
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<(String, Node)>: Freeze, PhantomData<(String, String)>: Freeze, *const ArcInner<dyn CheckpointStore> is !null: Freeze, PhantomData<ArcInner<dyn CheckpointStore>>: Freeze, *const ArcInner<dyn UsageLedger> is !null: Freeze, PhantomData<ArcInner<dyn UsageLedger>>: Freeze, PhantomData<PathBuf>: Freeze, PhantomData<String>: Freeze, *const ArcInner<dyn EventSink> is !null: Freeze, PhantomData<ArcInner<dyn EventSink>>: Freeze, *const ArcInner<dyn TraceSink> is !null: Freeze, PhantomData<ArcInner<dyn TraceSink>>: Freeze,

§

impl Move for Graph

§

impl Send for Graph
where RawVecInner: Send, BoxRaw<Agent>: Send, Arc<dyn Tool>: Send, Arc<dyn CheckpointStore>: Send, Arc<dyn UsageLedger>: Send, Arc<dyn EventSink>: Send, Arc<dyn TraceSink>: Send,

§

impl Sync for Graph
where RawVecInner: Sync, BoxRaw<Agent>: Sync, Arc<dyn Tool>: Sync, Arc<dyn CheckpointStore>: Sync, Arc<dyn UsageLedger>: Sync, Arc<dyn EventSink>: Sync, Arc<dyn TraceSink>: Sync,

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more