Fix agent token logic

fixes issue #2