Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changes/552.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**Apps with memory off no longer learn your name from Sentient's personality.** Setup writes your name into the
personality, so an app could still ask for it while "Let connected apps use my memories" was off, and so could an
incognito chat without memory. Now those turns keep the personality with "the user" in place of your name. Your other
chats still use it.
6 changes: 4 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,8 @@ when `openai_api.allow_memory` is on too (below).
to an older message does not cover newer API input.
- **What the key reaches.** Chatting and Sentient's tools, with approvals as above. Memories stay out unless
`openai_api.allow_memory` is on (default off, #479): an API turn then gets no recalled memories, user-model
insights, notes or profile files in its prompt (only Sentient's persona, plus a note saying they aren't available),
insights, notes or profile files in its prompt (only Sentient's persona, with the user's configured name in it
written as "the user", #552, plus a note saying they aren't available),
and `memory_recall`, `memory_search_by_source`, `memory_search_history`, `history_semantic_search`,
`history_time_search`, `user_model_ask` and `memory_forget` are left out of its tools and refused if called anyway.
This is the turn's one memory decision (section 10, "Turns without memory"), so the same holds for every helper,
Expand Down Expand Up @@ -2805,7 +2806,8 @@ Every new tool declares a `Risk`; approvals behave as in section 1.
the memory tools (`memory_recall`, `memory_search_by_source`, `memory_search_history`, `history_semantic_search`,
`history_time_search`, `user_model_ask`, `memory_forget`) are not offered by `run_loop` whoever built the list,
are not listed to scripts, and refuse to run (`{error}`) however they are called. A helper's prompt then leaves out
the user's name too.
the user's name too, and so does the turn's own: SOUL.md stays, with the configured name written as "the user"
(#552).
- Limits: `subagents.max_rounds` steps (default 24), `subagents.timeout_minutes` (20), and on cloud models
`subagents.max_tokens` (1000000) and `subagents.max_cost_usd` (2.0, when the price is known; `0` = no limit). The
repeated-call breaker applies too. Reaching one ends the subagent with `status: "error"` and a plain `error`
Expand Down
9 changes: 6 additions & 3 deletions sentient/agent/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
from sentient.memory import scopes as memory_scopes
from sentient.memory.facts import FactMemory, keyword_tokens, new_details
from sentient.memory.sources import MemorySources
from sentient.memory.workspace import Workspace
from sentient.memory.workspace import Workspace, without_user
from sentient.services import cancel_tasks
from sentient.skills.loader import SkillLibrary
from sentient.store.db import Store, after_watermark, new_id, next_watermark, now_iso
Expand Down Expand Up @@ -794,8 +794,11 @@ async def _system_prompt_with_sources(
sources.add_facts(facts)
sources.add_insights(insights)
snapshot = self.workspace.snapshot()
if not reads_memory: # only the persona: no profile, memory file or daily notes
snapshot = {k: (v if k == "soul" else "") for k, v in snapshot.items()}
if not reads_memory: # only the persona, without the user's name (#552): no profile, memory file or daily notes
soul = without_user(
snapshot.get("soul") or "", self.config.assistant.user_name, self.config.assistant.name
)
snapshot = {k: (soul if k == "soul" else "") for k in snapshot}
elif not personal: # MEMORY.md, daily notes and USER.md's learned facts come from personal memories (#155)
snapshot = {
**snapshot, "memory": "", "today": "", "yesterday": "",
Expand Down
26 changes: 26 additions & 0 deletions sentient/memory/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from __future__ import annotations

import re
from collections.abc import Callable
from datetime import date, timedelta
from pathlib import Path
Expand Down Expand Up @@ -49,6 +50,31 @@
"""


def without_user(text: str, user_name: str, assistant_name: str = "") -> str:
"""SOUL.md for a turn without memory (#552): the persona stays and the user's name goes, as in a home with no name.

Setup and the personality presets write the name into it ("You are Sentient, Maya Rao's chief of staff"). A line
that is still as they wrote it is written again without the name, so nothing else in it changes. In any other line
(edited by hand) the full name and each part of it become "the user" in any case. That can also take an ordinary
word ("will" for someone called Will): a changed word is better than a name that gets out."""
from sentient.memory.personas import PERSONAS

words = user_name.split()
if not words:
return text
written = {}
for template in (DEFAULT_SOUL, *(p["soul_md"] for p in PERSONAS)):
for line in template.splitlines():
before = line.format(name=assistant_name, user=user_name.strip())
written[before] = line.format(name=assistant_name, user="the user")
parts = sorted({w for w in words if len(w) >= 2}, key=len, reverse=True)
names = [r"\s+".join(map(re.escape, words)), *map(re.escape, parts)]
name = re.compile(rf"(?<!\w)(?:{'|'.join(names)})(?!\w)", re.IGNORECASE)
return "\n".join(
written[line] if line in written else name.sub("the user", line) for line in text.split("\n")
)


class Workspace:
def __init__(self, root: Path | None = None, budget_chars: int = 6000):
self.root = root or paths.workspace_dir()
Expand Down
37 changes: 35 additions & 2 deletions tests/test_incognito.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,15 @@ def test_gateway_creates_lists_and_deletes_incognito_chats(client):
async def test_without_memory_the_prompt_has_no_personal_details(app):
app.config.chat.incognito_uses_memory = False
app.config.assistant.location = "Koramangala, Bengaluru"
app.config.assistant.user_name = "Maya Rao"
app.workspace.write("soul", "You are Sentient, Maya Rao's assistant.\nCall MAYA RAO by name, or just Maya.\n")
sid = await app.store.create_session(channel="desktop", incognito=True)
app.fake.replies.append("Hello.")
await _turn(app, sid, "hi there")
system = app.fake.calls[-1]["messages"][0]["content"]
# the configured name and place stay out (the persona the user wrote is kept as it is)
assert "Koramangala" not in system and "- User: Maya" not in system
# the configured name and place stay out, the user's name from SOUL.md too, and the rest of the persona stays (#552)
assert "Koramangala" not in system and "Maya" not in system and "MAYA" not in system
assert "You are Sentient, the user's assistant.\nCall the user by name, or just the user." in system


async def test_a_reply_still_writing_is_not_swept_and_deleting_cancels_helpers(app, monkeypatch):
Expand Down Expand Up @@ -341,3 +344,33 @@ async def test_leftover_incognito_output_folders_are_removed_at_start(app, isola
assert await app.incognito.remove_stray_outputs() == ["incognito-gone"]
assert (outputs / f"incognito-{live}").is_dir() and (outputs / "keep-me").is_dir()
assert not (outputs / "incognito-gone").exists()


@pytest.mark.parametrize(("soul", "name", "expected"), [
("You are Sentient, Maya Rao's assistant.", "Maya Rao", "You are Sentient, the user's assistant."),
("Greet maya rao warmly.", "Maya Rao", "Greet the user warmly."), # the full name in any case and spacing
("Will is busy.", "Will Smith", "the user is busy."), # a part of it
("Mayank is Maya's friend.", "Maya", "Mayank is the user's friend."), # whole words only
("Greet will warmly.", "Will", "Greet the user warmly."), # edited by hand: a name never gets out
("Greet maya warmly.", "Maya", "Greet the user warmly."), # any other name in any case
("Address maya by name.", "Maya Rao", "Address the user by name."), # and any part of it
("You are Sentient, the user's assistant.", "", "You are Sentient, the user's assistant."), # no name set
])
def test_without_user_takes_only_the_name_out_of_the_persona(soul, name, expected):
from sentient.memory.workspace import without_user

assert without_user(soul, name) == expected


@pytest.mark.parametrize(("assistant", "user"), [
("Sentient", "Maya Rao"),
("Sentient", "Will"), ("Sentient", "will"), ("Sentient", "Act"), # also a word in the personas
("Maya", "Maya Rao"), ("Maya", "Maya"), # the assistant shares the user's name
])
def test_without_user_changes_nothing_but_the_name_in_sentients_own_personas(assistant, user):
from sentient.memory.personas import PERSONAS
from sentient.memory.workspace import DEFAULT_SOUL, without_user

for template in (DEFAULT_SOUL, *(p["soul_md"] for p in PERSONAS)):
soul = template.format(name=assistant, user=user)
assert without_user(soul, user, assistant) == template.format(name=assistant, user="the user")
16 changes: 16 additions & 0 deletions tests/test_openai_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,22 @@ def test_connected_apps_get_memories_only_when_allowed(client, allow):
assert "memory_remember" in offered # facts from an API chat still go to Review either way


@pytest.mark.parametrize("allow", [False, True], ids=["memory-off", "memory-on"])
def test_the_name_from_onboarding_reaches_an_app_only_with_memory(client, allow):
"""Onboarding writes the user's name into SOUL.md through the persona. Off, an API turn keeps the persona and the
assistant's name but not the user's; on, it has the name like a desktop chat (#552)."""
core = client.app.state.sentient
core.config.openai_api.allow_memory = allow
named = {"user_name": "Maya Rao", "assistant_name": "Juno", "persona": "professional"}
assert client.post("/api/onboarding", json=named, headers=WIN).json() == {"ok": True}
assert "Maya Rao's chief of staff" in core.workspace.soul.read_text(encoding="utf-8")
assert _ask(client, user="Notes app", messages=[{"role": "user", "content": "What's my name?"}]).status_code == 200
system = client.llm.calls[-1]["messages"][0]["content"]
assert ("Maya" in system) is allow
persona = "You are Juno, " + ("Maya Rao's" if allow else "the user's") + " chief of staff"
assert persona in system # the persona and the assistant's name stay either way


def test_a_memory_tool_the_app_was_not_offered_is_refused(client):
"""Leaving the tools out is enforced: a call made anyway is refused and returns nothing (#479)."""
assert client.post("/api/memories", json={"content": SISTER}, headers=WIN).status_code == 200
Expand Down
Loading