feat(persona-chat): continue an SMS thread with a persona

Persona conversations can now be anchored on a message in an SMS thread.
Creating one snapshots the thread up to that message (via SMS-API) into the
row; every turn appends it to the persona prompt with guidance to talk like a
text thread rather than write an insight.

Anchored turns get four tools: get_thread_messages (page the thread),
look_at_message_image (local vision on an MMS photo), get_photos_near_time
(library photos with tags and people) and look_at_photo (local vision on a
library photo). The conversation list filters by contact_id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cameron CordesandClaude Opus 5.5 committed 2026-10-17 18:07:49 -04:00
1 parent fdbcc75391
commit 4ac574d4d2
11 files changed
+1389 -40

No files matched your search

@@ -0,0 +1,6 @@
DROP INDEX IF EXISTS idx_persona_chat_anchor_contact;
ALTER TABLE persona_chat_conversations DROP COLUMN anchor_context;
ALTER TABLE persona_chat_conversations DROP COLUMN anchor_ts;
ALTER TABLE persona_chat_conversations DROP COLUMN anchor_message_id;
ALTER TABLE persona_chat_conversations DROP COLUMN anchor_contact_name;
ALTER TABLE persona_chat_conversations DROP COLUMN anchor_contact_id;
@@ -0,0 +1,23 @@
-- Anchor a persona conversation on a point in an SMS thread.
--
-- "Continue with persona" starts a persona chat from a long-pressed message
-- in the Messages screen. The conversation remembers which thread and which
-- message it grew out of, so the SMS screen can list the persona chats that
-- belong to a thread and the chat screen can show where it picked up.
--
-- `anchor_context` is a snapshot of the thread leading up to the anchor,
-- rendered once at creation and spliced into the system prompt on every
-- turn. Snapshotting (rather than refetching per turn) keeps the prompt
-- prefix byte-stable for KV-cache reuse and keeps the persona's view of the
-- thread fixed even if SMS-API is re-imported underneath it.
--
-- All nullable: an unanchored (open) persona chat leaves them NULL.
ALTER TABLE persona_chat_conversations ADD COLUMN anchor_contact_id BIGINT;
ALTER TABLE persona_chat_conversations ADD COLUMN anchor_contact_name TEXT;
ALTER TABLE persona_chat_conversations ADD COLUMN anchor_message_id BIGINT;
ALTER TABLE persona_chat_conversations ADD COLUMN anchor_ts BIGINT;
ALTER TABLE persona_chat_conversations ADD COLUMN anchor_context TEXT;
CREATE INDEX idx_persona_chat_anchor_contact
ON persona_chat_conversations (user_id, anchor_contact_id, updated_at DESC);