Resource management and task scheduling is a crucial problem (the core of all the questions) in grid environments. The aim of task scheduling is to take full advantage of grid resource and execute user's task request as early and quickly as possible. This paper introduces an agent-based resource management model and agent structure and its function. On the basis of local resource's adoption of the strategy "first come first served" to the task, we put forward a task scheduling algorithm using a technique of task advertisement and discovery. Agents are organized into a hierarchy and the algorithm is based on multi-agent cooperation, to ensure that this methodology achieves the goal of task scheduling.