Agents 1.4.0
Edge AI Agents SDK
Loading...
Searching...
No Matches
agents::Tool Class Reference

Interface for tools that an agent can use. More...

#include <tool.h>

Inheritance diagram for agents::Tool:
agents::MCPTool agents::tools::FileReadTool agents::tools::FileWriteTool agents::tools::MediaLoaderTool agents::tools::PythonTool agents::tools::RespondTool agents::tools::ShellCommandTool agents::tools::SummarizationTool agents::tools::WebSearchTool agents::tools::WikipediaTool

Public Member Functions

 Tool (const std::string &name, const std::string &description)
 Constructor.
 Tool (const std::string &name, const std::string &description, const JsonObject &parameters)
 Construct a new Tool object.
virtual ~Tool ()=default
 Destructor.
const std::string & getName () const
 Get the name of the tool.
const std::string & getDescription () const
 Get the description of the tool.
const ParameterMapgetParameters () const
 Get the parameters of the tool.
const JsonObjectgetSchema () const
 Get the schema of the tool.
void addParameter (const Parameter &param)
 Add a parameter to the tool.
void addParametersFromJson (const JsonObject &params)
 Add tool parameters from json definition.
void setCallback (ToolCallback callback)
 Set the execution callback.
virtual ToolResult execute (const JsonObject &params) const
 Execute the tool with the given parameters.
bool validateParameters (const JsonObject &params) const
 Validate parameters against schema.

Detailed Description

Interface for tools that an agent can use.

Tools are capabilities that the LLM can use to interact with the outside world. Each tool has a name, description, set of parameters, and execution logic.

Constructor & Destructor Documentation

◆ Tool() [1/2]

agents::Tool::Tool ( const std::string & name,
const std::string & description )

Constructor.

Parameters
nameThe name of the tool
descriptionThe description of the tool

◆ Tool() [2/2]

agents::Tool::Tool ( const std::string & name,
const std::string & description,
const JsonObject & parameters )

Construct a new Tool object.

Parameters
nameThe name of the tool
descriptionThe description of the tool
parametersThe json parameters of the tool

Member Function Documentation

◆ addParameter()

void agents::Tool::addParameter ( const Parameter & param)

Add a parameter to the tool.

Parameters
paramThe parameter to add

◆ addParametersFromJson()

void agents::Tool::addParametersFromJson ( const JsonObject & params)

Add tool parameters from json definition.

Parameters
paramsThe parameters to add

◆ execute()

virtual ToolResult agents::Tool::execute ( const JsonObject & params) const
virtual

Execute the tool with the given parameters.

Parameters
paramsThe parameters to execute the tool with
Returns
The result of the tool execution

Reimplemented in agents::MCPTool, agents::tools::FileReadTool, agents::tools::FileWriteTool, agents::tools::MediaLoaderTool, agents::tools::PythonTool, agents::tools::RespondTool, agents::tools::ShellCommandTool, agents::tools::SummarizationTool, agents::tools::WebSearchTool, and agents::tools::WikipediaTool.

◆ getDescription()

const std::string & agents::Tool::getDescription ( ) const

Get the description of the tool.

Returns
The description of the tool

◆ getName()

const std::string & agents::Tool::getName ( ) const

Get the name of the tool.

Returns
The name of the tool

◆ getParameters()

const ParameterMap & agents::Tool::getParameters ( ) const

Get the parameters of the tool.

Returns
The parameters of the tool

◆ getSchema()

const JsonObject & agents::Tool::getSchema ( ) const

Get the schema of the tool.

Returns
The schema of the tool

◆ setCallback()

void agents::Tool::setCallback ( ToolCallback callback)

Set the execution callback.

Parameters
callbackThe callback to set

◆ validateParameters()

bool agents::Tool::validateParameters ( const JsonObject & params) const

Validate parameters against schema.

Parameters
paramsThe parameters to validate
Returns
true of valid, otherwise false