Fix agent_key function

Agent_key function errors out on api-version 2, with no providor or
providor_id specified.

This results in ```list``` being ```nil```, and checking ```list``` with
```list.length``` returns a NoMethodError(undefined method for
nil:NilClass).

In case a second check for "nil" was really needed, checking the
variable ```list``` for ```empty?``` was added.