Okay, what follows is definitely not a working code, but just a lot of theorising and untested ideas. Therefore criticism and comments are extremely welcome.
It is theorized, that it's possible to create a working framework supporting a fully dynamic aristocracy system for Warband, with possibility to have NPCs 100% dynamically-generated from mod-defined templates.
To a certain extent this has been done before by "rewriting" a hero troop record with new name, xp/level, attributes, skills, proficiencies and equipment. However this method does not allow for face randomization, as even tf_randomize_face hero troops only get their face randomized at the beginning of the game, and never afterwards. So any replacements in the existing pool of heroes will inevitably have the same face as their predecessors. This fact imposes and additional limitation on the amount of heroes of different nationalities - if you need more Sarranid heroes than you have hero troops defined, you are out of luck.
As someone who is not satistifed with half-measures, I've been trying to devise a way to have fully dynamic heroes, up to and including a unique randomized face for each and every one of them. For quite a time I considered the idea of not using hero troops at all (with the exception of the player), but this idea was eventually scrapped due to two major problems: leveling of player's companions, and party skills.
However after some consideration, I came up with similar, but entirely different idea: instead of substituting hero troops with randomized DNA-generated regular troops, we should only substitute their looks.
Hero troops remain in the game and function absolutely identically to how they always worked. What changes are implemented, however, are as follows:
1. All hero troops become associated with an "image-troop" - essentially a 1st level regular troop with a defined face range for face generation. Essentially, this boils down to two slots: one referencing the image-troop ID, and another containing the unique hero DNA.
2. Actual hero troops are used in real parties and party templates, as well as for inventory handling and auto-resolve calculations.
3. For all tableau-related scripts generating a picture of the hero, instead of the hero troop him/herself, his/her image-troop is used (with overridden equipment). This includes party window ("tableau_game_party_window"), inventory window ("tableau_game_inventory_window"), character window ("tableau_game_character_sheet") and troop notes window ("tableau_troop_note_mesh"). Face generation interface in Edit Mode will not be affected, therefore it becomes impossible for player to change hero faces in Edit Mode.
4. Agents generated from image-troops with overridden attributes, skills, proficiencies and equipment are used in actual missions. The easiest and most generic way to achieve this is to make a basic on_agent_spawn trigger shared by all missions in the game, which will replace the generated hero agent with a DNA-initialized agent spawned from associated image-troop.
4.1. Since all image-troops are level 1, an additional trigger is necessary to grant extra HP to the spawned agent, as well as to render him/her unkillable (or a different trigger handling the death of said agent in order to support the lord permadeath feature).
4.2. Since all image-troops are level 1, an additional trigger is necessary to grant extra XP to whoever defeats the agent.
4.3. Since actual agent is replaced, any mission-caused changes to troop health and equipment must be handled by a separate script at the end of the mission.
4.4. Since regular troop cannot be correctly handled by tf_civilian flag in mission template, any missions involving enforcement of civilian-only grade clothing must be handled by a separate trigger and/or script.
5. All dialogs with the hero-troop must initialize the appropriate variables and immediately proceed to the dialog with image-troop, which will then proceed as normal, while pretending to be the actual hero troop. Note that dialogs will need additional support for quest handling - to retrieve the hero-associated quest in the actual hero dialog at the beginning of the conversation, as well as to ensure that any hero-related dialog gets created with association with appropriate hero by assigning the quest through an auto_proceed dialog with the actual hero troop.
It is theorized, that once implemented, this set of functionality will grant the modder with complete freedom with using it's hero troops - essentially, absolutely any hero troop record can be used to create absolutely any type of hero - kingdom monarch/lord/lady, village elder or arena master. Essentially, the mod will contain the list of potential heroes, and use it dynamically to allocate heroes and create new ones, changing their faction, age, gender, face, attributes/skills/proficiencies and equipment as necessary.
It is theorized, that it's possible to create a working framework supporting a fully dynamic aristocracy system for Warband, with possibility to have NPCs 100% dynamically-generated from mod-defined templates.
To a certain extent this has been done before by "rewriting" a hero troop record with new name, xp/level, attributes, skills, proficiencies and equipment. However this method does not allow for face randomization, as even tf_randomize_face hero troops only get their face randomized at the beginning of the game, and never afterwards. So any replacements in the existing pool of heroes will inevitably have the same face as their predecessors. This fact imposes and additional limitation on the amount of heroes of different nationalities - if you need more Sarranid heroes than you have hero troops defined, you are out of luck.
As someone who is not satistifed with half-measures, I've been trying to devise a way to have fully dynamic heroes, up to and including a unique randomized face for each and every one of them. For quite a time I considered the idea of not using hero troops at all (with the exception of the player), but this idea was eventually scrapped due to two major problems: leveling of player's companions, and party skills.
However after some consideration, I came up with similar, but entirely different idea: instead of substituting hero troops with randomized DNA-generated regular troops, we should only substitute their looks.
Hero troops remain in the game and function absolutely identically to how they always worked. What changes are implemented, however, are as follows:
1. All hero troops become associated with an "image-troop" - essentially a 1st level regular troop with a defined face range for face generation. Essentially, this boils down to two slots: one referencing the image-troop ID, and another containing the unique hero DNA.
2. Actual hero troops are used in real parties and party templates, as well as for inventory handling and auto-resolve calculations.
3. For all tableau-related scripts generating a picture of the hero, instead of the hero troop him/herself, his/her image-troop is used (with overridden equipment). This includes party window ("tableau_game_party_window"), inventory window ("tableau_game_inventory_window"), character window ("tableau_game_character_sheet") and troop notes window ("tableau_troop_note_mesh"). Face generation interface in Edit Mode will not be affected, therefore it becomes impossible for player to change hero faces in Edit Mode.
4. Agents generated from image-troops with overridden attributes, skills, proficiencies and equipment are used in actual missions. The easiest and most generic way to achieve this is to make a basic on_agent_spawn trigger shared by all missions in the game, which will replace the generated hero agent with a DNA-initialized agent spawned from associated image-troop.
4.1. Since all image-troops are level 1, an additional trigger is necessary to grant extra HP to the spawned agent, as well as to render him/her unkillable (or a different trigger handling the death of said agent in order to support the lord permadeath feature).
4.2. Since all image-troops are level 1, an additional trigger is necessary to grant extra XP to whoever defeats the agent.
4.3. Since actual agent is replaced, any mission-caused changes to troop health and equipment must be handled by a separate script at the end of the mission.
4.4. Since regular troop cannot be correctly handled by tf_civilian flag in mission template, any missions involving enforcement of civilian-only grade clothing must be handled by a separate trigger and/or script.
5. All dialogs with the hero-troop must initialize the appropriate variables and immediately proceed to the dialog with image-troop, which will then proceed as normal, while pretending to be the actual hero troop. Note that dialogs will need additional support for quest handling - to retrieve the hero-associated quest in the actual hero dialog at the beginning of the conversation, as well as to ensure that any hero-related dialog gets created with association with appropriate hero by assigning the quest through an auto_proceed dialog with the actual hero troop.
It is theorized, that once implemented, this set of functionality will grant the modder with complete freedom with using it's hero troops - essentially, absolutely any hero troop record can be used to create absolutely any type of hero - kingdom monarch/lord/lady, village elder or arena master. Essentially, the mod will contain the list of potential heroes, and use it dynamically to allocate heroes and create new ones, changing their faction, age, gender, face, attributes/skills/proficiencies and equipment as necessary.
Is it worth the effort, though? 
No.