NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
server.h
Go to the documentation of this file.
1
28#pragma once
29
30#include <neograph/api.h>
31#include <neograph/acp/types.h>
33
34#include <chrono>
35#include <iosfwd>
36#include <memory>
37#include <optional>
38#include <string>
39#include <string_view>
40
41namespace neograph::acp {
42
43class ACPServer;
44
57class NEOGRAPH_API ACPGraphAdapter {
58 public:
59 virtual ~ACPGraphAdapter() = default;
60
62 virtual std::string input_channel() const { return "prompt"; }
63
65 virtual std::string output_channel() const { return "response"; }
66
69 virtual std::string extract_user_text(
70 const std::vector<ContentBlock>& blocks) const;
71
78 virtual neograph::json build_initial_state(
79 const std::vector<ContentBlock>& blocks,
80 const std::string& session_id) const;
81
85 virtual std::string extract_agent_text(
86 const neograph::json& output) const;
87};
88
119class NEOGRAPH_API ACPClient {
120 public:
126
128 explicit ACPClient(ACPServer* server);
129
131 void bind(ACPServer* server);
132
134 bool bound() const noexcept;
135
138 void set_timeout(std::chrono::milliseconds t);
139
143 std::string read_text_file(std::string_view session_id,
144 std::string_view path,
145 std::optional<int> line = {},
146 std::optional<int> limit = {});
147
150 void write_text_file(std::string_view session_id,
151 std::string_view path,
152 std::string_view content);
153
160 RequestPermissionOutcome request_permission(
161 std::string_view session_id,
162 const ToolCallUpdate& tool_call,
163 const std::vector<PermissionOption>& options);
164
165 private:
166 ACPServer* server_ = nullptr;
167 std::chrono::milliseconds timeout_{std::chrono::seconds(30)};
168};
169
185class NEOGRAPH_API ACPServer {
186 public:
190 using NotificationSink = std::function<void(const neograph::json&)>;
191
196 ACPServer(std::shared_ptr<neograph::graph::GraphEngine> engine,
197 neograph::json info,
198 std::shared_ptr<ACPGraphAdapter> adapter = {});
199
200 ~ACPServer();
201
206 const AgentCapabilities& capabilities() const;
207
218 void run(std::istream& in, std::ostream& out);
219
221 void run();
222
227 bool is_running() const;
228
234 neograph::json handle_message(const neograph::json& envelope);
235
240
258 void stop();
259
261 bool initialized() const;
262
267 std::shared_ptr<ACPClient> client();
268
273 void attach_client(std::shared_ptr<ACPClient> c);
274
281 neograph::json call_client(std::string method,
282 neograph::json params,
283 std::chrono::milliseconds timeout
284 = std::chrono::seconds(30));
285
286 private:
287 struct Impl;
288 std::unique_ptr<Impl> impl_;
289};
290
291} // namespace neograph::acp
Core data types for the Agent Client Protocol (ACP).
NEOGRAPH_API export/import macro for shared-library builds.
Agent-side handle for issuing requests back to the editor.
Definition server.h:119
ACPClient(ACPServer *server)
Construct a client already bound to server.
bool bound() const noexcept
True once bind has been called with a non-null server.
void bind(ACPServer *server)
Late-binding hook — set the back-pointer to the server. Idempotent.
void write_text_file(std::string_view session_id, std::string_view path, std::string_view content)
Write (create or overwrite) a workspace file via the editor.
ACPClient()
Construct an unbound client.
RequestPermissionOutcome request_permission(std::string_view session_id, const ToolCallUpdate &tool_call, const std::vector< PermissionOption > &options)
Ask the editor to surface a permission prompt for an upcoming tool call.
Map between ACP ContentBlock[] and the engine's channels.
Definition server.h:57
virtual neograph::json build_initial_state(const std::vector< ContentBlock > &blocks, const std::string &session_id) const
Build the initial graph state for a turn.
virtual std::string extract_user_text(const std::vector< ContentBlock > &blocks) const
Concatenate every text-typed ContentBlock with single-space joins; non-text blocks are ignored unless...
virtual std::string input_channel() const
Channel name to write the inbound user text into (default "prompt").
Definition server.h:62
virtual std::string extract_agent_text(const neograph::json &output) const
Pull the agent's text reply out of the graph's final state.
virtual std::string output_channel() const
Channel name to read the agent's text reply from (default "response").
Definition server.h:65
HTTP-less, stdio-first ACP server hosting a NeoGraph engine.
Definition server.h:185
std::function< void(const neograph::json &)> NotificationSink
Sink for agent→client notifications (session/update).
Definition server.h:190
void run()
Convenience overload — uses std::cin / std::cout.
bool initialized() const
True after at least one initialize has been processed.
neograph::json handle_message(const neograph::json &envelope)
Process exactly one parsed JSON-RPC envelope.
neograph::json call_client(std::string method, neograph::json params, std::chrono::milliseconds timeout=std::chrono::seconds(30))
Issue a JSON-RPC request to the connected client and block until a response arrives.
bool is_running() const
True while run() is actively reading from its input stream.
AgentCapabilities & capabilities()
Mutable access to the capabilities advertised in initialize.
void run(std::istream &in, std::ostream &out)
Drive the server loop reading newline-delimited JSON-RPC envelopes from in and writing them to out.
std::shared_ptr< ACPClient > client()
Handle for issuing agent→client requests (fs/*, etc.).
void set_notification_sink(NotificationSink sink)
Where session/update notifications go.
void attach_client(std::shared_ptr< ACPClient > c)
Install a pre-constructed client and bind it to this server.
ACPServer(std::shared_ptr< neograph::graph::GraphEngine > engine, neograph::json info, std::shared_ptr< ACPGraphAdapter > adapter={})
void stop()
Signal a running run() loop to exit at the next message boundary.
Main graph execution engine with super-step loop and HITL support.
Capabilities advertised in InitializeResponse.
Definition types.h:70