Hello Hujui and welcome to Using English
First, let me say thank you for for using correct capitalization and punctuation in your post. I wish all first-time posters did the same.
The rule is to use "a" before consonant SOUNDS and "an" before vowel SOUNDS.
An FBI agent because we say "eff bee eye" etc.
So yes, we write them the way we say them.
Some words (like "herb") are said differently by different people. In this case, Americans say "an erb" but our British friends say "a herb."
"Historical" is another word that people say differently. I say "an 'istorical" but some people say "a historical" - so you can write that one either way.
Interested in Language