If an NPC calls to AI to talk...

And no one is around to listen, are we just wasting tokens?

Yup.
This commit is contained in:
Howard Abrams 2026-05-03 08:27:35 -07:00
parent 9e77eb87ad
commit 5f2df4341e
2 changed files with 17 additions and 15 deletions

View file

@ -436,16 +436,17 @@ class Dragon(Traveler):
"say Look at all these luscious peoples.", "say Look at all these luscious peoples.",
"emote waves to everyone.", "emote waves to everyone.",
"emote waves to everybody." "emote waves to everybody."
]) ]
delay(5, self.do_cmd, cmd) delay(5, self.do_cmd, cmd)
def goodbye(self, new_room=None): def goodbye(self, new_room=None):
if self.location.key == "Wyldwood Bar": if self.location.key == "Wyldwood Bar":
self.do_cmd("drop drink") self.do_cmd("drop drink")
system_prompt = self.setting_and_backstory() if self.location.characters_here():
messages = [{"role": "user", "content": "Say goodbye."}] system_prompt = self.setting_and_backstory()
reply = self._think(system_prompt, messages) messages = [{"role": "user", "content": "Say goodbye."}]
self.process_thoughts(reply) reply = self._think(system_prompt, messages)
self.process_thoughts(reply)
class TravelingNPC(Script): class TravelingNPC(Script):

View file

@ -846,18 +846,19 @@ class AI:
and 'messages' from the JSON history function, and 'messages' from the JSON history function,
appended with all 'events' recorded since last time. appended with all 'events' recorded since last time.
""" """
system_prompt = self.setting_and_backstory(speaker) if self.location.characters_here():
messages = self.history(speaker) system_prompt = self.setting_and_backstory(speaker)
recent_events = self.pop_recent_events(speech) messages = self.history(speaker)
if recent_events: recent_events = self.pop_recent_events(speech)
speech = f"{recent_events}\n\n{speaker.key}: {speech}" if recent_events:
messages.append({"role": "user", "content": speech}) speech = f"{recent_events}\n\n{speaker.key}: {speech}"
messages.append({"role": "user", "content": speech})
# logger.info(f"Deep Thoughts: {system_prompt} / {messages}") # logger.info(f"Deep Thoughts: {system_prompt} / {messages}")
reply = self._think(system_prompt, messages) reply = self._think(system_prompt, messages)
self.update_history(speaker, messages, reply) self.update_history(speaker, messages, reply)
return reply return reply
def process_thoughts(self, response): def process_thoughts(self, response):
paragraphs = response.split('\n\n') paragraphs = response.split('\n\n')