NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
neograph::graph::SyncGraphNode Class Referenceabstract

Adapter for CPU-light synchronous custom nodes. More...

#include <node.h>

Inheritance diagram for neograph::graph::SyncGraphNode:
[legend]
Collaboration diagram for neograph::graph::SyncGraphNode:
[legend]

Public Member Functions

std::string get_name () const final
 Get the node's unique name within the graph.
 
asio::awaitable< NodeOutput > run (NodeInput in) final
 Unified dispatch entry for sync work, async work, and streaming.
 

Detailed Description

Adapter for CPU-light synchronous custom nodes.

Subclasses implement only run_sync(NodeInput) -> NodeOutput; this adapter lifts that result into the one canonical GraphNode::run coroutine exactly once. NodeInput is forwarded unchanged, so state, RunContext, and the optional stream sink remain available. The returned NodeOutput preserves channel-write modes, Command, and Send values without reconstruction.

run_sync executes inline on the graph's current executor. It is intended for short computations and state transformations. Do not perform blocking network/file I/O, sleeps, or other waits here: those stall the graph loop. Derive directly from GraphNode and co_await an asynchronous dependency for such work.

class NormalizeNode : public SyncGraphNode {
public:
NormalizeNode() : SyncGraphNode("normalize") {}
protected:
NodeOutput run_sync(NodeInput in) override {
"text", normalize(in.state.get("text").get<std::string>())}}};
}
};
json get(const std::string &channel) const
Read a channel's current value (thread-safe, shared lock).
Adapter for CPU-light synchronous custom nodes.
Definition node.h:176
Output of a node: a write to a named channel.
Definition types.h:128
Per-call input bundle for the unified run() virtual.
Definition node.h:56
const GraphState & state
Snapshot of the channel state visible to this node.
Definition node.h:58
Extended result returned by node execution.
Definition types.h:902

Definition at line 176 of file node.h.

Member Function Documentation

◆ get_name()

std::string neograph::graph::SyncGraphNode::get_name ( ) const
finalvirtual

Get the node's unique name within the graph.

Returns
Node name string.

Implements neograph::graph::GraphNode.

◆ run()

asio::awaitable< NodeOutput > neograph::graph::SyncGraphNode::run ( NodeInput  in)
finalvirtual

Unified dispatch entry for sync work, async work, and streaming.

New nodes override THIS method. Read in.state for channel inputs, read in.ctx for available per-run metadata (cancel token, thread ID, current step, …), check in.stream_cb for an optional LLM_TOKEN sink, and return a NodeOutput (alias for NodeResult) populated with channel writes plus optional Command / Send directives.

The engine (NodeExecutor::execute_node_with_retry_async) dispatches only through this method. Sync-vs-async is no longer a public virtual cross-product: perform immediate work before co_return, or co_await asynchronous dependencies.

class MyNode : public GraphNode {
asio::awaitable<NodeOutput> run(NodeInput in) override {
auto request = make_provider_request(*provider_, model_, in.state.get_provider_messages());
auto outcome = co_await provider_->invoke_async(std::move(request));
record_usage(in.ctx, outcome);
outcome_or_throw(outcome);
out.writes.push_back(provider_messages_write(outcome));
co_return out;
}
std::string get_name() const override { return "my_node"; }
};
Abstract base class for all graph nodes.
Definition node.h:96
std::vector< sp::Message > get_provider_messages(const std::string &channel="messages") const
Full ordered provider history; JSON is only its portable projection.
void record_usage(const RunContext &ctx, const sp::runtime::Result &result)
Fold exactly the actual nullable report, never a reservation or charge.
const RunContext & ctx
Per-run metadata threaded by the engine — cancel token, usage, thread_id, current super-step,...
Definition node.h:63
std::vector< ChannelWrite > writes
Channel writes from this node.
Definition types.h:903
See also
NodeInput and NodeOutput above.

Lifetime note: in is taken by value so the coroutine frame owns its own copy of the struct. The state / ctx references inside still point to objects on the engine's suspended-frame stack (which outlive the run by construction), but the struct itself is no longer a reference parameter. The coroutine-reference-parameter UAF fixed in the v0.2.0 RunConfig path does not apply here.

Implements neograph::graph::GraphNode.


The documentation for this class was generated from the following file: