Documentation Index
Fetch the complete documentation index at: https://hastekit.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
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.
To create a tool, you need to implement the agents.Tool interface:
type CustomTool struct {
*agents.BaseTool
}
func NewCustomTool() *CustomTool {
return &CustomTool{
BaseTool: &agents.BaseTool{
ToolUnion: responses.ToolUnion{
OfFunction: &responses.FunctionTool{
Name: "get_user_name",
Description: utils.Ptr("Returns the user's name"),
Parameters: map[string]any{
"type": "object",
"properties": map[string]any{
"user_id": map[string]any{
"type": "string",
"description": "The user ID to look up",
},
},
"required": []string{"user_id"},
},
},
},
},
}
}
func (t *CustomTool) Execute(ctx context.Context, params *agents.ToolCall) (*responses.FunctionCallOutputMessage, error) {
// Parse arguments
args := map[string]interface{}{}
if err := json.Unmarshal([]byte(params.Arguments), &args); err != nil {
return nil, err
}
userID := args["user_id"].(string)
// Your custom logic here
userName := lookupUserName(userID) // Example function
// Return the result
return &responses.FunctionCallOutputMessage{
ID: params.ID,
CallID: params.CallID,
Output: responses.FunctionCallOutputContentUnion{
OfString: utils.Ptr(userName),
},
}, nil
}
Basic Example
Here’s a simple example of an agent with a custom tool:
func main() {
// Create agent with tool
agent := client.NewAgent(&hastekit.AgentOptions{
Name: "Assistant",
Instruction: client.Prompt("You are a helpful assistant. Use the get_user_name tool to get the user's name and greet them."),
LLM: client.NewLLM(hastekit.LLMOptions{
Provider: llm.ProviderNameOpenAI,
Model: "gpt-4o-mini",
}),
Tools: []agents.Tool{
NewGetUserNameTool(),
},
})
handle, err := agent.Execute(context.Background(), &agents.AgentInput{
Messages: []responses.InputMessageUnion{
responses.UserMessage("Hello! Can you get my name for user_id '123'?"),
},
})
if err != nil {
log.Fatal(err)
}
}