An Agent-Based Middleware for Adaptive Systems