From 5f2df4341e1a71f7e0adfefb10c17c227d50153c Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Sun, 3 May 2026 08:27:35 -0700 Subject: [PATCH] If an NPC calls to AI to talk... And no one is around to listen, are we just wasting tokens? Yup. --- typeclasses/chatbots.py | 11 ++++++----- typeclasses/objects.py | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/typeclasses/chatbots.py b/typeclasses/chatbots.py index 79c0beb..b8e45af 100755 --- a/typeclasses/chatbots.py +++ b/typeclasses/chatbots.py @@ -436,16 +436,17 @@ class Dragon(Traveler): "say Look at all these luscious peoples.", "emote waves to everyone.", "emote waves to everybody." - ]) + ] delay(5, self.do_cmd, cmd) def goodbye(self, new_room=None): if self.location.key == "Wyldwood Bar": self.do_cmd("drop drink") - system_prompt = self.setting_and_backstory() - messages = [{"role": "user", "content": "Say goodbye."}] - reply = self._think(system_prompt, messages) - self.process_thoughts(reply) + if self.location.characters_here(): + system_prompt = self.setting_and_backstory() + messages = [{"role": "user", "content": "Say goodbye."}] + reply = self._think(system_prompt, messages) + self.process_thoughts(reply) class TravelingNPC(Script): diff --git a/typeclasses/objects.py b/typeclasses/objects.py index 729e8eb..447ff2a 100755 --- a/typeclasses/objects.py +++ b/typeclasses/objects.py @@ -846,18 +846,19 @@ class AI: and 'messages' from the JSON history function, appended with all 'events' recorded since last time. """ - system_prompt = self.setting_and_backstory(speaker) - messages = self.history(speaker) - recent_events = self.pop_recent_events(speech) - if recent_events: - speech = f"{recent_events}\n\n{speaker.key}: {speech}" - messages.append({"role": "user", "content": speech}) + if self.location.characters_here(): + system_prompt = self.setting_and_backstory(speaker) + messages = self.history(speaker) + recent_events = self.pop_recent_events(speech) + if recent_events: + speech = f"{recent_events}\n\n{speaker.key}: {speech}" + messages.append({"role": "user", "content": speech}) - # logger.info(f"Deep Thoughts: {system_prompt} / {messages}") - reply = self._think(system_prompt, messages) + # logger.info(f"Deep Thoughts: {system_prompt} / {messages}") + reply = self._think(system_prompt, messages) - self.update_history(speaker, messages, reply) - return reply + self.update_history(speaker, messages, reply) + return reply def process_thoughts(self, response): paragraphs = response.split('\n\n')