NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
client.h
Go to the documentation of this file.
1
17#pragma once
18
19#include <neograph/api.h>
20#include <neograph/a2a/types.h>
21
22#include <asio/awaitable.hpp>
23
24#include <chrono>
25#include <functional>
26#include <string>
27
28namespace neograph::a2a {
29
44class NEOGRAPH_API A2AClient {
45 public:
48 explicit A2AClient(std::string base_url);
49
51 void set_timeout(std::chrono::seconds t) { timeout_ = t; }
52
59 AgentCard fetch_agent_card(bool force = false);
60
62 asio::awaitable<AgentCard> fetch_agent_card_async(bool force = false);
63
71 const std::string& text,
72 const std::string& task_id = "",
73 const std::string& context_id = "");
74
77
81 asio::awaitable<Task> send_message_async(const MessageSendParams& params);
82
84 Task get_task(const std::string& task_id, int history_length = 0);
85 asio::awaitable<Task> get_task_async(const std::string& task_id, int history_length = 0);
86
88 Task cancel_task(const std::string& task_id);
89 asio::awaitable<Task> cancel_task_async(const std::string& task_id);
90
98 using EventCallback = std::function<bool(const StreamEvent&)>;
105 using StreamCallback [[deprecated("use a2a::A2AClient::EventCallback")]]
107
108 Task send_message_stream(const std::string& text,
109 EventCallback on_event,
110 const std::string& task_id = "",
111 const std::string& context_id = "");
112
113 Task send_message_stream(const MessageSendParams& params,
114 EventCallback on_event);
115
117 json rpc_call(const std::string& method, const json& params);
118 asio::awaitable<json> rpc_call_async(const std::string& method, const json& params);
119
126 asio::awaitable<json> rpc_call_with_fallback(
127 const std::string& v1_method,
128 const std::string& v03_method,
129 const json& params);
130
131 const std::string& base_url() const { return base_url_; }
132
133 private:
134 std::string base_url_;
135 std::chrono::seconds timeout_ = std::chrono::seconds(30);
136 int request_id_ = 0;
137
139 AgentCard cached_card_;
140 bool card_loaded_ = false;
141};
142
143} // namespace neograph::a2a
Core data types for the Agent-to-Agent (A2A) protocol.
NEOGRAPH_API export/import macro for shared-library builds.
A2A client — call a remote agent over JSON-RPC + HTTP.
Definition client.h:44
AgentCard fetch_agent_card(bool force=false)
GET /.well-known/agent-card.json.
asio::awaitable< AgentCard > fetch_agent_card_async(bool force=false)
Async variant of fetch_agent_card.
Task get_task(const std::string &task_id, int history_length=0)
tasks/get — fetch the latest snapshot of a task.
Task send_message_sync(const std::string &text, const std::string &task_id="", const std::string &context_id="")
message/send — convenience wrapper around send_message_sync().
EventCallback StreamCallback
Definition client.h:106
Task cancel_task(const std::string &task_id)
tasks/cancel — request cancellation. Returns updated Task.
void set_timeout(std::chrono::seconds t)
Override the default 30 s request timeout.
Definition client.h:51
std::function< bool(const StreamEvent &)> EventCallback
message/stream — send a message and receive SSE-framed status updates as the agent progresses,...
Definition client.h:98
json rpc_call(const std::string &method, const json &params)
Lower-level: arbitrary JSON-RPC method.
asio::awaitable< json > rpc_call_with_fallback(const std::string &v1_method, const std::string &v03_method, const json &params)
Two A2A protocol generations are deployed in the wild: v1 (PascalCase, e.g.
asio::awaitable< Task > send_message_async(const MessageSendParams &params)
Async variant — server's response payload may be either a Message or a Task; we coerce both into a Ta...
Task send_message_sync(const MessageSendParams &params)
Send an arbitrary Message (multipart, file, structured data).
A2AClient(std::string base_url)
Subset of AgentCard required to interact (spec §5.5).
Definition types.h:160
Params object for message/send and message/stream.
Definition types.h:109
Tagged union over the two streaming event types + the terminal Task message.
Definition types.h:143
A unit of work tracked by the agent (spec §6.1).
Definition types.h:90