pulsatrix 1.1.0
Loading...
Searching...
No Matches
tool_registry.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <cstddef>
8#include <functional>
9#include <map>
10#include <string>
11#include <string_view>
12#include <vector>
13
14#include "pulsatrix/json.hpp"
17
18namespace pulsatrix::orch {
19
22using ToolHandler = std::function<ToolOutcome(const JsonValue& input)>;
23
25struct Tool {
26 std::string name;
27 std::string description;
33 bool strict = false;
34};
35
42public:
50
52 [[nodiscard]] const Tool* find(std::string_view name) const;
53 [[nodiscard]] std::size_t size() const { return tools_.size(); }
54 [[nodiscard]] bool empty() const { return tools_.empty(); }
56 [[nodiscard]] const std::vector<Tool>& tools() const { return tools_; }
57
59 [[nodiscard]] std::vector<ToolSpec> specs() const;
60
66 [[nodiscard]] ToolOutcome call(std::string_view name, const JsonValue& input) const;
67
70 [[nodiscard]] ToolExecutor executor() const;
71
72private:
73 std::vector<Tool> tools_;
74 std::map<std::string, std::size_t, std::less<>> index_;
75};
76
77} // namespace pulsatrix::orch
One JSON value: null, a boolean, a number, a string, an array or an object.
Definition json.hpp:22
The tools an agent may use. RunToolLoop() takes executor(), and a planned MCP server will serve the s...
Definition tool_registry.hpp:41
bool empty() const
Definition tool_registry.hpp:54
const Tool * find(std::string_view name) const
The tool named name, or nullptr.
ToolRegistry & add(Tool tool)
Adds tool.
const std::vector< Tool > & tools() const
The tools, in the order they were added.
Definition tool_registry.hpp:56
std::size_t size() const
Definition tool_registry.hpp:53
ToolExecutor executor() const
An executor for RunToolLoop() that calls call(). It refers to this registry, which must outlive it.
std::vector< ToolSpec > specs() const
The tools as ChatRequest::tools wants them, in the order they were added.
ToolOutcome call(std::string_view name, const JsonValue &input) const
Runs tool name on input. An unknown tool, an input that doesn't match the schema, or a handler that t...
A small strict JSON value, parser and deterministic writer (RFC 8259).
The orchestrator's message format, shared by every LLM provider.
Definition http.hpp:20
std::function< ToolOutcome(const ToolCall &)> ToolExecutor
Runs one tool call. ToolRegistry::executor() provides one; any function works.
Definition tool_loop.hpp:33
std::function< ToolOutcome(const JsonValue &input)> ToolHandler
Runs a tool on an input that already matches its schema. An exception becomes an error result with th...
Definition tool_registry.hpp:22
What a tool returned. An error is reported to the model, which can try again.
Definition tool_loop.hpp:24
A tool: what the model sees, and the function that runs it.
Definition tool_registry.hpp:25
ToolHandler handler
Definition tool_registry.hpp:30
std::string description
Definition tool_registry.hpp:27
JsonValue input_schema
A JSON Schema with "type": "object", using only the keywords json_schema.hpp lists.
Definition tool_registry.hpp:29
std::string name
letters, digits, _ and -, 1 to 128 characters
Definition tool_registry.hpp:26
bool strict
Ask the provider to guarantee inputs that match the schema. The schema must suit strict mode (see Str...
Definition tool_registry.hpp:33
The agent loop: ask the model, run the tools it calls, send back the results, repeat.