Bugfix for agents

And updated the tests affected by the bug.