An Agent-based Middleware for Adaptive Systems