The team should have a stable index in the GetPlayspace().GetTeamCollection().GetTeams() array if you want a representative team number.
TeamCollection := GetPlayspace().GetTeamCollection()
if (AgentsTeam := TeamCollection.GetTeam[Agent]):
TeamArray := TeamCollection.GetTeams()
for (TeamNumber->Team : TeamArray):
if (AgentsTeam = Team):
# If you get here the team's number will be TeamNumber