NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
scheduler.h
Go to the documentation of this file.
1
21#pragma once
22
23#include <neograph/api.h>
25
26#include <map>
27#include <memory>
28#include <optional>
29#include <set>
30#include <vector>
31
32namespace neograph::graph {
33
34class GraphState;
35class GraphRegistry;
36
46 std::string node_name;
47 std::optional<std::string> command_goto;
48};
49
60 std::vector<std::string> ready;
61 bool hit_end = false;
65 bool hit_explicit_end = false;
66 std::optional<std::string> winning_command_goto;
67};
68
77using BarrierState = std::map<std::string, std::set<std::string>>;
78
82using BarrierSpecs = std::map<std::string, std::set<std::string>>;
83
95struct JoinSpec {
96 std::vector<std::set<std::string>> slots;
97
98 bool operator==(const JoinSpec&) const = default;
99};
100
102using JoinSpecs = std::map<std::string, JoinSpec>;
103
114class NEOGRAPH_API Scheduler {
115public:
127 Scheduler(const std::vector<Edge>& edges,
128 const std::vector<ConditionalEdge>& conditional_edges,
129 BarrierSpecs barrier_specs = {});
130
132 Scheduler(const std::vector<Edge>& edges,
133 const std::vector<ConditionalEdge>& conditional_edges,
134 BarrierSpecs barrier_specs,
135 std::shared_ptr<const GraphRegistry> registry);
136
138 Scheduler(const std::vector<Edge>& edges,
139 const std::vector<ConditionalEdge>& conditional_edges,
140 BarrierSpecs barrier_specs,
141 JoinSpecs join_specs,
142 std::shared_ptr<const GraphRegistry> registry);
143
145 Scheduler(const std::vector<Edge>& edges,
146 const std::vector<ConditionalEdge>& conditional_edges,
147 BarrierSpecs barrier_specs,
148 JoinSpecs join_specs,
149 std::map<std::string, std::string> failure_targets,
150 std::shared_ptr<const GraphRegistry> registry);
151
172 std::vector<std::string> resolve_next_nodes(
173 const std::string& current, const GraphState& state) const;
174
180 std::vector<std::string> plan_start_step() const;
181
207 NextStepPlan plan_next_step(const std::vector<StepRouting>& routings,
208 const GraphState& state) const;
209
229 NextStepPlan plan_next_step(const std::vector<std::string>& just_ran,
230 const std::vector<NodeResult>& results,
231 const GraphState& state) const;
232
260 NextStepPlan plan_next_step(const std::vector<StepRouting>& routings,
261 const GraphState& state,
262 BarrierState& barrier_state) const;
263
265 NextStepPlan plan_next_step(const std::vector<std::string>& just_ran,
266 const std::vector<NodeResult>& results,
267 const GraphState& state,
268 BarrierState& barrier_state) const;
269
282 NextStepPlan plan_next_step(const std::vector<StepRouting>& routings,
283 const GraphState& state,
284 BarrierState& barrier_state,
285 const std::vector<bool>& failed) const;
286
288 const std::string* failure_target(const std::string& node) const;
289
292 bool ends_implicitly(const std::string& node) const;
293
295 const BarrierSpecs& barrier_specs() const { return barrier_specs_; }
296
298 const JoinSpecs& join_specs() const { return join_specs_; }
299
300private:
301 const std::vector<Edge>& edges_;
302 const std::vector<ConditionalEdge>& conditional_edges_;
303 BarrierSpecs barrier_specs_;
304 JoinSpecs join_specs_;
305 std::shared_ptr<const GraphRegistry> registry_;
306 std::map<std::string, std::string> failure_targets_;
307};
308
309} // namespace neograph::graph
NEOGRAPH_API export/import macro for shared-library builds.
Thread-safe container for all graph state channels.
Definition state.h:55
Immutable routing oracle for a compiled graph.
Definition scheduler.h:114
bool ends_implicitly(const std::string &node) const
True when node has neither a conditional edge nor a static edge, so it reaches END_NODE only implicit...
NextStepPlan plan_next_step(const std::vector< StepRouting > &routings, const GraphState &state) const
Decide the next ready set from this super-step's routing.
NextStepPlan plan_next_step(const std::vector< StepRouting > &routings, const GraphState &state, BarrierState &barrier_state, const std::vector< bool > &failed) const
Barrier-aware planning with handled failures (#364).
std::vector< std::string > plan_start_step() const
Nodes directly routed from __start__ at step 0.
Scheduler(const std::vector< Edge > &edges, const std::vector< ConditionalEdge > &conditional_edges, BarrierSpecs barrier_specs={})
Bind the scheduler to the graph's edge topology.
std::vector< std::string > resolve_next_nodes(const std::string &current, const GraphState &state) const
Resolve the direct successors of a node.
const std::string * failure_target(const std::string &node) const
The failure target of node, or null when it has no failure edge.
const JoinSpecs & join_specs() const
Read-only view of declared any_of joins (#363).
Definition scheduler.h:298
const BarrierSpecs & barrier_specs() const
Read-only view of declared barriers (mainly for tests).
Definition scheduler.h:295
NextStepPlan plan_next_step(const std::vector< std::string > &just_ran, const std::vector< NodeResult > &results, const GraphState &state) const
Convenience overload: pair up ready[i] with results[i].
Scheduler(const std::vector< Edge > &edges, const std::vector< ConditionalEdge > &conditional_edges, BarrierSpecs barrier_specs, JoinSpecs join_specs, std::map< std::string, std::string > failure_targets, std::shared_ptr< const GraphRegistry > registry)
Also bind failure edges (#364): failing node -> failure target.
Scheduler(const std::vector< Edge > &edges, const std::vector< ConditionalEdge > &conditional_edges, BarrierSpecs barrier_specs, JoinSpecs join_specs, std::shared_ptr< const GraphRegistry > registry)
Bind routing with legacy barriers and any_of joins (#363).
NextStepPlan plan_next_step(const std::vector< std::string > &just_ran, const std::vector< NodeResult > &results, const GraphState &state, BarrierState &barrier_state) const
NodeResult-taking barrier-aware overload.
Scheduler(const std::vector< Edge > &edges, const std::vector< ConditionalEdge > &conditional_edges, BarrierSpecs barrier_specs, std::shared_ptr< const GraphRegistry > registry)
Bind routing to a per-engine registry overlay.
NextStepPlan plan_next_step(const std::vector< StepRouting > &routings, const GraphState &state, BarrierState &barrier_state) const
Barrier-aware planning.
Graph engine type definitions: channels, edges, nodes, events, and control flow.
std::map< std::string, JoinSpec > JoinSpecs
Joins with at least one multi-alternative slot, by join node name.
Definition scheduler.h:102
std::map< std::string, std::set< std::string > > BarrierSpecs
Static barrier declarations extracted at graph-compile time.
Definition scheduler.h:82
std::map< std::string, std::set< std::string > > BarrierState
Per-barrier signal bookkeeping.
Definition scheduler.h:77
An AND join whose wait_for slots may each list alternatives (#363).
Definition scheduler.h:95
Plan for the next super-step.
Definition scheduler.h:59
bool hit_explicit_end
END_NODE was reached explicitly: an edge or route to it, or a Command.goto.
Definition scheduler.h:65
Per-node routing signal emitted by this super-step.
Definition scheduler.h:45