From d0bbd8aeea139ca4bf4ed37020c71c60a65f0a95 Mon Sep 17 00:00:00 2001 From: batsumaru <> Date: Fri, 11 Sep 2026 17:39:50 +0900 Subject: Added weather, file system, and memory --- context.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'context.py') diff --git a/context.py b/context.py index 4a65f57..d702706 100644 --- a/context.py +++ b/context.py @@ -1,4 +1,5 @@ from identity import AgentIdentity, UserProfile +from memory import WorkingMemory class ContextBuilder: @@ -10,7 +11,10 @@ class ContextBuilder: self.agent_identity = agent_identity self.user_profile = user_profile - def build_system_prompt(self) -> str: + def build_system_prompt( + self, + memory: WorkingMemory, + ) -> str: agent = self.agent_identity user = self.user_profile @@ -22,4 +26,38 @@ class ContextBuilder: f"Favorite color: {agent.quirks['favorite_color']}.\n" f"\n" f"The user's name is {user.name}" + f"\n" + f"{self.build_working_memory(memory)}" ) + + def build_working_memory(self, memory: WorkingMemory) -> str: + lines = ["Current working memory:"] + + if memory.objective: + lines.append(f"Objective: {memory.objective}") + + if memory.facts: + lines.append("Facts:") + lines.extend(f"- {fact}" for fact in memory.facts) + + if memory.notes: + lines.append("Notes:") + lines.extend(f"- {note}" for note in memory.notes) + + if len(lines) == 1: + lines.append("(empty)") + + return "\n".join(lines) + + def build_messages( + self, + history: list[dict[str, object]], + memory: WorkingMemory, + ) -> list[dict[str, object]]: + return [ + { + "role": "system", + "content": self.build_system_prompt(memory), + }, + *history, + ] -- cgit v1.3