NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
tool_service.h
1// neograph::grpc — single-tool-call gRPC service + remote-tool client.
2//
3// Two mirror halves of the same `ToolService.CallTool` RPC:
4//
5// * run_tool_server — SERVE local C++ functions over gRPC (the fair
6// gRPC counterpart of MCP's JSON-RPC 2.0 `tools/call`; example 55).
7// * GrpcRemoteTool — CONSUME a remote ToolService method as an
8// ordinary neograph::Tool, so an Agent/ReAct loop can call a tool
9// that lives in another process/language with no code change on
10// the agent side (example 57). Ported from NexaGraph's GrpcTool.
11//
12// Opt-in (NEOGRAPH_BUILD_GRPC). Whole header behind NEOGRAPH_HAVE_GRPC
13// so the umbrella include never pulls grpc++.
14
15#pragma once
16
17#ifdef NEOGRAPH_HAVE_GRPC
18
19#include <functional>
20#include <memory>
21#include <string>
22#include <unordered_map>
23
24#include <neograph/api.h> // NEOGRAPH_API
25#include <neograph/tool.h> // neograph::Tool, ChatTool, json
26
27namespace neograph::grpc {
28
31using ToolFn = std::function<std::string(const std::string&)>;
32
36NEOGRAPH_API void run_tool_server(
37 const std::string& address,
38 std::unordered_map<std::string, ToolFn> tools);
39
53class NEOGRAPH_API GrpcRemoteTool : public neograph::Tool {
54public:
56 GrpcRemoteTool(const std::string& target,
57 std::string name,
58 std::string description,
59 neograph::json parameters);
60 ~GrpcRemoteTool() override;
61
62 ChatTool get_definition() const override;
63 std::string execute(const neograph::json& arguments) override;
64 std::string get_name() const override;
65
66private:
67 struct Impl;
68 std::unique_ptr<Impl> impl_;
69};
70
71} // namespace neograph::grpc
72
73#endif // NEOGRAPH_HAVE_GRPC
NEOGRAPH_API export/import macro for shared-library builds.
Abstract base class for tools that agents can call.
Definition tool.h:28
Abstract tool interface for callable functions.