A Task Allocation Middleware for Wireless Sensor Networks in a Multi-agent Environment