NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
neograph::graph::NodeFactory Class Reference

Singleton factory for creating graph nodes by type name. More...

#include <loader.h>

Public Member Functions

std::unique_ptr< GraphNodecreate (const std::string &type, const std::string &name, const json &config, const NodeContext &ctx) const
 Create a node by type name.
 
json export_schema () const
 Export a machine-readable description of the topology JSON format this engine accepts.
 
void register_type (const std::string &type, NodeFactoryFn fn)
 Register a custom node type.
 
void register_type (const std::string &type, NodeFactoryFn fn, json config_schema)
 Register a custom node type with a declared config schema.
 
std::vector< std::string > registered_types () const
 List all registered node type names, sorted.
 

Static Public Member Functions

static NodeFactoryinstance ()
 Get the singleton instance.
 

Detailed Description

Singleton factory for creating graph nodes by type name.

Maps node type names (used in JSON node definitions) to factory functions. Built-in types: "llm_call", "tool_dispatch", "intent_classifier", "subgraph".

[](const std::string& name, const json& config, const NodeContext& ctx) {
return std::make_unique<MyCustomNode>(name, ctx);
});
void register_type(const std::string &type, NodeFactoryFn fn)
Register a custom node type.
static NodeFactory & instance()
Get the singleton instance.
Dependency injection context passed to nodes during construction.
Definition types.h:251

Definition at line 165 of file loader.h.

Member Function Documentation

◆ create()

std::unique_ptr< GraphNode > neograph::graph::NodeFactory::create ( const std::string &  type,
const std::string &  name,
const json &  config,
const NodeContext ctx 
) const

Create a node by type name.

Parameters
typeNode type name.
nameUnique node name within the graph.
configNode-specific configuration from JSON.
ctxNode context with provider, tools, and model.
Returns
A unique_ptr to the created GraphNode, or throws if type not found.

◆ export_schema()

json neograph::graph::NodeFactory::export_schema ( ) const

Export a machine-readable description of the topology JSON format this engine accepts.

Intended for external tooling — notably a visual block-coding topology editor — so the editor's node palette and the engine cannot drift apart across NeoGraph versions. The returned document is JSON, shaped as:

{
"neograph_version": "0.6.0",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"topology": { ...JSON Schema for the top-level envelope... },
"node_types": { "<type>": { ...config JSON Schema... }, ... },
"reducers": ["append", "overwrite", ...],
"conditions": ["has_tool_calls", "route_channel", ...]
}

neograph_version lets a tool detect when its cached schema is older than the engine and warn the user. The topology fragment is fixed (defined by the graph compiler); per-type config schemas come from register_type's 3-arg overload, or default to a permissive object for types registered without one.

Returns
The schema document as json.

◆ instance()

static NodeFactory & neograph::graph::NodeFactory::instance ( )
static

Get the singleton instance.

Returns
Reference to the global NodeFactory.

◆ register_type() [1/2]

void neograph::graph::NodeFactory::register_type ( const std::string &  type,
NodeFactoryFn  fn 
)

Register a custom node type.

Parameters
typeNode type name (referenced in JSON node definitions).
fnFactory function that creates the node.

The node's config schema defaults to a permissive {"type":"object"} (any config object accepted). Existing callers keep working unchanged; external tooling that consumes export_schema() will simply render a free-form config for such a type. To declare a concrete config schema, use the 3-arg overload below.

◆ register_type() [2/2]

void neograph::graph::NodeFactory::register_type ( const std::string &  type,
NodeFactoryFn  fn,
json  config_schema 
)

Register a custom node type with a declared config schema.

Parameters
typeNode type name (referenced in JSON node definitions).
fnFactory function that creates the node.
config_schemaJSON Schema (Draft 2020-12) fragment describing this node type's accepted config fields. Used only by export_schema() for external tooling; the engine does not validate config against it at compile time. Additive: callers using the 2-arg overload are unaffected.

◆ registered_types()

std::vector< std::string > neograph::graph::NodeFactory::registered_types ( ) const

List all registered node type names, sorted.

Returns
Sorted vector of node type names.

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