Skip to main content
Tool calling agents can execute custom functions to interact with external systems, databases, APIs, or perform computations. The agent decides when to call tools based on the user’s request and uses the results to provide better responses.

Creating a Custom Tool

To create a tool, you need to implement the agents.Tool interface:

The hastekit.NewTool Helper

If you don’t need the full control of agents.BaseTool, hastekit.NewTool turns any func(ctx, In) (Out, error) into a tool. The input JSON schema is derived from the argument struct, and arguments/results are marshalled for you:
WithDescription, WithNeedsApproval, and WithDeferred take explicit [ArgsType, ReturnType] type parameters; WithName does not.
Both agents.BaseTool-based tools and hastekit.NewTool tools implement hastekit.Tool and can be mixed into the same Tools slice.

Basic Example

Here’s a simple example of an agent with a custom tool: