We present a review of nucleosynthesis in AGB stars outlining the development of theoretical models and their relationship to observations. We focus on the new high resolution codes with improved opacities, which recently succeeded in accounting for the third dredge-up. This opens the possibility of understanding low luminosity C stars (enriched in s-elements) as the normal outcome of AGB evolution, characterized by production of 12 C and neutron-rich nuclei in the He intershell and by mass loss from strong stellar winds. Neutron captures in AGB stars are driven by two reactions: 13 C(α,n) 16 O, which provides the bulk of the neutron flux at low neutron densities (N n ≤ 10 7 n/cm 3 ), and 22 Ne(α,n) 25 Mg, which is mildly activated at higher temperatures and mainly affects the production of s-nuclei depending on reaction branchings. The first reaction is now known to occur in the radiative interpulse phase, immediately below the region previously homogenized by third dredge-up. The second reaction occurs during the convective thermal pulses. The resulting nucleosynthesis phenomena are rather complex and rule out any analytical approximation (exponential distribution of neutron fluences). Nucleosynthesis in AGB stars, modeled at different metallicities, account for several observational constraints, coming from a wide spectrum of sources: evolved red giants rich in s-elements, unevolved stars at different metallicities, presolar grains recovered from meteorites, and the abundances of s-process isotopes in the solar system. In particular, a good reproduction of the solar system main component is obtained as a result of Galactic chemical evolution that mixes the outputs of AGB stars of different stellar generations, born with different metallicities and producing different patterns of s-process nuclei. The main solar s-process pattern is thus not considered to be the result of a standard archetypal sprocess occurring in all stars. Concerning the 13 C neutron source, its synthesis requires penetration of small amounts of protons below the convective envelope, where they are captured by the abundant 12 C forming a 13 C-rich pocket. This penetration cannot be modeled in current evolutionary codes, but is treated as a free parameter. Future hydrodynamical studies of time dependent mixing will be required to attack this problem. Evidence of other insufficiencies in the current mixing algorithms is common throughout the evolution of low and intermediate mass stars, as is shown by the inadequacy of stellar models in reproducing the observations of CNO isotopes in red giants and in circumstellar dust grains. These observations require some circulation of matter between the bottom of convective envelopes and regions close to the H-burning shell (cool bottom processing). AGB stars are also discussed in the light of their possible contribution to the inventory of short-lived radioactivities that were found to be alive in the early solar system. We show that the pollution of the protosolar nebula by a close-by AGB st...