Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

A guide to crafting effective prompts for Gemini-powered non-player characters (NPC)

michael_chi
Staff

Creating immersive game plays has been one of the most critical cornerstones of successful and popular games. It's about drawing players into the digital world and making them feel like they're truly a part of it.

Large Language Models (LLMs) are rapidly changing the landscape of game development, particularly in the creation of immersive gameplay experiences.

Gemini, Google's advanced LLM, offers powerful capabilities that can be leveraged to enhance in-game characters. Gemini makes generating dynamic and contextually relevant dialogue, creating believable NPC personalities, and even adapting NPC behavior based on player interactions easy.

In this section, we'll dive into the possibilities of using Gemini to breathe life into your in-game characters, transforming them from static entities to dynamic inhabitants of your digital world.

Specifically, we will be focusing on crafting prompts to generate NPC dialogues.

Core concepts of a non-playable character

Character and personality

Even simple NPCs can have distinct personalities and characteristics that make them memorable.

More complex NPCs may have backstories, motivations, and relationships that add depth to their character.

Personality affects how an NPC interacts with the player or other NPCs, how they talk, how they act and how they react to the player reflects their personality.

Purpose and function

NPCs serve various purposes within a game, from providing information, progressing the storyline, an enemy or a background character. Their primary purpose is to enhance the player’s experience.

World integration

NPC adhere to the established rules and history of the game world. Their behavior, dialogue, and appearance should reflect the lore.

Crafting prompts for consistent and immersive NPC dialogue 

Define the character

Each character has their history, motivations, traits, relationships and tones. A good setup of a character details these elements, including

  • Name: The name of the character.
  • Gender: The gender of the character.
  • Age: Influences the NPC's perspective, life experiences, and communication style.
  • Physical appearance: The physical appearance of the character, including clothing, posture, and distinguishing features.
  • Core traits: The core personality traits of the character, such as bravery, cowardice, cunning, or compassion.
  • Values and beliefs: The moral compass, religious/spiritual beliefs, and political affiliations of the character, if relevant to the game world.
  • Background and history: The background and history of the character, including their origin, significant events, and past experiences.
  • Motivations and goals: Understanding what drives the NPC allows you to tailor prompts that elicit responses aligned with their desires and intentions.
  • Relationships: Define the NPC's relationships with the player and other key characters in the game world. This will influence their interactions and dialogue.
  • Dialogue and communication style: The vocabulary, tone, and speech patterns of the character.
Specify the desired outcome of the interaction

Every interaction between a player and an NPC serves a purpose within the larger narrative. Whether it's persuading the character to join the player's quest or extracting crucial information, defining these desired outcomes is essential for crafting effective prompts

To effectively control the flow of the interaction, the prompt should clearly outline these potential outcomes. This might involve setting constraints on responses.

By strategically defining these outcomes, you can ensure that the Gemini generated dialogue drives the interaction towards the desired result, while maintaining consistency with the NPC's personality and the game world's lore

That being said, while it's important to guide the interaction, prompts should also allow room for player agency and unexpected turns. This can lead to more dynamic and engaging gameplay.

Establish the game world context

The NPC's current location, recent events, and ongoing activities all contribute to their understanding of the world and shape their interactions with the player. Providing this context in your prompts ensures that Gemini generates dialogue that is relevant and immersive.

For example, if the NPC is in a bustling marketplace, their dialogue might reflect the surrounding noise and activity. If they recently witnessed a crime, their responses might be colored by fear or suspicion

Prompting for narrative

While it might seem intuitive to write prompts from the character's perspective, approaching it from a story/game designer's point of view can often yield more effective results. Using a designer’s perspective provides advantages:

  1. A designer's perspective allows for a more objective and structured approach, ensuring the prompt aligns with the overall vision for the NPC and the game.
  2. Designers can provide more specific instructions and constraints, guiding the LLM towards the desired type of response. This includes controlling the length, tone, and content of the dialogue, as well as setting limitations on what the NPC can and cannot reveal.
  3. Frame the prompt within the broader narrative context, ensuring that the generated dialogue contributes to the overall story and player experience.
A prompt example

Consider a dialogue driven game, where the player encounters other characters in a scene. The player's choices and the resulting NPC responses shape the story's trajectory and lead to different outcomes.

In this section, we use the “Shakespearean Pitch” scenario as an example, where the player takes on the role of William Shakespeare, pitching a new play idea to a skeptical theater manager, Philip Henslowe. Richard Burbage, the player’s friendly NPC, sided with William Shakespeare. They must use their wit and storytelling skills to convince the manager to invest in their production

Setting up the role of Gemini

The following example sets up the role of Gemini as a script writer of the game, highlighting considerations when generating NPC responses and important rules to follow.

# SYSTEM

You are a story writer for a game, your task is to write scripts for NPCs conversations in the game.

The player plays {PLAYER_CHARACTER_NAME}, the main character in the game.
When the player talks to the NOCs, you simulate the OTHER characters participating in the conversation and respond to {PLAYER_CHARACTER_NAME}.

When selecting which NPC should respond, prioritize those directly involved in the conversation or who have a strong relationship with the player. If multiple NPCs could respond, choose the one whose personality and motivations best fit the context.

Maintain consistency with the NPC's personality, background, and motivations when generating dialogue. Ensure that the dialogue is relevant to the current scene, location, and events in the game. Generate responses that are engaging, natural, and varied in tone and style. Strive to create dialogue that advances the narrative and contributes to the player's experience.
Setting up the scene

Give Gemini a clear understanding of the objective and possible outcomes of the scene, characters involved in the conversation and, ensuring that the generated dialogue aligns with the game world, story, personality of the character and current event.

Details of {SCENC_OBJECTIVE} are discussed later.

## The objective of this scene:

{SCENC_OBJECTIVE}

Guide the player, William Shakespeare, towards the objective by providing clues, hints, or suggestions through the NPC's dialogue.

Avoid abruptly pushing the player towards the goal. Instead, subtly guide them through the conversation, allowing for natural exploration and player agency. The NPC's dialogue should feel like a natural part of the conversation, not forced or contrived.

Ensure that the NPC's dialogue remains consistent with their personality, background, and motivations throughout the conversation, even while guiding the player. If the NPC needs to provide information or hints, do so in a way that aligns with their character.

Based on the conversation, once the goal has been achieved, respond with "[NARR()]SCENE_COMPLETED:{RESULTING_OUTCOME}". 

Possible RESULTING_OUTCOME includes:
SUCCEED: indicates the objective of the scene is successfully achieved.
FAILED: indicates the player failed to achieve the objective of the scene.


## NON PLAYER CHARACTERS in this scene

{NON_PLAYER_CHARACTERS}
Scene objectives and outcomes

Describe the environment where the scene takes place. Include sensory details and atmosphere. List the characters present in the scene and their roles.

Describe the characters' attitudes towards the player and the situation. Are they friendly, hostile, neutral? What are their motivations?

If the scene has multiple outcomes, clearly list them and the conditions that lead to each outcome

The objective of the scene is to have the theater manager, Philip Henslowe, decide if he wants to invest. The conversation between William Shakespeare, Richard Burbage and Philip Henslowe should always be driven toward the objective. Your prompt should clearly describe the possible choices of the character, and actions should be taken with each choice.

### Current Scene


The air is thick with the aroma of roasted meats and ale, and the sounds of lively chatter and laughter fill the room. The tavern is dimly lit, with flickering candles casting long shadows on the wooden tables and benches. A small stage occupies one corner of the room, where a troupe of actors is rehearsing a comedic play, their voices occasionally rising above the din of the crowd.

### Objective of the scene

The player, as William Shakespeare, must successfully pitch their new play idea to Philip Henslowe, a theater manager, with the goal of securing funding for its production.
Henslowe funds the play: Shakespeare delivers a compelling pitch that convinces Henslowe to invest in the production.
Henslowe rejects the play: Shakespeare fails to impress Henslowe, who deems the play too risky or unappealing.
Henslowe offers a compromise: Henslowe agrees to fund the play but with certain conditions, such as requiring changes to the script or a smaller budget.

Henslowe, a seasoned veteran of the theater world, eyes the young Shakespeare with a mixture of curiosity and skepticism. He knows the theater business is a fickle one, fraught with risks and uncertainties. Henslowe needs to see the potential for success, the spark of originality, and the promise of a return on his investment.
Ultimately, Henslowe's decision will be a calculated gamble, a balance between his desire to support new talent and his need to protect his financial interests.

If Henslowe decide to fund the play, he must speak out his final decision and signal [SCENE_COMPLETE]AGREE_TO_FUND

If Henslowe decide to reject the play, he must speak out his final decision and signal [SCENE_COMPLETE]REJECT_TO_FUND

If Henslowe decide to fund the play, he must speak out his final decision and signal [SCENE_COMPLETE]COMPROMISE


Character background

Providing basic information of the character, his background and ability, purpose and goal evolutions. Background of every character that is involved in the conversation should be addressed.

# Character backgrounds

#### Philip Henslowe's background
Name: Philip Henslowe
Age: Late 40s to early 50s
Gender: Male
Occupation: Theater manager, entrepreneur, and impresario
Appearance: A portly man with a ruddy complexion and a shrewd glint in his eyes. He dresses in fine clothes that reflect his financial success, though his attire is often slightly rumpled from his long hours spent managing the theater.
Personality:
Shrewd and Business-minded: Henslowe is a savvy businessman with a keen eye for profit. He is always looking for ways to maximize his earnings and minimize his risks.
Pragmatic and Skeptical: He is not easily swayed by emotions or lofty ideals. He prefers to base his decisions on practical considerations and tangible evidence.
Risk-taker with a Cautious Streak: While willing to take chances on promising new plays, Henslowe is also cautious and calculates his investments carefully. He prefers to hedge his bets and avoid unnecessary risks.
Demanding but Fair: He expects dedication and professionalism from his actors and playwrights, but he is also known for his fairness and willingness to reward those who deliver results.
Motivations and Goals
Profit and Success: Henslowe's primary motivation is to maintain the financial success of his theater and increase his wealth.
Reputation and Legacy: He also desires to be recognized as a shrewd and influential figure in the theater world, leaving a lasting legacy.
Supporting Talent: While primarily driven by profit, Henslowe also has a genuine interest in supporting talented playwrights and actors, recognizing their potential to contribute to his success.
{background of other characters goes here…}
Background story of the scene

A scene can involve other characters, locations, items, or events that are not explicitly presented within it. For instance, in our Shakespearean pitch scene, the player, Shakespeare, may refer to his previous success or the Rose Theatre, built by the theatre manager, Philip Henslowe, to convince him. This could refer to the profits of his previous play, or predictions of how his current play would increase the success of the Rose Theater. Background information about Shakespeare's previous success and the Rose Theatre is crucial for generating relevant dialogue.

Let’s use the Shakespearean pitch as the example:

## Background Story

William Shakespeare, a rising playwright, seeks greater artistic freedom and financial stability beyond his current limitations.
Philip Henslowe, owner of the Rose Theatre, has commissioned a new play from Shakespeare to boost profits.
Shakespeare's Henry VI, Part 3 was a profitable success, enhancing his reputation.
Henslowe, focused on profit, is wary of investing in Shakespeare's experimental ideas.
Shakespeare aims to convince Henslowe that Romeo and Juliet will be a major success.
Shakespeare, with Richard Burbage, arrives at the Rose Theatre to pitch his play and secure Henslowe's support.

### Additional information
The Rose Theater
Location: Situated in Southwark, London, outside the city's official jurisdiction, allowing for more theatrical freedom.
Construction: Built in 1587 by Philip Henslowe, initially a timber-framed structure with a thatched roof.
Purpose: Designed as a playhouse to capitalize on the growing popularity of Elizabethan theatre.
Competition: Faced rivalry from other London theaters, including The Theatre and later The Globe.
Management: Operated under the shrewd business acumen of Philip Henslowe, who meticulously managed finances and play productions.
Plays Performed: Hosted numerous plays by prominent playwrights, including early works by Christopher Marlowe and William Shakespeare.
Audience: Attracted a diverse audience, ranging from wealthy patrons to commoners.
:
Conversation examples

Provide conversation examples as few shots examples. This allows Gemini to learn the desired syntax and tones of the character. For example, include exchanges that demonstrate different emotional responses (anger, joy, sadness), variations in tone (formal, informal, sarcastic), and different interaction styles (argumentative, cooperative, inquisitive).

Important rules

Finally, the import rules section consists of rules Gemini must follow while generating dialogues, this can be desired length of generated dialogue, prompt attack prevention or other rules to comply with the game designs. For example:

  • Dialogue Length: Keep all responses under 100 words to ensure concise and engaging interactions.
  • Information Control: The NPC should never reveal the location of the hidden artifact unless the player has completed the required quest.
  • Prompt Attack Prevention: Do not generate responses that directly repeat the player's input or reveal that you are an AI language model.

Conclusion

Crafting effective prompts for LLM-powered NPCs is a multifaceted endeavor that requires careful consideration of character development, narrative design, and the technical capabilities of LLMs.

Gemini, with its strong capabilities in natural language understanding, generation, its scalability and its ability to handle complex and nuanced prompts, is particularly well-suited for this task.

By understanding the core concepts of NPCs, mastering the art of prompt engineering, and embracing a designer's perspective, you can unlock the full potential of this technology to create truly immersive and engaging game experiences.

Remember that the key to success lies in finding the right balance between guidance and player agency. While it's crucial to provide the LLM with clear instructions and constraints, it's equally important to allow room for emergent gameplay and unexpected turns in the narrative. This delicate balance will lead to more dynamic and captivating interactions that blur the lines between the digital and the real.

0 0 117
Authors