Agent-based service composition has provided a promising computing paradigm for the automatic web service composition. In this paper, a formal service agent model is proposed, which integrates the web service and software agent technologies into one cohesive entity. Based on the service agent model, a distributed planning algorithm for web service composition called DPAWSC is presented. DPAWSC formalizes web service composition into a graph search problem according to the dependence relations among service agents. The key to DPAWSC is that the alternative solution with smaller length has higher priority to be searched than one with larger length. DPAWSC is based on the distributed decision making of the autonomous service agents and addresses the distributed nature of web service composition. We evaluate the algorithm by simulation experiments and the results demonstrate that DPAWSC is effective for its ability to produce the high quality solution at a low cost of communications.