The ag
package (available on MELPA) has the ability to run ag
only within your specified folder or in project root. Check out its README on its github for more info.
Here are some of the answers from this stackexchange the elaborate on the use of ag
in emacs: