Read the error. It should be telling you you have ambiguous definition of Agent. Name your local Agent variable something different to the Agent input parameter. You also need to check your Agent of type ?agent actually exists before trying to use it.