NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
context_store.h
1#pragma once
2
3#include <neograph/api.h>
4#include <neograph/runtime_context.h>
5
6#include <cstdint>
7#include <memory>
8#include <optional>
9#include <string>
10#include <string_view>
11
12namespace neograph {
13
16 std::string owner_id;
17 std::string feed_id;
18};
19
22 std::uint64_t sequence = 0;
23 std::optional<std::string> record_id;
24};
25
26enum class ContextStoreAppendResult : std::uint8_t {
27 Appended,
28 AlreadyPresent,
29 Conflict,
30};
31
32enum class ContextArtifactPutResult : std::uint8_t {
33 Stored,
34 AlreadyPresent,
35 Conflict,
36};
37
40 std::string owner_id;
41 std::string feed_id;
42 std::uint64_t from_sequence = 0;
43 std::uint64_t through_sequence = 0;
44 std::string digest;
45 std::string artifact_uri;
46};
47
58class NEOGRAPH_API ContextStore {
59public:
60 virtual ~ContextStore() = default;
61
62 virtual ContextStoreAppendResult append_history(
63 const ContextStoreFeed& feed,
64 const RuntimeHistoryRecord& record,
65 const std::optional<std::string>& expected_head_id) = 0;
66 virtual ContextStoreHead history_head(const ContextStoreFeed& feed) const = 0;
68 virtual std::optional<RuntimeHistoryRecord> history_record_by_message_id(
69 const ContextStoreFeed& feed,
70 std::string_view message_id) const;
71 virtual ContextHistoryRange snapshot_history(
72 const ContextStoreFeed& feed,
73 std::uint64_t from_sequence,
74 std::uint64_t through_sequence) const = 0;
75 virtual std::string hydrate_history(const ContextHistoryRange& range) const = 0;
77 virtual std::vector<RuntimeHistoryRecord> hydrate_records(
78 const ContextHistoryRange& range) const;
79
80 virtual ContextArtifactPutResult put_artifact(
81 std::string_view owner_id,
82 const ContextArtifact& artifact) = 0;
83 virtual std::optional<ContextArtifact> get_artifact(
84 std::string_view owner_id,
85 std::string_view artifact_id) const = 0;
86};
87
89class NEOGRAPH_API DurableContextStore : public ContextStore {
90public:
91 ~DurableContextStore() override = default;
92};
93
95class NEOGRAPH_API InMemoryContextStore final : public ContextStore {
96public:
97 static constexpr std::size_t MAX_OWNER_ID_BYTES = 256;
98 static constexpr std::size_t MAX_FEED_ID_BYTES = 256;
99 static constexpr std::size_t MAX_RECORD_BYTES = 1024 * 1024;
100 static constexpr std::size_t MAX_ARTIFACT_BYTES = 1024 * 1024;
101 static constexpr std::size_t MAX_RANGE_RECORDS = 4096;
102 static constexpr std::size_t MAX_RANGE_BYTES = 8 * 1024 * 1024;
103
105 ~InMemoryContextStore() override;
107 InMemoryContextStore& operator=(InMemoryContextStore&&) noexcept;
109 InMemoryContextStore& operator=(const InMemoryContextStore&) = delete;
110
111 ContextStoreAppendResult append_history(
112 const ContextStoreFeed& feed,
113 const RuntimeHistoryRecord& record,
114 const std::optional<std::string>& expected_head_id) override;
115 ContextStoreHead history_head(const ContextStoreFeed& feed) const override;
116 std::optional<RuntimeHistoryRecord> history_record_by_message_id(
117 const ContextStoreFeed& feed,
118 std::string_view message_id) const override;
119 ContextHistoryRange snapshot_history(
120 const ContextStoreFeed& feed,
121 std::uint64_t from_sequence,
122 std::uint64_t through_sequence) const override;
123 std::string hydrate_history(const ContextHistoryRange& range) const override;
124 std::vector<RuntimeHistoryRecord> hydrate_records(
125 const ContextHistoryRange& range) const override;
126 ContextArtifactPutResult put_artifact(
127 std::string_view owner_id,
128 const ContextArtifact& artifact) override;
129 std::optional<ContextArtifact> get_artifact(
130 std::string_view owner_id,
131 std::string_view artifact_id) const override;
132
133private:
134 struct Impl;
135 std::unique_ptr<Impl> impl_;
136};
137
138} // namespace neograph
NEOGRAPH_API export/import macro for shared-library builds.
Immutable context material.
Durable contract for owner-isolated runtime history and context artifacts.
virtual std::vector< RuntimeHistoryRecord > hydrate_records(const ContextHistoryRange &range) const
Hydrate full typed records; native seals require trusted storage custody.
virtual std::optional< RuntimeHistoryRecord > history_record_by_message_id(const ContextStoreFeed &feed, std::string_view message_id) const
Exact host message identity lookup; default is a bounded reverse scan.
Opt-in marker for ContextStore implementations that survive process restart.
Thread-safe in-memory implementation of the ContextStore durable contract.
std::vector< RuntimeHistoryRecord > hydrate_records(const ContextHistoryRange &range) const override
Hydrate full typed records; native seals require trusted storage custody.
std::optional< RuntimeHistoryRecord > history_record_by_message_id(const ContextStoreFeed &feed, std::string_view message_id) const override
Exact host message identity lookup; default is a bounded reverse scan.
One immutable, content-addressed line in the authoritative RAW history feed.
Immutable reference to an exact contiguous history range, not a feed copy.
Owner-scoped identity of one append-only runtime-history feed.
The current durable head of a feed.