summaryrefslogtreecommitdiff
path: root/context.py
diff options
context:
space:
mode:
authorbatsumaru <>2026-09-11 17:39:50 +0900
committerbatsumaru <>2026-09-11 17:39:50 +0900
commitd0bbd8aeea139ca4bf4ed37020c71c60a65f0a95 (patch)
treea369d961de87df23359ad2e8931a04b5cbe6d40a /context.py
parentc90a0f8ae6ad5d6e07927cd0dc53b345a77494ae (diff)
Added weather, file system, and memory
Diffstat (limited to 'context.py')
-rw-r--r--context.py40
1 files changed, 39 insertions, 1 deletions
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,
+ ]