Agents 0.0.2
Edge AI Agents SDK
Loading...
Searching...
No Matches
tool.h
1
10#pragma once
11
12#include <agents-cpp/types.h>
13#include <functional>
14
15namespace agents {
16
36
41using ToolCallback = std::function<ToolResult(const JsonObject&)>;
42
49class Tool {
50public:
56 Tool(const String& name, const String& description);
57
61 virtual ~Tool() = default;
62
67 const String& getName() const;
68
73 const String& getDescription() const;
74
80
85 const JsonObject& getSchema() const;
86
91 void addParameter(const Parameter& param);
92
97 void setCallback(ToolCallback callback);
98
104 virtual ToolResult execute(const JsonObject& params) const;
105
111 bool validateParameters(const JsonObject& params) const;
112
114protected:
118 String name_;
122 String description_;
126 ParameterMap parameters_;
130 ToolCallback callback_;
134 JsonObject schema_;
135
139 void updateSchema();
141};
142
151std::shared_ptr<Tool> createTool(
152 const String& name,
153 const String& description,
154 const std::vector<Parameter>& parameters,
155 ToolCallback callback
156);
157
158} // namespace agents
const String & getDescription() const
Get the description of the tool.
const JsonObject & getSchema() const
Get the schema of the tool.
void setCallback(ToolCallback callback)
Set the execution callback.
Tool(const String &name, const String &description)
Constructor.
bool validateParameters(const JsonObject &params) const
Validate parameters against schema.
virtual ToolResult execute(const JsonObject &params) const
Execute the tool with the given parameters.
const String & getName() const
Get the name of the tool.
void addParameter(const Parameter &param)
Add a parameter to the tool.
virtual ~Tool()=default
Destructor.
const ParameterMap & getParameters() const
Get the parameters of the tool.
Framework Namespace.
Definition agent.h:18
nlohmann::json JsonObject
JSON object type.
Definition types.h:39
std::string String
String type.
Definition types.h:27
std::function< ToolResult(const JsonObject &)> ToolCallback
Callback type for tool execution.
Definition tool.h:41
std::shared_ptr< Tool > createTool(const String &name, const String &description, const std::vector< Parameter > &parameters, ToolCallback callback)
Create a custom tool with a name, description, parameters, and callback.
std::map< String, Parameter > ParameterMap
Parameter map type.
Definition types.h:78
Parameter type for tools and LLM calls.
Definition types.h:51
Result of a tool execution.
Definition tool.h:22
String content
The content of the tool result.
Definition tool.h:30
bool success
Whether the tool execution was successful.
Definition tool.h:26
JsonObject data
The data of the tool result.
Definition tool.h:34