Tools for agents are a trait, conveniently called Tool. The definition of the trait is as follows:
Macros are provided to make the implementation trivial. There is a macro for regular async functions, and one for structs if you need to have some sort
of internal state, tool, or anything else as well.
The macros will generate a ToolSpec, typed arguments (with serde_json), and the invoke call to the underlying function. Tools can have zero or more arguments. Their value always has to be of type &str.
The param names and the argument names of the function must be the same. Tools are executed in parallel.
Creating a tool from a function
Creating a tool from a struct
Creating a tool from a struct is similar. Important is that the struct name is the camelcase version of the method the tool should invoke.
Tool output and errors
In addition to feeding back output from tools to the llm with ToolOutput::Text, you can also return ToolOutput::Stop to stop the agent. The agent can always be resumed later.
ToolErrors are typed. By default, every ToolError will hard stop the agent. If you need custom handling for an error, you can use the after_tool or before_tool lifecycle hooks to report on or modify the tool calls and results.