NeoGraph 0.16.0
A C++20 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

json config_schema (const std::string &type) const
 Declared config schema for a 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.
 
json export_schema () const
 Export a machine-readable description of the topology JSON format this engine accepts.
 
json node_effects (const std::string &type) const
 Declared channel effects for a node type.
 
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.
 
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.
 
std::vector< std::string > registered_types () const
 List all registered node type names, sorted.
 

Static Public Member Functions

static NodeFactory & instance ()
 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:753

Definition at line 191 of file loader.h.

Member Function Documentation

◆ config_schema()

json neograph::graph::NodeFactory::config_schema ( const std::string &  type) const

Declared config schema for a node type.

Returns the schema passed to the 3-arg register_type overload, or the permissive {"type":"object"} default for types registered without one (never throws on unknown types — returns the permissive default; create() is where unknown types fail). Backs strict-mode consumed-key accounting in GraphCompiler and per-type introspection for external tooling.

◆ 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... }, ... },
"node_effects": {
"<type>": { "reads": [...], "writes": [...], "exports": [...] }
},
"reducers": ["append", "overwrite", ...],
"conditions": ["has_tool_calls", "route_channel", ...],
"condition_specs": { ... }
}

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. node_effects preserves each declared effect contract verbatim.

Returns
The schema document as json.

◆ instance()

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

Get the singleton instance.

Returns
Reference to the global NodeFactory.

◆ node_effects()

json neograph::graph::NodeFactory::node_effects ( const std::string &  type) const

Declared channel effects for a node type.

Returns
{"reads":[...],"writes":[...],"exports":[...]}, or null json for types registered without an effect contract.

◆ register_type() [1/3]

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/3]

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.

◆ register_type() [3/3]

void neograph::graph::NodeFactory::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.

Parameters
effects{"reads": ["ch", ...], "writes": ["ch", ...], "exports": ["result", ...]} — the channels instances of this type touch at runtime. Optional exports marks written channels that a caller consumes after graph execution, so they are not reported as write-only by E6. Only exported channels that are also declared in writes suppress E6; the graph must still declare the channel itself. Enables static effect checking (GraphValidator E4/E5/E6: writes to undeclared channels, overwrite races, dead channels). Effect analysis only runs on graphs where EVERY node's type declared effects — one unknown type disables it (soundness of the checker over coverage).

◆ 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: