Skip to main content

NodeOutput

Struct NodeOutput 

Source
pub struct NodeOutput {
    pub updates: HashMap<String, Value>,
    pub interrupt: Option<Interrupt>,
    pub events: Vec<StreamEvent>,
    pub goto: Option<Vec<String>>,
    pub goto_parent: Option<Vec<String>>,
}
Expand description

Output from a node execution

Fields§

§updates: HashMap<String, Value>

State updates to apply

§interrupt: Option<Interrupt>

Optional interrupt request

§events: Vec<StreamEvent>

Custom stream events

§goto: Option<Vec<String>>

Nodes to run next, replacing this node’s declared outgoing edges.

§goto_parent: Option<Vec<String>>

Nodes of the parent graph to run next, when this graph is a subgraph.

A node deep in a nested graph can end its own graph and hand control to a node of the graph that holds it.

Implementations§

Source§

impl NodeOutput

Source

pub fn new() -> Self

Create a new empty output

Source

pub fn with_goto_parent<I, S>(self, targets: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Names the nodes to run next, replacing this node’s declared edges.

A conditional edge fixes its targets when the graph is built. This does not: a node reads state and names any node in the graph, including one it has no edge to. Naming END stops the branch.

The declared edges from this node do not also fire. Setting no goto leaves the declared edges in charge, which is the default.

§Example
use adk_graph::node::NodeOutput;
use serde_json::json;

// Write state and choose the next node in one step.
let output = NodeOutput::new()
    .with_update("risk", json!("high"))
    .with_goto(["escalate"]);
assert_eq!(output.goto.as_deref(), Some(&["escalate".to_string()][..]));

Names nodes of the parent graph to run next.

Only meaningful inside a SubgraphNode. The subgraph finishes, its output channels are projected out as usual, and the parent continues at the named nodes rather than following the subgraph node’s own edges. This is the counterpart to LangGraph’s Command(goto=..., graph=Command.PARENT).

A name the parent does not hold fails the run with GraphError::UnknownRouteTarget, checked by the parent, which is the only side that knows its own nodes.

§Example
use adk_graph::node::NodeOutput;
use serde_json::json;

// Inside a subgraph: give up, and let the parent's escalation path run.
let output = NodeOutput::new()
    .with_update("reason", json!("no confident answer"))
    .with_goto_parent(["escalate"]);
assert_eq!(output.goto_parent.as_deref(), Some(&["escalate".to_string()][..]));
Source

pub fn with_goto<I, S>(self, targets: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Source

pub fn with_update(self, key: &str, value: impl Into<Value>) -> Self

Add a state update

Source

pub fn with_updates(self, updates: HashMap<String, Value>) -> Self

Add multiple state updates

Source

pub fn with_interrupt(self, interrupt: Interrupt) -> Self

Set an interrupt

Source

pub fn with_event(self, event: StreamEvent) -> Self

Add a custom stream event

Source

pub fn interrupt(message: &str) -> Self

Create output that triggers a dynamic interrupt

Source

pub fn interrupt_with_data(message: &str, data: Value) -> Self

Create output that triggers a dynamic interrupt with data

Trait Implementations§

Source§

impl Default for NodeOutput

Source§

fn default() -> NodeOutput

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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