In this paper, we present a hybrid, multi-layered, agent-oriented architecture for distributed sensor networks. We propose an agent-based middleware that bridges the gap between the programmable application layer consisting of software agents and the physical layer consisting of extremely small, low power devices that combine programmable computing with sensing, tracking and wireless communication capabilities. The middleware supports mechanisms for communication, mobility, cooperative data mining, querying, tasking, self-organization and administration of the constituent sensor nodes to build higher-level, interoperable applications with software agents. We discuss two major middleware components, namely, CCL: a command and control language and STACS: a programmable controller synthesizer. We explain how the controller can be used to configure the behavior of a node and CCL to command and control the nodes in a sensor network. We provide frameworks for communication and mobility. We suggest an agent model that integrates the software agents of the application with the hardware agents of the physical environment. We describe an integrated target tracking experiment, to demonstrate an implementation of this architecture. Finally, we conclude with an insight to our future challenges.