NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
invocation.h
Go to the documentation of this file.
1
9#pragma once
10
11#include <neograph/api.h>
12#include <neograph/json.h>
15
16#include <cstdint>
17#include <optional>
18#include <string>
19#include <string_view>
20#include <vector>
21
22namespace neograph::program {
23
25enum class InvocationTerminalStatus : std::uint8_t {
26 Unknown,
27 Completed,
28 Failed,
29 Interrupted,
30 Cancelled,
31 BudgetExhausted,
32 TimedOut,
33};
34
35NEOGRAPH_PROGRAM_API std::string_view to_string(InvocationTerminalStatus status) noexcept;
37NEOGRAPH_PROGRAM_API InvocationTerminalStatus
38invocation_terminal_status_from_string(std::string_view value) noexcept;
39NEOGRAPH_PROGRAM_API bool invocation_terminal_status_succeeded(
40 InvocationTerminalStatus status) noexcept;
41NEOGRAPH_PROGRAM_API bool invocation_terminal_status_failed(
42 InvocationTerminalStatus status) noexcept;
43
45enum class InvocationDiagnosticSeverity : std::uint8_t {
46 Unknown,
47 Error,
48 Warning,
49 Info,
50};
51
52NEOGRAPH_PROGRAM_API std::string_view to_string(InvocationDiagnosticSeverity severity) noexcept;
53NEOGRAPH_PROGRAM_API InvocationDiagnosticSeverity
54invocation_diagnostic_severity_from_string(std::string_view value) noexcept;
55
57struct NEOGRAPH_PROGRAM_API InvocationDiagnostic {
58 std::string code;
59 std::string message;
60 InvocationDiagnosticSeverity severity = InvocationDiagnosticSeverity::Unknown;
61 std::string severity_value;
62 bool blocking = true;
63 json witness = json::object();
64
65 bool operator==(const InvocationDiagnostic&) const = default;
66};
67
72struct NEOGRAPH_PROGRAM_API InvocationTerminal {
73 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 1;
74
75 InvocationTerminalStatus status = InvocationTerminalStatus::Unknown;
76 std::string status_value = "unknown";
77 std::vector<InvocationDiagnostic> diagnostics;
78 json output = json::object();
79
80 static InvocationTerminal create(std::string status_value,
81 json output = json::object(),
82 std::vector<InvocationDiagnostic> diagnostics = {});
83 static InvocationTerminal parse(std::string_view stored_bytes);
84
85 bool succeeded() const noexcept;
86 bool failed() const noexcept;
87 std::string serialize_canonical() const;
88
89 bool operator==(const InvocationTerminal&) const = default;
90};
91
92NEOGRAPH_PROGRAM_API void to_json(json& value, const InvocationDiagnostic& diagnostic);
93NEOGRAPH_PROGRAM_API void from_json(const json& value, InvocationDiagnostic& diagnostic);
94NEOGRAPH_PROGRAM_API void to_json(json& value, const InvocationTerminal& terminal);
95NEOGRAPH_PROGRAM_API void from_json(const json& value, InvocationTerminal& terminal);
96
98struct NEOGRAPH_PROGRAM_API InvocationArtifactReference {
99 std::string artifact_identity;
100 std::string uri;
101 std::string media_type;
102 std::uint64_t size_bytes = 0;
103
104 bool operator==(const InvocationArtifactReference&) const = default;
105};
106
107NEOGRAPH_PROGRAM_API void to_json(json& value, const InvocationArtifactReference& artifact);
108NEOGRAPH_PROGRAM_API void from_json(const json& value, InvocationArtifactReference& artifact);
109
115struct NEOGRAPH_PROGRAM_API RunInvocation {
116 static constexpr std::uint32_t PROTOCOL_REVISION = 1;
117 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 1;
118
119 std::uint32_t protocol_revision = PROTOCOL_REVISION;
120 std::string owner_scope;
121 std::string agent_id;
122 std::string program_version_id;
123 std::string run_id;
124 std::string parent_run_id;
125 RunBudget budget;
126 json input = json::object();
127 std::uint64_t message_sequence = 0;
128 std::string idempotency_key;
129 std::string correlation_id;
130 std::optional<InvocationArtifactReference> artifact;
133 std::optional<ProgramActivation> selected_activation;
134
136 void validate() const;
138 std::string canonical_payload() const;
140 std::string canonical_identity() const;
141 std::string content_hash() const { return canonical_identity(); }
142 std::string id() const { return canonical_identity(); }
143
144 std::string serialize_canonical() const;
145 static RunInvocation parse(std::string_view stored_bytes);
146 std::string canonical_id() const { return canonical_identity(); }
147 static RunInvocation from_canonical(std::string_view stored_bytes) { return parse(stored_bytes); }
148
149 bool operator==(const RunInvocation& other) const;
150
151};
152
153NEOGRAPH_PROGRAM_API void to_json(json& value, const RunInvocation& invocation);
154NEOGRAPH_PROGRAM_API void from_json(const json& value, RunInvocation& invocation);
155
157enum class InvocationIdempotencyResult : std::uint8_t {
158 Distinct,
159 Duplicate,
160 Conflict,
161};
162using IdempotencyResult = InvocationIdempotencyResult;
163
164NEOGRAPH_PROGRAM_API std::string_view to_string(InvocationIdempotencyResult result) noexcept;
165
173 const RunInvocation& existing,
174 const RunInvocation& incoming);
175NEOGRAPH_PROGRAM_API InvocationIdempotencyResult compare_invocation_idempotency(
176 const RunInvocation& existing,
177 const RunInvocation& incoming);
178
179} // namespace neograph::program
Owner-scoped activation records for immutable Program versions.
NEOGRAPH_API export/import macro for shared-library builds.
Thin C++ RAII wrapper around yyjson with nlohmann-compatible API.
InvocationIdempotencyResult
Strict result for comparing one idempotency key in an owner mailbox.
Definition invocation.h:157
InvocationTerminalStatus
Terminal states accepted by the invocation contract.
Definition invocation.h:25
NEOGRAPH_PROGRAM_API InvocationTerminalStatus invocation_terminal_status_from_string(std::string_view value) noexcept
Unknown wire values return Unknown; callers must not treat that as success.
NEOGRAPH_PROGRAM_API InvocationIdempotencyResult compare_invocations(const RunInvocation &existing, const RunInvocation &incoming)
Compare requests at the durable boundary.
InvocationDiagnosticSeverity
Severity is also open-ended on the wire; unknown values remain unknown.
Definition invocation.h:45
Immutable outcome of one Program run attempt.
A transport-neutral artifact witness attached to one invocation.
Definition invocation.h:98
A diagnostic is retained even when its severity is not known locally.
Definition invocation.h:57
Terminal publication is separate from the request.
Definition invocation.h:72
One owner-scoped Program request.
Definition invocation.h:115
std::string canonical_payload() const
Canonical payload excludes the idempotency key and envelope metadata.
std::optional< ProgramActivation > selected_activation
Present only for an activation-selected top-level start.
Definition invocation.h:133
void validate() const
Validate ownership, identity, sequence and required request fields.
std::string canonical_identity() const
Content-addressed identity of the canonical payload.