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/graph/execution.h>
13
14#include <asio/awaitable.hpp>
15
16#include <atomic>
17#include <cstdint>
18#include <exception>
19#include <memory>
20#include <optional>
21#include <string>
22#include <string_view>
23
24namespace neograph::graph {
25
27enum class InvocationStatus : std::uint8_t {
28 Completed = 0,
29 Interrupted = 1,
30 MaxSteps = 2,
31 Cancelled = 3,
32 Error = 4,
33 SafePoint = 5,
34};
35
36NEOGRAPH_API std::string_view to_string(InvocationStatus status) noexcept;
37
47 RunConfig config;
48 RunMetadata metadata;
49 RunResources resources;
50 GraphStreamCallback on_event;
51};
52
55 InvocationStatus status = InvocationStatus::Error;
56 std::optional<RunResult> run_result;
58 std::string error;
64 std::optional<FailureVerdict> failure;
65
66 bool succeeded() const noexcept {
67 return status == InvocationStatus::Completed ||
68 status == InvocationStatus::Interrupted ||
69 status == InvocationStatus::MaxSteps ||
70 status == InvocationStatus::SafePoint;
71 }
72 bool cancelled() const noexcept { return status == InvocationStatus::Cancelled; }
73};
74
84class NEOGRAPH_API RunInvocation final {
85public:
88 RunInvocation(std::shared_ptr<GraphEngine> engine, RunInvocationRequest request);
89
90 RunInvocation(const RunInvocation&) = delete;
91 RunInvocation& operator=(const RunInvocation&) = delete;
92 RunInvocation(RunInvocation&&) = delete;
93 RunInvocation& operator=(RunInvocation&&) = delete;
94 ~RunInvocation() = default;
95
96 const RunInvocationRequest& request() const noexcept { return request_; }
97 std::shared_ptr<CancelToken> cancel_token() const noexcept { return token_; }
98 void cancel() noexcept { token_->cancel(); }
99
100 InvocationResult run();
101 asio::awaitable<InvocationResult> run_async();
102
103 InvocationResult resume(json resume_value = {});
104 asio::awaitable<InvocationResult> resume_async(json resume_value = {});
105
106 InvocationResult resume_from(std::string checkpoint_id,
107 json resume_value = {});
108 asio::awaitable<InvocationResult> resume_from_async(
109 std::string checkpoint_id, json resume_value = {});
110
111private:
112 GraphExecution execution_;
113 RunInvocationRequest request_;
114 std::shared_ptr<CancelToken> token_;
115 std::atomic_bool started_{false};
116
117 void validate_request() const;
118 bool try_start() noexcept;
119 InvocationResult failure(std::string message) const;
120 static InvocationResult classify(RunResult result);
121 static InvocationResult classify_exception(std::exception_ptr error,
122 bool cancelled);
123};
124
125} // namespace neograph::graph
NEOGRAPH_API export/import macro for shared-library builds.
Owning, concrete execution capability for protocol hosts.
Definition execution.h:18
Owns one Core graph invocation and its cancellation lifetime.
Definition invocation.h:84
RunInvocation(std::shared_ptr< GraphEngine > engine, RunInvocationRequest request)
Compatibility constructor; new hosts retain GraphExecution instead.
InvocationStatus
The five terminal outcomes visible to every protocol host.
Definition invocation.h:27
std::function< void(const GraphEvent &)> GraphStreamCallback
Callback for receiving graph execution events.
Definition types.h:881
Result of one invocation, including a distinct terminal status.
Definition invocation.h:54
std::optional< FailureVerdict > failure
Error and Cancelled only: the classified failure (classify_failure()), with its stable code ("NG....
Definition invocation.h:64
std::string error
what() of the failure: for logs in this process, never for a peer.
Definition invocation.h:58
Configuration for a graph execution run.
Definition engine.h:225
Immutable input snapshot for one RunInvocation.
Definition invocation.h:46
Optional per-run metadata without changing the stable RunConfig ABI.
Definition engine.h:341
Optional persistence resources scoped to one run or resume call.
Definition engine.h:183