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

Thread-safe container for all graph state channels. More...

#include <state.h>

Public Member Functions

void apply_writes (const std::vector< ChannelWrite > &writes)
 Apply a batch of channel writes atomically (exclusive lock).
 
std::vector< std::string > channel_names () const
 List all channel names in this state.
 
uint64_t channel_version (const std::string &channel) const
 Get the version counter of a specific channel.
 
json get (const std::string &channel) const
 Read a channel's current value (thread-safe, shared lock).
 
std::vector< ChatMessageget_messages () const
 Convenience method to read the "messages" channel as a vector of ChatMessage.
 
uint64_t global_version () const
 Get the global version counter across all channels.
 
void init_channel (const std::string &name, ReducerType type, ReducerFn reducer, const json &initial_value=json())
 Initialize a new channel with a reducer and optional initial value.
 
void restore (const json &data)
 Restore state from a JSON snapshot (for time-travel).
 
json serialize () const
 Serialize the entire state to JSON (for checkpointing).
 
void write (const std::string &channel, const json &value)
 Write a value to a single channel through its reducer (exclusive lock).
 

Detailed Description

Thread-safe container for all graph state channels.

Provides concurrent read access (shared lock) and exclusive write access (unique lock) to state channels. Supports serialization for checkpointing and version tracking for change detection.

Definition at line 26 of file state.h.

Member Function Documentation

◆ apply_writes()

void neograph::graph::GraphState::apply_writes ( const std::vector< ChannelWrite > &  writes)

Apply a batch of channel writes atomically (exclusive lock).

All writes in the batch are applied under a single lock acquisition, ensuring consistency when multiple channels must be updated together.

Parameters
writesVector of ChannelWrite objects to apply.

◆ channel_names()

std::vector< std::string > neograph::graph::GraphState::channel_names ( ) const

List all channel names in this state.

Returns
Vector of channel name strings.

◆ channel_version()

uint64_t neograph::graph::GraphState::channel_version ( const std::string &  channel) const

Get the version counter of a specific channel.

Parameters
channelChannel name.
Returns
The channel's version counter (incremented on each write).

◆ get()

json neograph::graph::GraphState::get ( const std::string &  channel) const

Read a channel's current value (thread-safe, shared lock).

Parameters
channelChannel name.
Returns
The current value, or null if the channel does not exist.

◆ get_messages()

std::vector< ChatMessage > neograph::graph::GraphState::get_messages ( ) const

Convenience method to read the "messages" channel as a vector of ChatMessage.

Returns
Vector of ChatMessage objects from the "messages" channel.

◆ global_version()

uint64_t neograph::graph::GraphState::global_version ( ) const

Get the global version counter across all channels.

Returns
The global version counter.

◆ init_channel()

void neograph::graph::GraphState::init_channel ( const std::string &  name,
ReducerType  type,
ReducerFn  reducer,
const json &  initial_value = json() 
)

Initialize a new channel with a reducer and optional initial value.

Parameters
nameChannel name (must be unique within the graph).
typeReducer strategy for merging writes.
reducerCustom reducer function (used when type == ReducerType::CUSTOM).
initial_valueInitial channel value (default: null).

◆ restore()

void neograph::graph::GraphState::restore ( const json &  data)

Restore state from a JSON snapshot (for time-travel).

Parameters
dataJSON object previously produced by serialize().

◆ serialize()

json neograph::graph::GraphState::serialize ( ) const

Serialize the entire state to JSON (for checkpointing).

Returns
JSON object containing all channel values and versions.

◆ write()

void neograph::graph::GraphState::write ( const std::string &  channel,
const json &  value 
)

Write a value to a single channel through its reducer (exclusive lock).

Parameters
channelChannel name.
valueValue to merge via the channel's reducer.

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