forgeant
docs-test-0
Build LLM-powered agents in C++
Loading...
Searching...
No Matches
tool.hpp
Go to the documentation of this file.
1
#ifndef FORGEANT_TOOL_TOOL_HPP
2
#define FORGEANT_TOOL_TOOL_HPP
3
4
#include <
forgeant/json/json.hpp
>
5
#include <
forgeant/schema/param_schema.hpp
>
6
#include <functional>
7
#include <string>
8
#include <utility>
9
10
namespace
forgeant
{
11
12
struct
Tool
{
13
std::string
name
;
14
std::string
description
;
15
Json
parameters
;
16
std::function<
Json
(
const
Json
&)>
execute
;
17
18
Tool
(std::string
name
, std::string
description
,
Json
parameters
,
19
std::function<
Json
(
const
Json
&)>
execute
)
20
:
name
(std::
move
(
name
)),
description
(std::
move
(
description
)),
21
parameters
(std::
move
(
parameters
)),
execute
(std::
move
(
execute
)) {}
22
};
23
24
template
<
typename
Params,
typename
Func>
25
Tool
make_tool
(std::string name, std::string description, Func&& func) {
26
auto
schema =
ParamSchema<Params>::schema
();
27
auto
handler = [f = std::forward<Func>(func)](
const
Json
& args) ->
Json
{
28
auto
params = args.
get
<Params>();
29
return
Json
(f(std::move(params)));
30
};
31
return
Tool
(std::move(name), std::move(description), std::move(schema), std::move(handler));
32
}
33
34
}
// namespace forgeant
35
36
#endif
// FORGEANT_TOOL_TOOL_HPP
forgeant::Json
Definition
json.hpp:27
forgeant::Json::get
T get() const
Definition
json.hpp:178
json.hpp
forgeant
Definition
agent.hpp:25
forgeant::make_tool
Tool make_tool(std::string name, std::string description, Func &&func)
Definition
tool.hpp:25
param_schema.hpp
forgeant::ParamSchema
Definition
param_schema.hpp:10
forgeant::Tool
Definition
tool.hpp:12
forgeant::Tool::name
std::string name
Definition
tool.hpp:13
forgeant::Tool::description
std::string description
Definition
tool.hpp:14
forgeant::Tool::Tool
Tool(std::string name, std::string description, Json parameters, std::function< Json(const Json &)> execute)
Definition
tool.hpp:18
forgeant::Tool::execute
std::function< Json(const Json &)> execute
Definition
tool.hpp:16
forgeant::Tool::parameters
Json parameters
Definition
tool.hpp:15
include
forgeant
tool
tool.hpp
Generated by
1.9.8