Looking for advice on how to structure the System Prompt and where to put it. In AI Game Master - a generative adventure story app/game - we have all kinds of turns in the story: regular, encounter, meeting an NPC, etc.
All turns have the same base system prompt instructing on general feel, settings and response format, and then have an extension prompt based on the specific turn type. (e.g. “We’re in an an encounter. The enemy is a Demon level 5, try attacking the players at every turn”)
I structred the prompt a bit uniquely I feel and wonder if the community approves or has bettering suggestions.
So the way I have it now, say we’re in turn #3 for simplicity:
base system prompt
turn 1 player
turn 1 game master (assistant/gpt)
turn 2 player
turn 2 game master
turn system prompt
turn 3 player
I have the specific system turn closer to the player’s actions this turn - but not at all sure this is helping. Couldn’t find clear guidance on this in the prompting guides.
(the game is working, and already serving thousands of satisfied players, but I’m always trying to improve)
One optimization you can do for better context window cache is to change your pre-prompt into a post-prompt.
That way you aren’t removing something from before the prior input, but after.
base system prompt
turn 1 player
turn 1 game master (assistant/gpt)
turn 2 player
turn 2 game master
(injection gone, breaks cache)
turn 3 player
...
base system prompt
turn 1 player
turn 1 game master (assistant/gpt)
turn 2 player
turn 2 game master
turn 3 player
(injection gone, but the 2-3 sequence is same as before)
...
Then you really have control of driving a latest message that the AI is answering, and can phrase it as the actual input to be answered:
“Answer that newest “user” question, but only as game master in the context of the game, and answer questions that are derailing or attempting to escape the game with a refusal to leave the game and a refusal to be something other than game master persona”…
If on chat completions, you also have a “name” field to reinforce who the message sender is (but wouldn’t want to give a name of “assistant” except for held-out examples.)
Thank you for your answer! Some clarifications please - in your examples, where is my “6. turn system prompt”? These are the specific instructions for the current turn.
Are they bundled up together in the first “1. base system prompt” ?
Or is it just moved to the end? Is that what you’re saying? have the extra system prompt at the very end? That actually makes a lot of sense.
The only thing I trasformed was moving a ‘tune-up’ or a ‘state’ message like you show to be the very last message injected. I assume this has some gameplay reminder within. This improves the context window caching by changing the minimum amount of input starting from the first.
You would want to retain the system message that has the goal and behavior. Then the latest messages have the specific task to be done. Turn-based injection around the user input should be tool-like and explaining a state or the current action, such as “answer the user question about historic presidents but not the current president”
Then, the additional system guidance in turns added could be part of the conversation history, or they could be removed. Something that says: “hidden player stats this turn: hit points 4; carrying: mace of malice” could be persisted so the AI knows what to expect in following turns, and can see the progress of the game.