We study the role played by nucleosynthesis processes in thermal pulses and by mixing episodes (the third dredge-up) in determining the abundances of intrinsic and extrinsic asymptotic giant branch (AGB) stars. This is done by comparing results from AGB models with observations of s-process and CNO nuclei in C stars (N-type) and in various classes of Ba stars (Ba dwarfs, CH subgiants, and Ba II giants) with metallicities typical of the disk population. The complementary information coming from abundances of Li and Mg isotopes is also discussed. According to a generally accepted scenario, the main neutron source at the origin of s-process nucleosynthesis is assumed to be the reaction C-13(alpha, n)O-16; a minor contribution derives also from the marginal activation of the reaction Ne-22(alpha, n)Mg-25 at the end of each flash. Making use of the latest neutron-capture cross sections and parameterizing the amount of C-13 burnt per pulse, we compute the nucleosynthesis occurring in the He shell and the dredge-up of material to the surface according to recent AGB models. Using envelope abundances after the first dredge-up derived from observations of first-ascent red giants and adopting standard prescriptions for mass loss, we succeed in fitting the photospheric compositions of C and Ba stars within their uncertainties. Our results confirm that C stars (N-type) are evolutionary descendants of normal (Tc-rich) S stars and are characterized by the same spread in mean neutron exposures (0.2-0.4 mbarn(-1)). As for the binary Ba stars, their abundances are compatible with the from an AGB primary component to a dwarf or giant secondary. We show that several constraints, including the Mg isotope ratios and the neutron density derived from the Rb/Sr ratio, require that s-processing occur in low-mass AGB stars but exclude the possibility that barium stars derive from primaries of intermediate mass (3 less than or equal to M/M. less than or equal to 8) efficiently burning the neutron source Ne-22. The s-process-enriched binary Ba giants show mean neutron exposures covering a wider range, reaching higher values (up to 1.0 mbarn(-1)) than for normal (single) C stars. An inverse correlation of the mean neutron exposure with metallicity is also present. Hence, the higher efficiency in s-processing shown by several Ba stars is interpreted as an indication that the metallicity range they cover is larger than for intrinsic AGB stars commonly observed. In fact, if the amount of primary C-13 burnt is roughly constant for the studied stars, their effectiveness in producing neutron-rich nuclei must increase (nonlinearly) toward lower metal contents. In this scenario the exponential distributions of neutron exposures provided by low-mass AGB stars can account well for the s-process abundances observed in Population I AGB stars, with no need to invoke strong single neutron exposures, as sometimes suggested in the past.