NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
node.h
Go to the documentation of this file.
1
29#pragma once
30
31#include <neograph/api.h>
35#include <neograph/runtime_interposition_consumer.h>
36
37#include <asio/awaitable.hpp>
38
39#include <stdexcept>
40#include <mutex>
41#include <set>
42#include <string_view>
43
44namespace neograph { class RuntimeInterpositionController; }
45namespace neograph::graph {
46
56struct NodeInput {
59
64
71};
72
76
96class NEOGRAPH_API GraphNode {
97public:
98 virtual ~GraphNode() = default;
99
140 virtual asio::awaitable<NodeOutput> run(NodeInput in) = 0;
141
146 virtual std::string get_name() const = 0;
147};
148
176class NEOGRAPH_API SyncGraphNode : public GraphNode {
177public:
178 explicit SyncGraphNode(std::string name);
179 ~SyncGraphNode() override;
180
181 asio::awaitable<NodeOutput> run(NodeInput in) final;
182 std::string get_name() const final;
183
184protected:
185 virtual NodeOutput run_sync(NodeInput in) = 0;
186
187private:
188 std::string name_;
189};
190
198class NEOGRAPH_API LLMCallNode : public GraphNode, public ::neograph::RuntimeInterpositionConsumer {
199public:
205 LLMCallNode(const std::string& name, const NodeContext& ctx);
206
209 asio::awaitable<NodeOutput> run(NodeInput in) override;
210
211 std::string get_name() const override { return name_; }
212
214 bool has_provider() const noexcept { return provider_ != nullptr; }
215
216private:
217 std::string name_;
218 std::shared_ptr<Provider> provider_;
219 ToolSet tools_owner_;
220 std::vector<Tool*> tools_;
221 std::string model_;
222 std::string instructions_;
223 ProviderControls controls_;
224
225 ProviderRequest build_params(const GraphState& state) const;
226};
227
238class NEOGRAPH_API ToolDispatchNode : public GraphNode {
239public:
245 ToolDispatchNode(const std::string& name, const NodeContext& ctx);
246
251 asio::awaitable<NodeOutput> run(NodeInput in) override;
252 std::string get_name() const override { return name_; }
253
254private:
255 std::string name_;
256 ToolSet tools_owner_;
257 std::vector<Tool*> tools_;
258};
259
260// Forward declaration
261class GraphEngine;
262
271public:
281 IntentClassifierNode(const std::string& name, const NodeContext& ctx,
282 const std::string& prompt,
283 std::vector<std::string> valid_routes);
284
289 asio::awaitable<NodeOutput> run(NodeInput in) override;
290 std::string get_name() const override { return name_; }
291
293 bool has_provider() const noexcept { return provider_ != nullptr; }
294
295private:
296 std::string name_;
297 std::shared_ptr<Provider> provider_;
298 std::string model_;
299 std::string prompt_;
300 std::vector<std::string> valid_routes_;
301 ProviderControls controls_;
302
303 ProviderRequest build_params(const GraphState& state) const;
304 std::vector<ChannelWrite> route_from(const std::string& intent) const;
305};
306
309 Legacy,
311 PerThread,
312 Stateless
313};
314
343class NEOGRAPH_API SubgraphNode : public GraphNode {
344public:
353 SubgraphNode(const std::string& name,
354 std::shared_ptr<GraphEngine> subgraph,
355 std::map<std::string, std::string> input_map = {},
356 std::map<std::string, std::string> output_map = {},
357 SubgraphPersistence persistence = SubgraphPersistence::Legacy);
358
359 SubgraphPersistence persistence() const noexcept { return persistence_; }
360 const GraphEngine& child_engine() const noexcept { return *subgraph_; }
364 const std::string& parent_thread_id, int parent_step,
365 std::string_view task_id,
366 std::string_view graph_invocation_id = {}) const;
367
374 asio::awaitable<NodeOutput> run(NodeInput in) override;
375 std::string get_name() const override { return name_; }
376
377private:
378 std::string name_;
379 std::shared_ptr<GraphEngine> subgraph_;
380 std::map<std::string, std::string> input_map_;
381 std::map<std::string, std::string> output_map_;
382 SubgraphPersistence persistence_;
383 std::mutex active_mutex_;
384 std::set<std::string> active_per_thread_;
385
386 json build_subgraph_input(const GraphState& state) const;
387 std::vector<ChannelWrite> map_output_writes(
388 const std::vector<ChannelWrite>& child_writes) const;
389};
390
391} // namespace neograph::graph
NEOGRAPH_API export/import macro for shared-library builds.
Additive opt-in for built-in provider-calling runtime components.
Copyable owner of a fixed collection of tools.
Definition tool_set.h:21
Abstract base class for all graph nodes.
Definition node.h:96
virtual std::string get_name() const =0
Get the node's unique name within the graph.
virtual asio::awaitable< NodeOutput > run(NodeInput in)=0
Unified dispatch entry for sync work, async work, and streaming.
Thread-safe container for all graph state channels.
Definition state.h:55
Node that classifies user intent via LLM and routes execution.
Definition node.h:270
std::string get_name() const override
Get the node's unique name within the graph.
Definition node.h:290
asio::awaitable< NodeOutput > run(NodeInput in) override
v0.4 PR 9a: unified run — calls the LLM with the classification prompt, parses the result against val...
IntentClassifierNode(const std::string &name, const NodeContext &ctx, const std::string &prompt, std::vector< std::string > valid_routes)
Construct an intent classifier node.
bool has_provider() const noexcept
False when built from a NodeContext without a provider; run() then fails.
Definition node.h:293
Node that makes LLM completion calls.
Definition node.h:198
LLMCallNode(const std::string &name, const NodeContext &ctx)
Construct an LLM call node.
std::string get_name() const override
Get the node's unique name within the graph.
Definition node.h:211
bool has_provider() const noexcept
False when built from a NodeContext without a provider; run() then fails.
Definition node.h:214
asio::awaitable< NodeOutput > run(NodeInput in) override
Dispatch the owned typed request and retain every ordered returned message.
Node that runs a compiled GraphEngine as a single node (hierarchical composition).
Definition node.h:343
SubgraphNode(const std::string &name, std::shared_ptr< GraphEngine > subgraph, std::map< std::string, std::string > input_map={}, std::map< std::string, std::string > output_map={}, SubgraphPersistence persistence=SubgraphPersistence::Legacy)
Construct a subgraph node.
std::string get_name() const override
Get the node's unique name within the graph.
Definition node.h:375
asio::awaitable< NodeOutput > run(NodeInput in) override
v0.4 PR 9a: unified run — drives the child engine via run_async (or run_stream_async when in....
std::string checkpoint_thread_id(const std::string &parent_thread_id, int parent_step, std::string_view task_id, std::string_view graph_invocation_id={}) const
Reconstruct an inspection namespace from its parent path and invocation.
Adapter for CPU-light synchronous custom nodes.
Definition node.h:176
asio::awaitable< NodeOutput > run(NodeInput in) final
Unified dispatch entry for sync work, async work, and streaming.
std::string get_name() const final
Get the node's unique name within the graph.
Node that dispatches and executes pending tool calls.
Definition node.h:238
asio::awaitable< NodeOutput > run(NodeInput in) override
Unified run — finds the latest assistant message with tool_calls, dispatches each call to the matchin...
ToolDispatchNode(const std::string &name, const NodeContext &ctx)
Construct a tool dispatch node.
std::string get_name() const override
Get the node's unique name within the graph.
Definition node.h:252
Graph engine type definitions: channels, edges, nodes, events, and control flow.
std::function< void(const GraphEvent &)> GraphStreamCallback
Callback for receiving graph execution events.
Definition types.h:881
SubgraphPersistence
A subgraph's checkpoint lifetime. Legacy preserves the pre-#238 wire identity.
Definition node.h:308
@ Legacy
Existing parent-thread/step/task namespace (compatibility default).
@ Stateless
No child checkpoint or child interrupt/resume.
@ PerThread
Retain channel state across parent runs on the same thread.
@ PerInvocation
Fresh namespace for each parent run; durable across its resume.
Per-run metadata exposed to graph nodes.
Thread-safe mutable graph state management.
Typed per-call controls translated into the selected SDK provider family.
Definition provider.h:118
Portable request controls remain the SDK's declared, family-specific fields.
Definition provider.h:190
Dependency injection context passed to nodes during construction.
Definition types.h:753
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
const RunContext & ctx
Per-run metadata threaded by the engine — cancel token, usage, thread_id, current super-step,...
Definition node.h:63
const GraphStreamCallback * stream_cb
Streaming sink.
Definition node.h:70
Extended result returned by node execution.
Definition types.h:902
Per-run dispatch metadata threaded through the engine and executor.
Definition run_context.h:71