NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
node.h
Go to the documentation of this file.
1
36#pragma once
37
38#include <neograph/api.h>
41
42#include <asio/awaitable.hpp>
43
44#include <stdexcept>
45
46namespace neograph::graph {
47
53struct RunContext;
54
72struct NodeInput {
75
81
88};
89
97
105#define NEOGRAPH_DEPRECATED_VIRTUAL \
106 [[deprecated( \
107 "v0.4: override run(NodeInput) -> awaitable<NodeOutput> " \
108 "instead. The legacy 8-virtual chain is preserved for " \
109 "back-compat through v0.5 and removed in v1.0. " \
110 "Migration recipe: docs/migration-v0.4-to-v1.0.md")]]
111
132class NEOGRAPH_API GraphNode {
133public:
134 virtual ~GraphNode() = default;
135
184 virtual asio::awaitable<NodeOutput> run(NodeInput in) = 0;
185
190 virtual std::string get_name() const = 0;
191};
192
200class NEOGRAPH_API LLMCallNode : public GraphNode {
201public:
207 LLMCallNode(const std::string& name, const NodeContext& ctx);
208
216 asio::awaitable<NodeOutput> run(NodeInput in) override;
217
218 std::string get_name() const override { return name_; }
219
220private:
221 std::string name_;
222 std::shared_ptr<Provider> provider_;
223 std::vector<Tool*> tools_;
224 std::string model_;
225 std::string instructions_;
226
227 CompletionParams build_params(const GraphState& state) const;
228};
229
243class NEOGRAPH_API ToolDispatchNode : public GraphNode {
244public:
250 ToolDispatchNode(const std::string& name, const NodeContext& ctx);
251
256 asio::awaitable<NodeOutput> run(NodeInput in) override;
257 std::string get_name() const override { return name_; }
258
259private:
260 std::string name_;
261 std::vector<Tool*> tools_;
262};
263
264// Forward declaration
265class GraphEngine;
266
274class NEOGRAPH_API IntentClassifierNode : public GraphNode {
275public:
283 IntentClassifierNode(const std::string& name, const NodeContext& ctx,
284 const std::string& prompt,
285 std::vector<std::string> valid_routes);
286
291 asio::awaitable<NodeOutput> run(NodeInput in) override;
292 std::string get_name() const override { return name_; }
293
294private:
295 std::string name_;
296 std::shared_ptr<Provider> provider_;
297 std::string model_;
298 std::string prompt_;
299 std::vector<std::string> valid_routes_;
300
303 CompletionParams build_params(const GraphState& state) const;
304 std::vector<ChannelWrite> route_from(const std::string& intent) const;
305};
306
320class NEOGRAPH_API SubgraphNode : public GraphNode {
321public:
329 SubgraphNode(const std::string& name,
330 std::shared_ptr<GraphEngine> subgraph,
331 std::map<std::string, std::string> input_map = {},
332 std::map<std::string, std::string> output_map = {});
333
340 asio::awaitable<NodeOutput> run(NodeInput in) override;
341 std::string get_name() const override { return name_; }
342
343private:
344 std::string name_;
345 std::shared_ptr<GraphEngine> subgraph_;
346 std::map<std::string, std::string> input_map_;
347 std::map<std::string, std::string> output_map_;
348
349 json build_subgraph_input(const GraphState& state) const;
350 std::vector<ChannelWrite> extract_output(const json& subgraph_output) const;
351};
352
353} // namespace neograph::graph
NEOGRAPH_API export/import macro for shared-library builds.
Abstract base class for all graph nodes.
Definition node.h:132
virtual std::string get_name() const =0
Get the node's unique name within the graph.
virtual asio::awaitable< NodeOutput > run(NodeInput in)=0
v0.4 unified dispatch entry — replaces the 8-virtual cross product over (sync/async) × (writes/full) ...
Thread-safe container for all graph state channels.
Definition state.h:26
Node that classifies user intent via LLM and routes execution.
Definition node.h:274
std::string get_name() const override
Get the node's unique name within the graph.
Definition node.h:292
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.
Node that makes LLM completion calls.
Definition node.h:200
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:218
asio::awaitable< NodeOutput > run(NodeInput in) override
v0.4 PR 9a: unified run override.
Node that runs a compiled GraphEngine as a single node (hierarchical composition).
Definition node.h:320
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={})
Construct a subgraph node.
std::string get_name() const override
Get the node's unique name within the graph.
Definition node.h:341
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....
Node that dispatches and executes pending tool calls.
Definition node.h:243
asio::awaitable< NodeOutput > run(NodeInput in) override
v0.4 PR 9a: unified run — finds the latest assistant message with tool_calls, dispatches each call to...
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:257
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:287
Thread-safe mutable graph state management.
Parameters for an LLM completion request.
Definition provider.h:57
Dependency injection context passed to nodes during construction.
Definition types.h:251
Per-call input bundle for the v0.4 unified run() virtual.
Definition node.h:72
const GraphState & state
Snapshot of the channel state visible to this node.
Definition node.h:74
const RunContext & ctx
Per-run metadata threaded by the engine — cancel token, deadline, trace_id, thread_id,...
Definition node.h:80
const GraphStreamCallback * stream_cb
Streaming sink.
Definition node.h:87
Extended result returned by node execution.
Definition types.h:297
Per-run dispatch metadata threaded through the engine and executor.
Definition engine.h:118