NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
tool.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <neograph/api.h>
12#include <neograph/types.h>
13
14#include <asio/awaitable.hpp>
15
16#include <chrono>
17#include <cstdint>
18#include <memory>
19#include <optional>
20#include <string>
21#include <vector>
22namespace neograph::graph {
23class CancelToken;
24}
25
26namespace neograph {
27class HookRuntime;
28class ToolEffectBroker;
29
40 std::shared_ptr<graph::CancelToken> cancel_token;
41 std::shared_ptr<ToolExecutionController> controller;
42 ToolExecutionIdentity identity;
44 std::shared_ptr<ToolEffectBroker> effect_broker;
46 std::string effect_task_id;
47 ToolEffectGrantIdentity effect_grant;
50 std::optional<std::chrono::steady_clock::time_point> deadline;
53 std::shared_ptr<HookRuntime> hook_runtime;
55 std::uint8_t requested_priority = 0;
57 std::uint8_t inherited_priority = 0;
58};
59
67class NEOGRAPH_API ContextualAsyncTool {
68 public:
69 virtual ~ContextualAsyncTool() = default;
70
71 virtual asio::awaitable<std::string> execute_async(
72 const json& arguments, ToolExecutionContext context) = 0;
73};
74
82struct NEOGRAPH_API ToolProcessSpec {
83 std::vector<std::string> argv;
84 std::vector<std::string> environment;
85 std::string working_directory;
86 std::string stdin_data;
87 bool interactive = false;
88};
89
98class NEOGRAPH_API ProcessTool {
99public:
100 virtual ~ProcessTool() = default;
101 virtual ToolProcessSpec prepare_process(
102 const json& arguments, const ToolExecutionContext& context) const = 0;
103};
104
114class NEOGRAPH_API Tool {
115 public:
116 virtual ~Tool() = default;
117
127 virtual ChatTool get_definition() const = 0;
128
134 virtual std::string execute(const json& arguments) = 0;
135
140 virtual std::string get_name() const = 0;
141
151 virtual asio::awaitable<std::string> execute_async(const json& arguments);
152};
153
185class NEOGRAPH_API AsyncTool : public Tool {
186 public:
191 asio::awaitable<std::string> execute_async(const json& arguments) override = 0;
192
197 std::string execute(const json& arguments) final;
198};
199
200} // namespace neograph
NEOGRAPH_API export/import macro for shared-library builds.
Adapter base class for tools whose work is naturally coroutine-shaped (HTTP fetch,...
Definition tool.h:185
asio::awaitable< std::string > execute_async(const json &arguments) override=0
Async work — override this.
std::string execute(const json &arguments) final
Sync facade — drives execute_async on a private io_context.
Optional async Tool extension that receives per-invocation context.
Definition tool.h:67
Optional extension for tools implemented by a real subprocess.
Definition tool.h:98
Abstract base class for tools that agents can call.
Definition tool.h:114
virtual asio::awaitable< std::string > execute_async(const json &arguments)
Canonical async entry point for tool execution.
virtual std::string execute(const json &arguments)=0
Execute the tool with the given arguments.
virtual std::string get_name() const =0
Get the tool name.
virtual ChatTool get_definition() const =0
Get the tool definition metadata.
Tool definition metadata sent to the LLM.
Definition types.h:62
Exact host authorization for one invocation of mediated Tool dispatch.
Per-invocation context for a cooperative asynchronous tool.
Definition tool.h:39
std::shared_ptr< HookRuntime > hook_runtime
Optional host-owned lifecycle boundary: dispatch_tool_calls emits the BeforeToolExecution and AfterTo...
Definition tool.h:53
std::uint8_t inherited_priority
Bounded critical-path inheritance supplied by the parent policy.
Definition tool.h:57
std::shared_ptr< ToolEffectBroker > effect_broker
Optional host broker; only mediated dispatch_tool_calls invokes it.
Definition tool.h:44
std::uint8_t requested_priority
Policy-derived priority request; depth never supplies this value.
Definition tool.h:55
std::string effect_task_id
Stable Core node invocation slot, populated by GraphEngine.
Definition tool.h:46
std::optional< std::chrono::steady_clock::time_point > deadline
The run's deadline.
Definition tool.h:50
Stable request identity used for resource accounting and audit correlation.
Description of a subprocess invocation owned by a ProcessTool.
Definition tool.h:82
Resource-aware, coroutine-safe execution boundary for tools.