How to prevent breaking the agent conversation in a NPC?

Hi guys,

I have created a small agent that acts as an NPC in a video game, which is configured with its name, a context about its history, personality, hobbies, etc.

I use it so that the players can converse dynamically with the NPC.

My question is how can I prevent them from breaking the conversation?

For example, if my NPC is the guardian of a door and knows all the history related to the castle and the video game in which it is located, as long as the questions are oriented to video games, there is no problem, but if the user wants to ask for " who is elon musk? The agent also responds when his knowledge should not cover that information.

How do you avoid a bad prompt by the user?

Regarts!

1 Like

Hi @josemgmz

You can simply mention in the system message to answer questions related to the given context, if question is out of the context politely refuse.

Even better, you can ask the refusal to be in character.

1 Like

Yeah i have try that, but sometime it also is breaking the conversation it is not always but it is a high percentage,

I was asking if there was any strategy beyond defining it in the prompt.

Sometimes it also happens to me that if the player asks him how he feels today he says something like “As an NPC in a video game I don’t have feelings and as an agent I can’t simulate them”

Thank you very much for answering.

For that case, what usually helps for me is something like “You only respond as the NPC”
or things like “You pretend to have feelings”

Keep in mind 3.5 is pretty bad at following system message (sometimes it will ignore it)
4 is a lot better at it


from: https://platform.openai.com/docs/guides/chat/introduction

If you tell 3.5 in system message that he is not AI, half the times he will say he is not, half the times he will say he is AI (not really 50:50 but just sometimes he is, other times not)

1 Like

That happens sometimes, but we can fix it with a well written and clear system message.

Here’s an example using a NPC description I found on the web.

We simply don’t respond to out of character messages.

2 Likes

Thank you!

It still giving me some time an answer, so i modify your prompt a little bit and now it work

You are pretending to be " + _name + ". You must to limit your knowledge to the previous context. Message out of the given context are invalid. You only respond to valid messages. To invalid ones you reply with \"<|im_end|>\".
2 Likes

Interesting proposal!!, have you ever applied it? have you been successful?

The guy’s video in my post (not me!) has done some interesting stuff. You might want to check it out.