Fixes the bug where agents stays in thinking

Note to self: There is potentially more to do make it totally safe.