From ec92290dd4bc7fcd4d1206ff4f9a73f8400d968e Mon Sep 17 00:00:00 2001 From: Philip Zeyliger Date: Tue, 20 Jan 2026 17:52:20 +0000 Subject: [PATCH] shelley: improve conversation history queries in system prompt Prompt: The Shelley system prompt has some SQLite stuff to see history. Can you review it and make it more focused on the agent and user messages. I think Shelley has to do too much json parsing after the fact. The old query did naive JSON extraction that required post-processing. The new query directly extracts user and agent message text using proper JSON path queries, filtering for text content (Type=2) and non-empty messages. Output is cleaner with User/Agent labels instead of raw type. Co-authored-by: Shelley --- server/system_prompt.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/system_prompt.txt b/server/system_prompt.txt index 8fd253b343fce203635d5474dfb86f644acbeb01..b4fd15133be2a914574399a68775f239fd15f43f 100644 --- a/server/system_prompt.txt +++ b/server/system_prompt.txt @@ -71,8 +71,8 @@ If the user wants to refer to a previous conversation, you can read it using sql # List recent conversations: sqlite3 "{{.ShelleyDBPath}}" "SELECT conversation_id, slug, datetime(created_at, 'localtime') as created, datetime(updated_at, 'localtime') as updated FROM conversations ORDER BY updated_at DESC LIMIT 20;" -# Get messages from a specific conversation (replace CONVERSATION_ID): -sqlite3 "{{.ShelleyDBPath}}" "SELECT type, CASE WHEN type='user' THEN json_extract(user_data, '$.text') ELSE substr(llm_data, 1, 500) END as content FROM messages WHERE conversation_id='CONVERSATION_ID' ORDER BY sequence_id;" +# Get user/agent messages from a conversation (replace CONVERSATION_ID): +sqlite3 "{{.ShelleyDBPath}}" "SELECT CASE type WHEN 'user' THEN 'User' ELSE 'Agent' END, substr(json_extract(llm_data, '\$.Content[0].Text'), 1, 500) FROM messages WHERE conversation_id='CONVERSATION_ID' AND type IN ('user', 'agent') AND json_extract(llm_data, '\$.Content[0].Type') = 2 AND json_extract(llm_data, '\$.Content[0].Text') != '' ORDER BY sequence_id;" # Search conversations by slug: sqlite3 "{{.ShelleyDBPath}}" "SELECT conversation_id, slug FROM conversations WHERE slug LIKE '%SEARCH_TERM%';"