In the UK (the Advocate General in Scotland) an attorney general is one of the Law Officers, a Member of Parliament, who prosecutes for the Crown in certain cases, advises government departments on legal problems and decides if major criminal offences should be tried. The attorney general is politically appointed and changes when the government changes.
In the US, the attorney general has the same function as in the UK but there is one federal attorney general and one attorney general for each state. The federal attorney general is appointed by the President of the US and confirmed by the US Senate. The individual state’s attorney general is either appointed by the governor or elected by the people of the given state.