NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
tool_dispatch.h
Go to the documentation of this file.
1
27#pragma once
28
29#include <neograph/api.h>
30#include <neograph/types.h>
31#include <neograph/tool.h>
32
33#include <asio/awaitable.hpp>
34
35#include <functional>
36#include <memory>
37#include <optional>
38#include <string>
39#include <vector>
40
41namespace neograph {
42
59 std::optional<json> resume_value;
60
62 std::string thread_id;
63
65 int step = 0;
66
72 std::shared_ptr<const std::vector<ToolCall>> batch_calls;
73};
74
85 enum class Kind {
86 Allow,
87 Deny,
90 };
91
92 Kind kind = Kind::Allow;
93
96 std::optional<json> args;
97
99 std::string reason;
100
103 std::optional<json> payload;
104
105 static ToolDecision allow() { return ToolDecision{}; }
106
107 static ToolDecision allow(json rewritten_args) {
108 ToolDecision d;
109 d.args = std::move(rewritten_args);
110 return d;
111 }
112
113 static ToolDecision deny(std::string reason) {
114 ToolDecision d;
115 d.kind = Kind::Deny;
116 d.reason = std::move(reason);
117 return d;
118 }
119
120 static ToolDecision interrupt(std::string reason) {
121 ToolDecision d;
122 d.kind = Kind::Interrupt;
123 d.reason = std::move(reason);
124 return d;
125 }
126
127 static ToolDecision interrupt(std::string reason, json payload) {
128 ToolDecision d;
129 d.kind = Kind::Interrupt;
130 d.reason = std::move(reason);
131 d.payload = std::move(payload);
132 return d;
133 }
134};
135
146using ToolGate =
147 std::function<asio::awaitable<ToolDecision>(ToolCall, ToolGateContext)>;
148
216NEOGRAPH_API asio::awaitable<std::vector<ChatMessage>>
217dispatch_tool_calls(std::vector<ToolCall> calls, std::vector<Tool*> tools,
218 ToolGate gate = {}, ToolGateContext gctx = {},
219 ToolExecutionContext execution = {});
220
221} // namespace neograph
NEOGRAPH_API export/import macro for shared-library builds.
Represents a single tool invocation requested by the LLM.
Definition types.h:27
A gate's verdict on one tool call.
std::string reason
Deny / Interrupt: why. Reaches the model (Deny) or the caller (Interrupt).
std::optional< json > args
Allow: the arguments to actually pass.
std::optional< json > payload
Interrupt: the structured payload, surfacing at RunResult::interrupt_value["value"] for the caller to...
@ Interrupt
Do not run it, and pause the whole run for a human.
@ Allow
Run it, optionally with rewritten arguments.
What a ToolGate is allowed to know about the run it is gating.
std::string thread_id
Mirrors RunConfig::thread_id. Empty on the Agent path.
std::optional< json > resume_value
The human's answer from GraphEngine::resume().
int step
Super-step index. Zero on the Agent path.
std::shared_ptr< const std::vector< ToolCall > > batch_calls
Immutable assistant-message batch being decided.
Abstract tool interface for callable functions.
NEOGRAPH_API asio::awaitable< std::vector< ChatMessage > > dispatch_tool_calls(std::vector< ToolCall > calls, std::vector< Tool * > tools, ToolGate gate={}, ToolGateContext gctx={}, ToolExecutionContext execution={})
Execute every tool call in calls and return one tool message each.
std::function< asio::awaitable< ToolDecision >(ToolCall, ToolGateContext)> ToolGate
Called once per tool call, before any tool runs.