feat: reminders and scheduled tasks (schedule tool, app store and delivery)
The brain gets a schedule tool (add, list, delete the asker's own reminders, timers and tasks) offered only with a schedule backend. The voice worker asks the app through schedule_action and runs fired tasks as reply via task with read-only tools, no MCP and a fresh short-term memory. The app keeps the schedules in config/schedules.json, fires them every 5 s, speaks them when the person is in Jarvis's voice channel and otherwise posts in the chat channel they asked in (or schedule.chatChannel for voice). A feature switch and a 예약 screen list and delete everyone's schedules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,10 +17,13 @@ from jarvis.memory.history import HistoryContext, Scope
|
||||
|
||||
|
||||
class Brain(Protocol):
|
||||
def reply(self, user: str, text: str, history: HistoryContext, chat=None) -> Optional[str]:
|
||||
def reply(self, user: str, text: str, history: HistoryContext, chat=None, schedule=None,
|
||||
task: bool = False) -> Optional[str]:
|
||||
"""Blocking; called on a worker thread, one call per person at a time (a voice and a chat
|
||||
reply for different people may overlap). ``chat``: the chat backend for
|
||||
the chatChannels tool (voice_worker/chat_bridge.py), or None without registered channels."""
|
||||
the chatChannels tool (voice_worker/chat_bridge.py), or None without registered channels.
|
||||
``schedule``: the schedule backend for the schedule tool (voice_worker/schedule_bridge.py).
|
||||
``task``: a scheduled task runs, with the read-only tools only (``TASK_TOOLS``)."""
|
||||
|
||||
def addressed(self, user: str, text: str, names: list[str]) -> Optional[bool]:
|
||||
"""Blocking: was ``text`` said to the assistant (called ``names``)? None when it could not tell.
|
||||
@@ -150,6 +153,9 @@ MCP_ENV_VAR = "JARVIS_MCP_ENV"
|
||||
# voice channel or a registered chat channel asks, so they are never offered (M7 brings screen
|
||||
# viewing with its own permissions).
|
||||
V2_HOST_TOOLS = ("localFiles", "screenshot")
|
||||
# The only tools a scheduled task may use: it runs with nobody there to ask, so it only looks
|
||||
# things up (schedule.spec.md, "Tasks"). No MCP tools either: what they do is not known.
|
||||
TASK_TOOLS = ("getWeather", "webSearch", "fetchWebPage", "fetchMeals", "toolSearchTool")
|
||||
|
||||
|
||||
def take_mcp_env() -> dict:
|
||||
@@ -261,7 +267,7 @@ class JarvisBrain:
|
||||
self._prepared[user] = p
|
||||
t0 = time.perf_counter()
|
||||
try:
|
||||
p.tools = Muted.run(prepare_intent, self.cfg, text, mem, chat)
|
||||
p.tools = Muted.run(prepare_intent, self.cfg, text, mem, chat, schedule_available=True)
|
||||
finally:
|
||||
p.done.set()
|
||||
debug_log(f"brain prepare user={user} picked={p.tools is not None} "
|
||||
@@ -277,21 +283,34 @@ class JarvisBrain:
|
||||
return None
|
||||
return p.tools
|
||||
|
||||
def reply(self, user: str, text: str, history: HistoryContext, chat=None) -> Optional[str]:
|
||||
def _task_cfg(self):
|
||||
from jarvis.tools.registry import BUILTIN_TOOLS
|
||||
|
||||
off = (*self.cfg.disabled_tools, *(t for t in BUILTIN_TOOLS if t not in TASK_TOOLS))
|
||||
return dataclasses.replace(self.cfg, disabled_tools=tuple(dict.fromkeys(off)), mcps={})
|
||||
|
||||
def reply(self, user: str, text: str, history: HistoryContext, chat=None, schedule=None,
|
||||
task: bool = False) -> Optional[str]:
|
||||
from jarvis.memory.conversation import DialogueMemory
|
||||
from jarvis.reply import turn_state
|
||||
from jarvis.reply.engine import run_reply_engine
|
||||
|
||||
t0 = time.perf_counter()
|
||||
prepared = self._prepared_tools(user, text)
|
||||
# A task has its own short-term memory: it is not a turn of the person's conversation.
|
||||
prepared = None if task else self._prepared_tools(user, text)
|
||||
cfg = self._task_cfg() if task else self.cfg
|
||||
memory = DialogueMemory(inactivity_timeout=self.cfg.dialogue_memory_timeout, max_interactions=20) \
|
||||
if task else self._memory(user)
|
||||
# legacy_memory=False: v1's profile, diary and graph belong to one user; several people
|
||||
# share this assistant, so only the asker's scoped history may reach the prompt.
|
||||
def turn():
|
||||
# Tools with personal data (meals) read the asker from the turn state.
|
||||
turn_state.reset()
|
||||
turn_state.set_user(user)
|
||||
turn_state.set_chat(chat)
|
||||
turn_state.set_chat(None if task else chat)
|
||||
turn_state.set_schedule(None if task else schedule)
|
||||
try:
|
||||
return run_reply_engine(self.db, self.cfg, None, text, self._memory(user),
|
||||
return run_reply_engine(self.db, cfg, None, text, memory,
|
||||
language=self.language, history=history, legacy_memory=False,
|
||||
default_language=self.reply_language, compact_prompt=True,
|
||||
intent_judge=True, prepared_tools=prepared)
|
||||
@@ -299,7 +318,7 @@ class JarvisBrain:
|
||||
turn_state.reset()
|
||||
|
||||
answer = Muted.run(turn)
|
||||
debug_log(f"brain reply user={user} ok={bool(answer)} prepared={prepared is not None} "
|
||||
debug_log(f"brain reply user={user} ok={bool(answer)} task={task} prepared={prepared is not None} "
|
||||
f"ms={(time.perf_counter() - t0) * 1000:.0f}", "llm")
|
||||
return answer
|
||||
|
||||
|
||||
Reference in New Issue
Block a user