Factor out AI agent