  We present AGNfitter, a publicly available open-source algorithm implementing
a fully Bayesian Markov Chain Monte Carlo method to fit the spectral energy
distributions (SEDs) of active galactic nuclei (AGN) from the sub-mm to the UV,
allowing one to robustly disentangle the physical processes responsible for
their emission. AGNfitter makes use of a large library of theoretical,
empirical, and semi-empirical models to characterize both the nuclear and host
galaxy emission simultaneously. The model consists of four physical emission
components: an accretion disk, a torus of AGN heated dust, stellar populations,
and cold dust in star forming regions. AGNfitter determines the posterior
distributions of numerous parameters that govern the physics of AGN with a
fully Bayesian treatment of errors and parameter degeneracies, allowing one to
infer integrated luminosities, dust attenuation parameters, stellar masses, and
star formation rates. We tested AGNfitter's performace on real data by fitting
the SEDs of a sample of 714 X-ray selected AGN from the XMM-COSMOS survey,
spectroscopically classified as Type1 (unobscured) and Type2 (obscured) AGN by
their optical-UV emission lines. We find that two independent model parameters,
namely the reddening of the accretion disk and the column density of the dusty
torus, are good proxies for AGN obscuration, allowing us to develop a strategy
for classifying AGN as Type1 or Type2, based solely on an SED-fitting analysis.
Our classification scheme is in excellent agreement with the spectroscopic
classification, giving a completeness fraction of $\sim 86\%$ and $\sim 70\%$,
and an efficiency of $\sim 80\%$ and $\sim 77\%$, for Type1 and Type2 AGNs,
respectively.
