NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
plan.h
Go to the documentation of this file.
1
9#pragma once
10
11#include <neograph/api.h>
12#include <neograph/json.h>
13
14#include <cstdint>
15#include <memory>
16#include <optional>
17#include <string>
18#include <string_view>
19#include <vector>
20
21namespace neograph::program {
22
23enum class ProgramOperationKind : std::uint8_t {
24 CallCore,
25 Sequence,
26 Branch,
27 Loop,
28 Retry,
29 Parallel,
30 Race,
31 Quorum,
32 Map,
33 Spawn,
34 Await,
35 Emit,
37 Cancel,
38 Return,
39 ParallelMap,
40 ExpandTaskGraph,
41};
42
43enum class ProgramTaskGraphFailurePolicy : std::uint8_t {
44 FailFast,
45 Collect,
46};
47
48enum class ProgramParallelMapItemSource : std::uint8_t {
49 Literal,
50 InputField,
51};
52
53enum class ProgramParallelMapFailurePolicy : std::uint8_t {
54 FailFast,
55 Collect,
56};
57
63struct NEOGRAPH_PROGRAM_API ProgramParallelMapSpec {
64 ProgramParallelMapItemSource item_source = ProgramParallelMapItemSource::Literal;
65 json literal_items = json::array();
66 std::string input_field;
67 std::string child_binding;
68 std::string input_from_field;
69 std::string input_to_field;
70 std::string output_from_field;
71 std::uint64_t max_items = 0;
72 std::uint32_t max_in_flight = 0;
73 std::uint64_t max_output_bytes = 0;
74 ProgramParallelMapFailurePolicy failure_policy = ProgramParallelMapFailurePolicy::FailFast;
75
76 bool operator==(const ProgramParallelMapSpec&) const = default;
77};
78
80struct NEOGRAPH_PROGRAM_API ProgramExpandTaskGraphSpec {
81 json proposal_source = json::object();
82 std::uint64_t max_tasks = 0;
83 std::uint64_t max_edges = 0;
84 std::uint64_t max_depth = 0;
85 std::uint64_t max_dynamic_compiles = 0;
86 std::uint64_t max_total_children = 0;
87 std::uint32_t max_concurrency = 0;
88 ProgramTaskGraphFailurePolicy failure_policy = ProgramTaskGraphFailurePolicy::FailFast;
89
90 bool operator==(const ProgramExpandTaskGraphSpec&) const = default;
91};
92
93NEOGRAPH_PROGRAM_API std::string_view to_string(ProgramOperationKind kind) noexcept;
94NEOGRAPH_PROGRAM_API ProgramOperationKind
95program_operation_kind_from_string(std::string_view value);
96
104struct NEOGRAPH_PROGRAM_API ProgramPlanDispatchDescriptor {
105 ProgramOperationKind operation = ProgramOperationKind::CallCore;
106 std::string source_pointer;
107 std::vector<std::string> children;
108 std::optional<std::string> then_id;
109 std::optional<std::string> else_id;
110 std::optional<std::string> body;
111 std::optional<std::string> child_binding;
112 std::vector<std::string> branches;
113 bool operator==(const ProgramPlanDispatchDescriptor&) const = default;
114};
115
117
119class NEOGRAPH_PROGRAM_API ProgramPlanNode final {
120public:
121 ProgramPlanNode(const ProgramPlanNode&) = default;
122 ProgramPlanNode& operator=(const ProgramPlanNode&) = default;
123 ProgramPlanNode(ProgramPlanNode&&) noexcept = default;
124 ProgramPlanNode& operator=(ProgramPlanNode&&) noexcept = default;
126
127 const std::string& id() const noexcept;
128 ProgramOperationKind operation() const noexcept;
129 const ProgramPlanDispatchDescriptor& dispatch() const noexcept;
130 const ProgramPlanDispatchDescriptor& dispatch_descriptor() const noexcept;
131 const std::string& source_pointer() const noexcept;
132 const std::optional<std::string>& core() const noexcept;
133 const std::vector<std::string>& children() const noexcept;
134 const std::optional<std::string>& then_id() const noexcept;
135 const std::optional<std::string>& else_id() const noexcept;
136 const std::optional<std::string>& body() const noexcept;
137 const std::optional<std::string>& child_binding() const noexcept;
138 const std::vector<std::string>& branches() const noexcept;
139 const std::optional<std::uint64_t>& max_iterations() const noexcept;
140 const std::optional<std::uint64_t>& max_attempts() const noexcept;
141 const std::optional<std::uint64_t>& min_success() const noexcept;
142 const std::optional<std::uint64_t>& timeout_ms() const noexcept;
143 const std::optional<std::string>& scope() const noexcept;
144 const std::optional<ProgramParallelMapSpec>& parallel_map() const noexcept;
145 const std::optional<ProgramExpandTaskGraphSpec>& expand_task_graph() const noexcept;
146 const std::optional<std::string>& reason() const noexcept;
148 json condition() const;
149 json value() const;
150 json items() const;
151
153 json to_json() const;
154
155private:
156 struct Impl;
157 explicit ProgramPlanNode(std::shared_ptr<const Impl> impl);
158 std::shared_ptr<const Impl> impl_;
159
160 friend class ProgramPlan;
161};
162
168class NEOGRAPH_PROGRAM_API ProgramPlan final {
169public:
170 static constexpr std::uint32_t SCHEMA_VERSION = 1;
171
172 ProgramPlan(const ProgramPlan&) = default;
173 ProgramPlan& operator=(const ProgramPlan&) = default;
174 ProgramPlan(ProgramPlan&&) noexcept = default;
175 ProgramPlan& operator=(ProgramPlan&&) noexcept = default;
176 ~ProgramPlan();
177
178 static ProgramPlan from_json(const json& plan);
179
180 std::uint32_t schema_version() const noexcept;
181 const std::string& root_id() const noexcept;
182 const std::vector<ProgramPlanNode>& nodes() const noexcept;
183 const ProgramPlanNode& root() const;
184 const ProgramPlanNode* find(std::string_view id) const noexcept;
185 json to_json() const;
186
187private:
188 struct Impl;
189 explicit ProgramPlan(std::shared_ptr<const Impl> impl);
190 std::shared_ptr<const Impl> impl_;
191};
192
200struct NEOGRAPH_PROGRAM_API ProgramStaticBudgetRequirements {
201 std::uint64_t max_program_operations = 0;
202 std::uint32_t max_concurrency = 0;
203 std::uint64_t max_core_steps = 0;
204 std::uint64_t max_core_invocations = 0;
205 std::uint32_t max_child_depth = 0;
206 std::uint64_t max_total_children = 0;
207 std::uint64_t max_dynamic_compiles = 0;
208
209 bool operator==(const ProgramStaticBudgetRequirements&) const = default;
210};
211
219NEOGRAPH_PROGRAM_API ProgramStaticBudgetRequirements
221
222} // namespace neograph::program
NEOGRAPH_API export/import macro for shared-library builds.
One immutable operation and its statically lowered references.
Definition plan.h:119
json condition() const
Authored condition/value/items are returned as owned immutable copies.
json to_json() const
Canonical lowered representation, useful to durable compatibility code.
Immutable operation graph.
Definition plan.h:168
@ Checkpoint
Include value and version in checkpoints.
Thin C++ RAII wrapper around yyjson with nlohmann-compatible API.
NEOGRAPH_PROGRAM_API ProgramStaticBudgetRequirements derive_static_budget_requirements(const ProgramPlan &plan)
Derive finite worst-case floors for a sealed Program operation tree.
Fixed, bounded source and admission contract for expand_task_graph.
Definition plan.h:80
Closed, bounded child-work fan-out contract carried by a parallel_map operation.
Definition plan.h:63
Immutable, typed dispatch metadata for one Program operation.
Definition plan.h:104
Worst-case resource floors implied by one finite typed Program tree.
Definition plan.h:200