feat(journal): LLM tools (record_moment, search_journal) + system prompt wiring

- services/tools/journal.py — record_moment + search_journal tool handlers
- services/tools/_registry.py: add `journal` flag on ToolDef + tool() decorator
- get_tools_for_user(user_id, conversation_type='chat'|'journal') —
  exclude journal-only tools from chat sessions; exclude set_rag_scope
  from journal sessions
- services/tools/__init__.py: register the new journal module; drop the
  unused get_briefing_tools export
- services/llm.py build_context: short-circuit for journal conversations,
  using journal_pipeline.build_journal_system_prompt and skipping all
  notes-RAG injection (preserves the journal/notes isolation invariant)
- services/generation_task.py: pass conversation_type into get_tools_for_user

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-25 22:39:42 -04:00
parent d9ab538ef4
commit ac188c40a5
5 changed files with 203 additions and 18 deletions
+28
View File
@@ -573,6 +573,34 @@ async def build_context(
"""
exclude_set = set(exclude_note_ids or [])
from datetime import date as date_type
# --- Journal short-circuit ---
# Journal conversations get a different persona, calibration, and an
# ambient-moments context block. CRUCIALLY, no notes-RAG injection here
# (preserves the notes/journal isolation invariant).
if conv_id is not None:
from fabledassistant.models import async_session as _async_session
from fabledassistant.models.conversation import Conversation as _Conversation
async with _async_session() as _sess:
_conv = await _sess.get(_Conversation, conv_id)
if _conv and getattr(_conv, "conversation_type", None) == "journal":
from fabledassistant.services.journal_pipeline import build_journal_system_prompt
day_date = _conv.day_date or date_type.today()
system_content = await build_journal_system_prompt(
user_id=user_id,
day_date=day_date,
user_timezone=user_timezone or "UTC",
)
messages_out: list[dict] = [{"role": "system", "content": system_content}]
messages_out.extend(history)
messages_out.append({"role": "user", "content": user_message})
return messages_out, {
"context_note_id": None,
"context_note_title": None,
"auto_notes": [],
"auto_injected_notes": [],
}
assistant_name = await get_setting(user_id, "assistant_name", "Fable")
today = date_type.today().isoformat()
has_caldav = await is_caldav_configured(user_id)