NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
hook_rpc.h
Go to the documentation of this file.
1
2#pragma once
3
6#include <neograph/runtime_context.h>
7
8#include <asio/awaitable.hpp>
9
10#include <chrono>
11#include <cstddef>
12#include <memory>
13#include <string>
14#include <vector>
15
16namespace neograph {
17
19struct RpcRequest {
20 std::string request;
21 std::chrono::steady_clock::time_point deadline;
22 std::shared_ptr<graph::CancelToken> cancel_token;
23};
24
29class NEOGRAPH_API RpcTransport {
30public:
31 virtual ~RpcTransport() = default;
32 virtual asio::awaitable<std::string> request_async(RpcRequest request) = 0;
33};
34
35class NEOGRAPH_API RpcProtocolError final : public std::runtime_error {
36public:
37 explicit RpcProtocolError(const std::string& message) : std::runtime_error(message) {}
38};
39
40struct HookRpcExecution {
41 HookExecutionReceipt receipt;
42 std::vector<ContextArtifact> artifacts;
43};
44
46class NEOGRAPH_API HookRpcExecutor final {
47public:
48 struct Limits {
49 std::size_t max_response_bytes = 64U * 1024U;
50 unsigned max_json_nesting = 16;
51 };
52
53 explicit HookRpcExecutor(std::shared_ptr<RpcTransport> transport);
54 HookRpcExecutor(std::shared_ptr<RpcTransport> transport, Limits limits);
55
56 asio::awaitable<HookRpcExecution> execute_async(
57 const HookInvocation& invocation, std::uint32_t attempt,
58 std::chrono::steady_clock::time_point deadline,
59 std::shared_ptr<graph::CancelToken> cancel_token = {}) const;
60
61private:
62 std::shared_ptr<RpcTransport> transport_;
63 Limits limits_;
64};
65
67class NEOGRAPH_API RpcHookExecutionAdapter final {
68public:
69 explicit RpcHookExecutionAdapter(std::shared_ptr<HookRpcExecutor> executor);
70
71 asio::awaitable<HookExecutionAttempt> execute_async(
72 const HookInvocation& invocation,
73 const RuntimeEvent& event,
74 std::uint32_t attempt,
75 ToolExecutionContext context) const;
76
77private:
78 std::shared_ptr<HookRpcExecutor> executor_;
79};
80
81} // namespace neograph
Cooperative cancellation primitive for graph runs.
Strict JSON-RPC 2.0 client for the fixed hooks/invoke method.
Definition hook_rpc.h:46
Binds the strict JSON-RPC executor to MandatoryHookRunner's backend contract.
Definition hook_rpc.h:67
Injectable wire boundary for hook RPC.
Definition hook_rpc.h:29
Durable hook dispatch contracts and in-memory journal.
A raw JSON-RPC exchange.
Definition hook_rpc.h:19
Per-invocation context for a cooperative asynchronous tool.
Definition tool.h:39