type CustomTool struct {
*core.BaseTool
}
func NewCustomTool() *CustomTool {
return &CustomTool{
BaseTool: &core.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 *responses.FunctionCallMessage) (*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
}