NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
loader.h
Go to the documentation of this file.
1
9#pragma once
10
11#include <neograph/api.h>
13#include <mutex>
14#include <unordered_map>
15#include <optional>
16#include <string>
17#include <vector>
18
19namespace neograph::graph {
20
21class GraphNode;
22
42class NEOGRAPH_API ReducerRegistry {
43public:
47
53 void register_reducer(const std::string& name, ReducerFn fn);
54
60 ReducerFn get(const std::string& name) const;
61
70 std::vector<std::string> names() const;
71
72private:
73 friend class GraphRegistry;
74 mutable std::mutex mutex_;
76 std::unordered_map<std::string, ReducerFn> registry_;
77};
78
105 std::vector<std::string> labels;
109 bool open = false;
110};
111
112class NEOGRAPH_API ConditionRegistry {
113public:
116 static ConditionRegistry& instance();
117
123 void register_condition(const std::string& name, ConditionFn fn);
124
130 void register_condition(const std::string& name, ConditionFn fn,
131 ConditionSpec spec);
132
138 ConditionFn get(const std::string& name) const;
139
145 std::optional<ConditionSpec> condition_spec(const std::string& name) const;
146
155 std::vector<std::string> names() const;
156
157private:
158 friend class GraphRegistry;
159 mutable std::mutex mutex_;
160 ConditionRegistry();
161 std::unordered_map<std::string, ConditionFn> registry_;
162 std::unordered_map<std::string, ConditionSpec> specs_;
163};
164
172using NodeFactoryFn = std::function<std::unique_ptr<GraphNode>(
173 const std::string& name,
174 const json& config,
175 const NodeContext& ctx)>;
176
191class NEOGRAPH_API NodeFactory {
192public:
196
209 void register_type(const std::string& type, NodeFactoryFn fn);
210
222 void register_type(const std::string& type, NodeFactoryFn fn,
223 json config_schema);
224
241 void register_type(const std::string& type, NodeFactoryFn fn,
242 json config_schema, json effects);
243
249 json node_effects(const std::string& type) const;
250
259 std::unique_ptr<GraphNode> create(const std::string& type,
260 const std::string& name,
261 const json& config,
262 const NodeContext& ctx) const;
263
268 std::vector<std::string> registered_types() const;
269
280 json config_schema(const std::string& type) const;
281
315 json export_schema() const;
316
317private:
318 friend class GraphRegistry;
319 mutable std::mutex mutex_;
320 NodeFactory();
321 std::unordered_map<std::string, NodeFactoryFn> registry_;
322 std::unordered_map<std::string, json> schemas_;
323 std::unordered_map<std::string, json> effects_;
324};
325
326} // namespace neograph::graph
NEOGRAPH_API export/import macro for shared-library builds.
Engine-owned registry of custom graph callables.
Definition registry.h:21
Singleton factory for creating graph nodes by type name.
Definition loader.h:191
json node_effects(const std::string &type) const
Declared channel effects for a node type.
void register_type(const std::string &type, NodeFactoryFn fn, json config_schema, json effects)
Register a custom node type with a declared config schema AND a declared channel-effect contract.
void register_type(const std::string &type, NodeFactoryFn fn, json config_schema)
Register a custom node type with a declared config schema.
json export_schema() const
Export a machine-readable description of the topology JSON format this engine accepts.
json config_schema(const std::string &type) const
Declared config schema for a node type.
void register_type(const std::string &type, NodeFactoryFn fn)
Register a custom node type.
std::unique_ptr< GraphNode > create(const std::string &type, const std::string &name, const json &config, const NodeContext &ctx) const
Create a node by type name.
std::vector< std::string > registered_types() const
List all registered node type names, sorted.
static NodeFactory & instance()
Get the singleton instance.
Singleton registry for channel reducer functions.
Definition loader.h:42
ReducerFn get(const std::string &name) const
Look up a reducer by name.
std::vector< std::string > names() const
List all registered reducer names, sorted.
void register_reducer(const std::string &name, ReducerFn fn)
Register a named reducer function.
static ReducerRegistry & instance()
Get the singleton instance.
Graph engine type definitions: channels, edges, nodes, events, and control flow.
std::function< json(const json &current, const json &incoming)> ReducerFn
Custom reducer function signature.
Definition types.h:103
std::function< std::string(const GraphState &)> ConditionFn
Condition function signature for conditional edge routing.
Definition types.h:919
std::function< std::unique_ptr< GraphNode >(const std::string &name, const json &config, const NodeContext &ctx)> NodeFactoryFn
Factory function signature for creating graph nodes.
Definition loader.h:175
Singleton registry for conditional edge routing functions.
Definition loader.h:102
std::vector< std::string > labels
Labels the condition is known to return ("known" for open specs, "exactly these" for closed specs).
Definition loader.h:105
bool open
True when the condition can return values outside labels (e.g.
Definition loader.h:109
Dependency injection context passed to nodes during construction.
Definition types.h:753