NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
collaboration.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <neograph/api.h>
14#include <neograph/a2a/types.h>
15
16#include <cstdint>
17#include <memory>
18#include <mutex>
19#include <optional>
20#include <string>
21#include <string_view>
22#include <vector>
23
24#ifdef NEOGRAPH_A2A_PROGRAM
25namespace neograph::program {
26class ProgramVersion;
27struct RunInvocation;
28} // namespace program
29#endif
30
31namespace neograph::a2a {
32
33enum class CollaborationLinkState : std::uint8_t {
34 Proposed,
35 Accepted,
36 Revoked,
37};
38
39NEOGRAPH_API std::string_view to_string(CollaborationLinkState state) noexcept;
40NEOGRAPH_API CollaborationLinkState collaboration_link_state_from_string(std::string_view value);
41
43struct NEOGRAPH_API CollaborationLinkSpec {
44 std::uint32_t schema_version = 2;
45 std::string link_id;
46 std::string sender_owner_scope;
47 std::string receiver_owner_scope;
48 std::string sender_agent_id;
49 std::string receiver_agent_id;
50 std::string task_scope;
51 std::vector<std::string> capability_allowlist;
52 std::vector<std::string> effect_allowlist;
53 std::vector<std::string> artifact_allowlist;
54 std::vector<std::string> cancellation_rights;
56 std::vector<std::string> message_kind_allowlist;
57 std::uint64_t expires_at_unix_ms = 0;
58 std::uint32_t max_retries = 0;
59 std::uint64_t acknowledgement_timeout_ms = 1;
60
61 bool operator==(const CollaborationLinkSpec&) const = default;
62};
63
65class NEOGRAPH_API CollaborationLink final {
66public:
67 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 2;
68
69 static CollaborationLink create(CollaborationLinkSpec spec);
70 static CollaborationLink parse(std::string_view stored_bytes);
71
72 CollaborationLink accept(std::string receiver_agent_id, std::string consent_token) const;
73 CollaborationLink revoke(std::string actor_agent_id) const;
74
75 CollaborationLinkState state() const noexcept;
76 const CollaborationLinkSpec& spec() const noexcept;
77 const std::string& consent_fingerprint() const noexcept;
78 const std::string& content_hash() const noexcept;
79 bool is_expired(std::uint64_t now_unix_ms) const noexcept;
80 bool permits_capability(std::string_view capability) const noexcept;
81 bool permits_effect(std::string_view effect) const noexcept;
82 bool permits_artifact(std::string_view artifact_identity) const noexcept;
83 bool permits_message_kind(std::string_view kind) const noexcept;
84 bool permits_cancellation(std::string_view actor_agent_id) const noexcept;
85 std::string serialize_canonical() const;
86
87private:
88 struct Impl;
89 explicit CollaborationLink(std::shared_ptr<const Impl> impl);
90 std::shared_ptr<const Impl> impl_;
91};
92
93struct NEOGRAPH_API CollaborationArtifactReference {
94 std::string artifact_identity;
95 std::string uri;
96 std::string media_type;
97 std::uint64_t size_bytes = 0;
98
99 bool operator==(const CollaborationArtifactReference&) const = default;
100};
101
107struct NEOGRAPH_API CollaborationEnvelope {
108 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 1;
109
110 std::string link_id;
111 std::string sender_owner_scope;
112 std::string receiver_owner_scope;
113 std::string sender_agent_id;
114 std::string receiver_agent_id;
115 std::string sender_program_run_id;
116 std::string receiver_program_run_id;
119 std::string a2a_task_id;
120 std::string a2a_context_id;
121 std::string message_id;
122 std::string correlation_id;
123 std::uint64_t sequence = 0;
124 std::string kind;
125 std::string idempotency_key;
126 json payload = json::object();
127 std::vector<CollaborationArtifactReference> artifacts;
128
129 static CollaborationEnvelope create(const CollaborationLink& link,
130 std::string sender_program_run_id,
131 std::string receiver_program_run_id,
132 std::string a2a_task_id,
133 std::string a2a_context_id,
134 std::string message_id,
135 std::string correlation_id,
136 std::uint64_t sequence,
137 std::string kind,
138 std::string idempotency_key,
139 json payload = json::object(),
140 std::vector<CollaborationArtifactReference> artifacts = {});
141
142#ifdef NEOGRAPH_A2A_PROGRAM
146 static CollaborationEnvelope bind_program(const CollaborationEnvelope& envelope,
147 const program::ProgramVersion& version);
148#endif
149
150 static CollaborationEnvelope parse(std::string_view stored_bytes);
151 std::string serialize_canonical() const;
152 std::string content_hash() const;
153 bool is_terminal() const noexcept;
154};
155
162inline constexpr std::string_view COLLABORATION_EXTENSION_URI =
163 "https://github.com/fox1245/NeoGraph/blob/master/docs/reference-en.md"
164 "#a2a-collaboration-extension";
165
167NEOGRAPH_API Message collaboration_to_message(const CollaborationEnvelope& envelope);
168
170NEOGRAPH_API CollaborationEnvelope collaboration_from_message(const Message& message);
171
172enum class CollaborationRecordState : std::uint8_t {
173 Accepted,
174 Acknowledged,
175 Canceled,
176};
177
178NEOGRAPH_API std::string_view to_string(CollaborationRecordState state) noexcept;
179NEOGRAPH_API CollaborationRecordState collaboration_record_state_from_string(std::string_view value);
180
182struct NEOGRAPH_API CollaborationPeerIdentity {
183 std::string owner_scope;
184 std::string agent_id;
185
186 bool operator==(const CollaborationPeerIdentity&) const = default;
187};
188
194enum class CollaborationTaskAuthorization : std::uint8_t {
195 NotLinked,
196 Authorized,
197 Unauthorized,
198};
199
200struct NEOGRAPH_API CollaborationRecord {
201 CollaborationEnvelope envelope;
202 CollaborationRecordState state = CollaborationRecordState::Accepted;
203 std::string diagnostic;
204#ifdef NEOGRAPH_A2A_PROGRAM
208 struct ProgramRequest {
209 std::shared_ptr<const program::ProgramVersion> version;
210 std::shared_ptr<const program::RunInvocation> invocation;
211 };
212 std::optional<ProgramRequest> program_request;
213#endif
214};
215
216enum class CollaborationSubmitResult : std::uint8_t {
217 Accepted,
218 Duplicate,
219 Conflict,
220 Rejected,
221};
222
223NEOGRAPH_API std::string_view to_string(CollaborationSubmitResult result) noexcept;
224
230class NEOGRAPH_API CollaborationMailbox final {
231public:
232 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 2;
233
234 CollaborationMailbox(std::string owner_scope, std::string agent_id);
235 CollaborationMailbox(CollaborationMailbox&&) noexcept;
236 CollaborationMailbox& operator=(CollaborationMailbox&&) noexcept;
237 CollaborationMailbox(const CollaborationMailbox&) = delete;
238 CollaborationMailbox& operator=(const CollaborationMailbox&) = delete;
239 ~CollaborationMailbox();
240
241 static CollaborationMailbox parse(std::string_view stored_bytes);
242
243 const std::string& owner_scope() const noexcept;
244 const std::string& agent_id() const noexcept;
245
247 void accept_link(CollaborationLink link, std::string consent_token);
248 void revoke_link(std::string_view link_id, std::string actor_agent_id);
249
250 CollaborationSubmitResult submit(CollaborationEnvelope envelope);
251#ifdef NEOGRAPH_A2A_PROGRAM
252 CollaborationSubmitResult submit_program(CollaborationEnvelope envelope,
253 program::ProgramVersion version,
254 program::RunInvocation invocation);
256 CollaborationSubmitResult submit(CollaborationEnvelope envelope,
257 program::ProgramVersion version,
258 program::RunInvocation invocation);
259 std::optional<CollaborationRecord::ProgramRequest>
260 get_program_request(std::string_view idempotency_key) const;
261#endif
262 bool acknowledge(std::string_view idempotency_key);
263 bool cancel(std::string_view link_id,
264 std::string_view correlation_id,
265 std::string_view actor_agent_id);
266
268 std::optional<CollaborationRecord> get(std::string_view idempotency_key) const;
273 bool authenticates_sender(std::string_view link_id,
274 const CollaborationPeerIdentity& peer) const;
275
281 CollaborationTaskAuthorization authorize_task(
282 std::string_view receiver_program_run_id,
283 const CollaborationPeerIdentity& peer,
284 bool require_cancellation = false) const;
285
286 std::vector<CollaborationRecord> snapshot() const;
289 bool permits_artifact(std::string_view link_id,
290 std::string_view artifact_identity) const;
291 std::string serialize_canonical() const;
292
293private:
294 struct Impl;
295 explicit CollaborationMailbox(std::shared_ptr<Impl> impl);
296 std::shared_ptr<Impl> impl_;
297};
298
299} // namespace neograph::a2a
Core data types for the Agent-to-Agent (A2A) protocol.
NEOGRAPH_API export/import macro for shared-library builds.
The exact logical message sent over same-runtime mailboxes or A2A.
std::string program_version_id
Optional admitted ProgramVersion identity. Legacy envelopes leave this empty.
Explicit invitation and capability boundary between two owners.
std::vector< std::string > message_kind_allowlist
Explicit protocol actions permitted across this owner boundary.