Some refactoring to better manage the agent creation