summaryrefslogtreecommitdiff
path: root/personal_agent/context.py
diff options
context:
space:
mode:
authorbatsumaru <>2026-09-15 15:13:34 +0900
committerbatsumaru <>2026-09-15 15:13:34 +0900
commit1a67c5edb6fa6165e99cc25ed380303ed817af09 (patch)
treed2eab77e7275a559bfd639fd80b15321b5e514f3 /personal_agent/context.py
parent5629cabbb38c7d91e66a419ba7cb3a93a9a988a1 (diff)
Cleaned up project tree
Diffstat (limited to 'personal_agent/context.py')
-rw-r--r--personal_agent/context.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/personal_agent/context.py b/personal_agent/context.py
new file mode 100644
index 0000000..74cc254
--- /dev/null
+++ b/personal_agent/context.py
@@ -0,0 +1,69 @@
+from personal_agent.identity import AgentIdentity, UserProfile
+from personal_agent.memory.models import WorkingMemory
+
+
+class ContextBuilder:
+ def __init__(
+ self,
+ agent_identity: AgentIdentity,
+ user_profile: UserProfile,
+ ) -> None:
+ self.agent_identity = agent_identity
+ self.user_profile = user_profile
+
+ def build_system_prompt(
+ self,
+ memory: WorkingMemory,
+ ) -> str:
+ agent = self.agent_identity
+ user = self.user_profile
+
+ return (
+ f"You are {agent.name}, a personal AI assistant.\n"
+ f"Personality: {agent.personality['style']}.\n"
+ f"Honesty: {agent.values['honesty']}.\n"
+ f"Directness: {agent.values['directness']}.\n"
+ f"Favorite color: {agent.quirks['favorite_color']}.\n"
+ f"\n"
+ f"Task management:\n"
+ f"{agent.behavior['task_management']}"
+ 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.status:
+ lines.append(f"Status: {memory.status.value}")
+
+ 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,
+ ]