NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
result.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <neograph/api.h>
8#include <neograph/json.h>
10#include <neograph/types.h>
11#include <core/native_archive.h>
12
13#include <cstdint>
14#include <exception>
15#include <memory>
16#include <optional>
17#include <string>
18#include <string_view>
19#include <vector>
20
21namespace neograph::program {
22
23namespace detail {
24class RunControl;
25}
26
27enum class ProgramTerminalStatus : std::uint8_t {
28 Completed,
29 Interrupted,
32 TimedOut,
33 Failed,
34 AmbiguousEffect,
35 CheckpointIncompatible,
36};
37
38NEOGRAPH_PROGRAM_API std::string_view to_string(ProgramTerminalStatus status) noexcept;
39NEOGRAPH_PROGRAM_API ProgramTerminalStatus
40program_terminal_status_from_string(std::string_view value);
41
42struct RunBudget {
43 std::uint64_t wall_time_ms = 0;
44 std::uint64_t model_tokens = 0;
45 std::uint64_t monetary_microunits = 0;
46 std::uint32_t max_concurrency = 0;
47 std::uint64_t max_program_operations = 0;
48 std::uint64_t max_core_steps = 0;
49 std::uint64_t max_dynamic_compiles = 0;
51 std::uint32_t max_child_depth = 0;
53 std::uint64_t max_total_children = 0;
57 std::optional<std::uint64_t> max_node_retries;
58
59 bool operator==(const RunBudget&) const = default;
60};
61
62struct ProgramUsage {
63 std::uint64_t wall_time_ms = 0;
64 std::uint64_t model_tokens = 0;
67 std::uint64_t monetary_microunits = 0;
68 std::uint64_t program_operations = 0;
69 std::uint64_t core_steps = 0;
70 std::uint32_t peak_concurrency = 0;
73 std::uint64_t node_retries = 0;
74
75 bool operator==(const ProgramUsage&) const = default;
76};
77
79enum class ProgramMonetaryEvidence : std::uint8_t {
83 Estimated,
85 Held,
86};
87
88NEOGRAPH_PROGRAM_API std::string_view to_string(ProgramMonetaryEvidence evidence) noexcept;
89NEOGRAPH_PROGRAM_API ProgramMonetaryEvidence
90program_monetary_evidence_from_string(std::string_view value);
91
95 std::string call_id;
96 std::string operation_id;
98 std::string node;
101 std::string origin;
102 std::string model;
103 ProgramMonetaryEvidence evidence = ProgramMonetaryEvidence::Estimated;
105 std::uint64_t microunits = 0;
107 std::uint64_t reserved_microunits = 0;
109 std::string basis;
113 std::string catalog_version;
114 std::string catalog_digest;
117 bool conservative = false;
121 bool may_undercount = false;
124 bool replayed = false;
126 std::string reason;
132 json pricing = json::object();
142 std::optional<std::string> served_by;
143
144 bool operator==(const ProgramMonetaryRecord&) const = default;
145};
146
147struct CoreCheckpointIdentity {
148 std::string core_name;
149 std::string core_generation_id;
150 std::string core_thread_id;
151 std::string checkpoint_id;
152 std::uint32_t checkpoint_schema_version;
153
154 bool operator==(const CoreCheckpointIdentity&) const = default;
155};
156
157struct ProgramFailure {
158 std::string code;
159 std::string message;
160 std::string operation_id;
161 std::string core_node;
162 std::uint32_t attempts = 0;
163 json witness;
166 sp::runtime::Result provider_outcome;
167 std::exception_ptr provider_cause;
168
169 bool operator==(const ProgramFailure& other) const {
170 return code == other.code && message == other.message &&
171 operation_id == other.operation_id && core_node == other.core_node &&
172 attempts == other.attempts && witness == other.witness;
173 }
174};
175
176struct ProgramInterrupt {
177 std::string core_node;
178 json value;
179 std::optional<ProgramPendingInput> pending_input;
180 std::optional<ProgramPendingEffect> pending_effect;
181
182};
183
184struct ProgramResultData {
185 ProgramTerminalStatus status = ProgramTerminalStatus::Failed;
186 std::string run_id;
187 std::string program_version_id;
188 std::string bundle_id;
189 std::string operation_id = "root";
190 std::uint64_t attempt = 0;
191 json output = json::object();
192 ProgramUsage usage;
193 RunBudget remaining_budget;
194 std::optional<CoreCheckpointIdentity> checkpoint;
195 std::optional<ProgramInterrupt> interrupt;
196 std::optional<ProgramFailure> failure;
197 std::vector<std::string> execution_trace;
200 std::optional<UsageAccumulator::AuthoritySnapshot> provider_budget_authority;
202 std::vector<ProgramMonetaryRecord> monetary_records;
203};
204
205class NEOGRAPH_PROGRAM_API ProgramResult {
206public:
214 ProgramResult();
215 static ProgramResult create(ProgramResultData data);
218 static ProgramResult parse(std::string_view stored_bytes);
219 std::string serialize_canonical() const;
220 const std::string& id() const noexcept;
221 ProgramTerminalStatus status() const noexcept;
222 const std::string& run_id() const noexcept;
223 const std::string& program_version_id() const noexcept;
224 const std::string& bundle_id() const noexcept;
225 const std::string& operation_id() const noexcept;
226 std::uint64_t attempt() const noexcept;
227 json output() const;
228 ProgramUsage usage() const noexcept;
229 RunBudget remaining_budget() const noexcept;
230 std::optional<CoreCheckpointIdentity> checkpoint() const;
231 std::optional<ProgramInterrupt> interrupt() const;
233 std::optional<ProgramFailure> failure() const;
234 std::vector<std::string> execution_trace() const;
235 const std::optional<UsageAccumulator::AuthoritySnapshot>& provider_budget_authority() const noexcept;
238 const std::vector<ProgramMonetaryRecord>& monetary_records() const noexcept;
239
240private:
241 using ConstructionData = ProgramResultData;
242
243 struct Impl;
244 explicit ProgramResult(ConstructionData data, bool persistable = true);
245 ProgramResult restore_provider_failure(
246 std::string_view owner_scope, const std::shared_ptr<sp::NativeArchive>& archive) const;
247 static ProgramResult create_for_runtime(
248 ConstructionData data, std::string_view owner_scope,
249 const std::shared_ptr<sp::NativeArchive>& archive);
250 std::shared_ptr<const Impl> impl_;
251
252 friend class detail::RunControl;
253};
254
255} // namespace neograph::program
@ Cancelled
"cancelled" — cancelled via session/cancel.
NEOGRAPH_API export/import macro for shared-library builds.
@ BudgetExhausted
NG.BudgetExhausted: budget or quota exhaustion.
Thin C++ RAII wrapper around yyjson with nlohmann-compatible API.
Protocol-neutral durable pending input and effect values.
ProgramMonetaryEvidence
Where the amount of one priced provider call came from.
Definition result.h:79
@ Reported
The provider's own cost for the call (OpenRouter usage.cost).
@ Held
The outcome or its usage is unknown, so the call's reservation is charged.
One provider call of a Program attempt, priced in micro-USD (1e-6 USD).
Definition result.h:93
std::string call_id
Stable logical call slot, the provider journal's dispatch id.
Definition result.h:95
std::uint64_t microunits
Amount charged to the run.
Definition result.h:105
json pricing
What priced an estimated or held amount, empty before 0.16.0: entry (the catalogue entry id),...
Definition result.h:132
std::optional< std::string > served_by
The upstream a routing gateway named as having served the call, as the SDK reports it: OpenRouter's p...
Definition result.h:142
std::string origin
The provider's base URL, for example "https://openrouter.ai".
Definition result.h:101
bool replayed
Restored from the provider journal after a restart; its request was sent once, before the restart.
Definition result.h:124
std::uint64_t reserved_microunits
Preflight reservation; 0 when none could be computed.
Definition result.h:107
std::string node
Core node that made the call.
Definition result.h:98
std::string basis
"provider_reported", "list_rates" or "route_ceiling".
Definition result.h:109
std::string catalog_version
The catalogue that priced an estimated or held amount: "sp-model-catalogue/1" and the SchemaProvider ...
Definition result.h:113
bool may_undercount
The amount may be below the bill: the catalogue gave no price for a dearer band and the cheaper one p...
Definition result.h:121
bool conservative
Some tokens or tool uses were priced at the highest rate or count they could have billed at.
Definition result.h:117
std::string reason
Why an amount is held (the usage state or the unknown outcome).
Definition result.h:126