NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1
12#pragma once
13
14#include <neograph/api.h>
15#include <neograph/json.h>
16
17#include <optional>
18#include <string>
19#include <vector>
20
21namespace neograph::a2a {
22
23using json = neograph::json;
24
40enum class WireDialect { V0_3, V1_0 };
41
43enum class TaskState {
44 Submitted,
45 Working,
46 InputRequired,
47 Completed,
48 Canceled,
49 Failed,
50 Rejected,
51 AuthRequired,
52 Unknown,
53};
54
55NEOGRAPH_API std::string task_state_to_string(TaskState s);
56NEOGRAPH_API std::string task_state_to_string(TaskState s, WireDialect dialect);
58NEOGRAPH_API TaskState task_state_from_string(std::string_view s);
59
61enum class Role { User, Agent };
62
63NEOGRAPH_API std::string role_to_string(Role r);
64NEOGRAPH_API std::string role_to_string(Role r, WireDialect dialect);
66NEOGRAPH_API Role role_from_string(std::string_view s);
67
71struct NEOGRAPH_API Part {
72 std::string kind;
73 std::string text;
77 json file;
78 json data;
79 json metadata;
82 std::string media_type;
83
85 static Part text_part(std::string s);
86};
87
89struct NEOGRAPH_API Message {
90 std::string message_id;
91 Role role = Role::User;
92 std::vector<Part> parts;
93 std::optional<std::string> task_id;
94 std::optional<std::string> context_id;
95 std::vector<std::string> reference_task_ids;
96 std::vector<std::string> extensions;
97 json metadata;
98 std::string kind = "message";
99};
100
102struct NEOGRAPH_API Artifact {
103 std::string artifact_id;
104 std::vector<Part> parts;
105 std::optional<std::string> name;
106 std::optional<std::string> description;
107 json metadata;
108};
109
111struct NEOGRAPH_API TaskStatus {
112 TaskState state = TaskState::Submitted;
113 std::optional<Message> message;
114 std::optional<std::string> timestamp;
115};
116
118struct NEOGRAPH_API Task {
119 std::string id;
120 std::string context_id;
121 TaskStatus status;
122 std::vector<Artifact> artifacts;
123 std::vector<Message> history;
124 json metadata;
125 std::string kind = "task";
126};
127
129struct NEOGRAPH_API MessageSendConfiguration {
130 std::vector<std::string> accepted_output_modes;
131 std::optional<bool> blocking;
132 std::optional<int> history_length;
134};
135
137struct NEOGRAPH_API MessageSendParams {
138 Message message;
139 std::optional<MessageSendConfiguration> configuration;
140 json metadata;
141};
142
149struct NEOGRAPH_API TaskStatusUpdateEvent {
150 std::string task_id;
151 std::string context_id;
152 TaskStatus status;
153 bool final = false;
154 json metadata;
155 std::string kind = "status-update";
156};
157
158struct NEOGRAPH_API TaskArtifactUpdateEvent {
159 std::string task_id;
160 std::string context_id;
161 Artifact artifact;
162 bool append = false;
163 bool last_chunk = false;
164 json metadata;
165 std::string kind = "artifact-update";
166};
167
171struct NEOGRAPH_API StreamEvent {
172 enum class Type { StatusUpdate, ArtifactUpdate, Task };
173 Type type = Type::Task;
174 std::optional<TaskStatusUpdateEvent> status_update;
175 std::optional<TaskArtifactUpdateEvent> artifact_update;
176 std::optional<a2a::Task> task;
177
178 bool is_final() const noexcept {
179 if (type == Type::StatusUpdate && status_update) return status_update->final;
180 // A Task frame is terminal unless it is the opening snapshot of a
181 // 1.0 / 0.3 task lifecycle stream (submitted or still working).
182 if (type == Type::Task) {
183 if (!task) return true;
184 return task->status.state != TaskState::Submitted
185 && task->status.state != TaskState::Working;
186 }
187 return false;
188 }
189};
190
193struct NEOGRAPH_API AgentInterface {
194 std::string url;
195 std::string protocol_binding;
196 std::string protocol_version;
197 std::string tenant;
198};
199
203struct NEOGRAPH_API AgentSkill {
204 std::string id;
205 std::string name;
206 std::string description;
207 std::vector<std::string> tags;
208 std::vector<std::string> examples;
209 std::vector<std::string> input_modes;
210 std::vector<std::string> output_modes;
211};
212
222struct NEOGRAPH_API AgentCard {
223 std::string name;
224 std::string description;
231 std::string url;
232 std::string version;
235 std::string protocol_version;
236 std::string preferred_transport = "JSONRPC";
237 std::vector<std::string> default_input_modes;
238 std::vector<std::string> default_output_modes;
239
243 bool streaming = true;
246 bool push_notifications = false;
249 bool extended_card = false;
250 bool supports_authenticated_extended = false;
251
255 std::vector<AgentInterface> supported_interfaces;
256
259 std::vector<std::string> skill_names;
262 std::vector<AgentSkill> skills;
263
277
279 json raw;
280};
281
282// ---------------------------------------------------------------------------
283// JSON adapters (defined in src/a2a/types.cpp).
284//
285// The two-argument to_json overloads emit the 0.3 dialect (unchanged);
286// the three-argument overloads select a WireDialect explicitly.
287// ---------------------------------------------------------------------------
288NEOGRAPH_API void to_json(json& j, const Part& p, WireDialect dialect);
289NEOGRAPH_API void to_json(json& j, const Message& m, WireDialect dialect);
290NEOGRAPH_API void to_json(json& j, const Artifact& a, WireDialect dialect);
291NEOGRAPH_API void to_json(json& j, const TaskStatus& s, WireDialect dialect);
292NEOGRAPH_API void to_json(json& j, const Task& t, WireDialect dialect);
293NEOGRAPH_API void to_json(json& j, const MessageSendConfiguration& c, WireDialect dialect);
294NEOGRAPH_API void to_json(json& j, const MessageSendParams& p, WireDialect dialect);
295NEOGRAPH_API void to_json(json& j, const TaskStatusUpdateEvent& e, WireDialect dialect);
296NEOGRAPH_API void to_json(json& j, const TaskArtifactUpdateEvent& e, WireDialect dialect);
297
298NEOGRAPH_API void to_json(json& j, const Part& p);
299NEOGRAPH_API void from_json(const json& j, Part& p);
300
301NEOGRAPH_API void to_json(json& j, const Message& m);
302NEOGRAPH_API void from_json(const json& j, Message& m);
303
304NEOGRAPH_API void to_json(json& j, const Artifact& a);
305NEOGRAPH_API void from_json(const json& j, Artifact& a);
306
307NEOGRAPH_API void to_json(json& j, const TaskStatus& s);
308NEOGRAPH_API void from_json(const json& j, TaskStatus& s);
309
310NEOGRAPH_API void to_json(json& j, const Task& t);
311NEOGRAPH_API void from_json(const json& j, Task& t);
312
313NEOGRAPH_API void to_json(json& j, const MessageSendConfiguration& c);
314NEOGRAPH_API void from_json(const json& j, MessageSendConfiguration& c);
315
316NEOGRAPH_API void to_json(json& j, const MessageSendParams& p);
317NEOGRAPH_API void from_json(const json& j, MessageSendParams& p);
318
322NEOGRAPH_API void to_json(json& j, const AgentCard& c);
326NEOGRAPH_API void to_json(json& j, const AgentCard& c, WireDialect dialect);
327NEOGRAPH_API void from_json(const json& j, AgentCard& c);
328
329NEOGRAPH_API void to_json(json& j, const TaskStatusUpdateEvent& e);
330NEOGRAPH_API void from_json(const json& j, TaskStatusUpdateEvent& e);
331
332NEOGRAPH_API void to_json(json& j, const TaskArtifactUpdateEvent& e);
333NEOGRAPH_API void from_json(const json& j, TaskArtifactUpdateEvent& e);
334
344NEOGRAPH_API StreamEvent parse_stream_event(const json& j);
345
353NEOGRAPH_API Task task_from_result(const json& result);
354
355} // namespace neograph::a2a
NEOGRAPH_API Role role_from_string(std::string_view s)
Accepts both user/agent (0.3) and ROLE_USER/ROLE_AGENT (1.0).
Role
Message role (spec §6.4).
Definition types.h:61
NEOGRAPH_API TaskState task_state_from_string(std::string_view s)
Accepts both the kebab-case (0.3) and TASK_STATE_* (1.0) spellings.
NEOGRAPH_API Task task_from_result(const json &result)
Coerce a SendMessage / message/send / GetTask / CancelTask result into a Task.
NEOGRAPH_API StreamEvent parse_stream_event(const json &j)
Parse a single SSE data: {...} JSON object into the right variant.
WireDialect
A2A wire dialect — the JSON encoding of the data model.
Definition types.h:40
TaskState
TaskState — kebab-case strings on the 0.3 wire, TASK_STATE_* on 1.0.
Definition types.h:43
NEOGRAPH_API export/import macro for shared-library builds.
Thin C++ RAII wrapper around yyjson with nlohmann-compatible API.
Subset of AgentCard required to interact (spec §5.5).
Definition types.h:222
std::string url
Public endpoint of the JSON-RPC binding.
Definition types.h:231
json security_requirements
1.0 securityRequirements: an array of {"schemes": {"<name>": {"list": [<scope>...]}}}.
Definition types.h:271
json security_schemes
1.0 securitySchemes: an object mapping a scheme name to a 1.0 SecurityScheme in ProtoJSON form,...
Definition types.h:268
std::string protocol_version
The 0.3 card's protocolVersion; A2AServer always serves "0.3.0" in the 0.3 card and 1....
Definition types.h:235
std::vector< AgentSkill > skills
Full skill objects (parsed, or set by a server).
Definition types.h:262
std::vector< AgentInterface > supported_interfaces
1.0 supportedInterfaces in card order (preferred first).
Definition types.h:255
json extensions
capabilities.extensions (both versions): an array of AgentExtension objects {uri, description,...
Definition types.h:276
std::vector< std::string > skill_names
Parsed skill ids.
Definition types.h:259
json raw
Full original document as received. Preserves fields we don't yet model.
Definition types.h:279
One protocol binding + version + URL an agent exposes (1.0 AgentInterface; 0.3 cards contribute addit...
Definition types.h:193
std::string protocol_binding
"JSONRPC" | "GRPC" | "HTTP+JSON" | custom
Definition types.h:195
std::string protocol_version
"Major.Minor", e.g. "1.0" / "0.3"
Definition types.h:196
std::string tenant
optional routing id (1.0 only)
Definition types.h:197
One capability the agent advertises (1.0 AgentSkill).
Definition types.h:203
Generated output (spec §6.7).
Definition types.h:102
Optional knobs for message/send (spec §7.2).
Definition types.h:129
Params object for message/send and message/stream.
Definition types.h:137
A single conversational turn (spec §6.4).
Definition types.h:89
std::vector< Part > parts
REQUIRED, ≥1 element.
Definition types.h:92
std::string message_id
client-generated UUID, REQUIRED
Definition types.h:90
std::optional< std::string > context_id
grouping id
Definition types.h:94
json metadata
optional bag
Definition types.h:97
std::optional< std::string > task_id
server task id (omit on first send)
Definition types.h:93
One content fragment of a Message or Artifact.
Definition types.h:71
std::string media_type
1.0 Part.media_type for text/data parts (e.g.
Definition types.h:82
json metadata
optional extension bag
Definition types.h:79
std::string kind
"text" | "file" | "data"
Definition types.h:72
static Part text_part(std::string s)
Convenience: TextPart of given content.
json file
populated when kind == "file".
Definition types.h:77
json data
populated when kind == "data" (arbitrary JSON)
Definition types.h:78
std::string text
populated when kind == "text"
Definition types.h:73
Tagged union over the two streaming event types + the terminal Task message.
Definition types.h:171
SSE event emitted by message/stream and tasks/resubscribe while a Task is running.
Definition types.h:149
Status snapshot of a running Task (spec §6.5).
Definition types.h:111
std::optional< std::string > timestamp
RFC3339 UTC.
Definition types.h:114
A unit of work tracked by the agent (spec §6.1).
Definition types.h:118
std::string id
server-generated, REQUIRED
Definition types.h:119
std::string context_id
server-generated grouping id
Definition types.h:120