feat(article-discuss): unify /news + briefing entry points, persist summaries to RAG

Both the /news discuss button and the briefing discuss button now call a
shared seed_article_discussion() helper that stages the synthetic
read_article tool exchange and the conversational seed prompt — behavior
stays byte-identical across entry points. /news also auto-starts
generation so the chat screen lands on an in-flight stream.

First assistant reply in a seeded article conversation is persisted as a
Note (tags: article-summary + article topics) and backlinked via
rss_items.discussion_note_id, so the knowledge base stops being amnesiac
about articles the user has engaged with.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-14 07:54:24 -04:00
parent 9157740069
commit ba90ad8132
8 changed files with 284 additions and 78 deletions
+7 -46
View File
@@ -532,54 +532,15 @@ async def discuss_article(item_id: int):
if get_buffer(conv_id) is not None:
return jsonify({"error": "Generation already in progress"}), 409
# Three-layer cache: context_prepared (post-map-reduce) → content_full
# (raw trafilatura) → fresh fetch. Only the first miss pays the fetch
# cost; only a large uncached article pays the map-reduce cost. Repeat
# clicks on the same article skip straight to the chat turn.
from fabledassistant.services.article_context import prepare_article_context
from fabledassistant.services.rss import get_or_fetch_full_article
# Shared helper handles the three-layer cache (context_prepared
# content_full → fresh fetch), writes the synthetic read_article tool
# exchange and the conversational seed user prompt into the conversation.
# The /news from-article route calls the same helper so behavior stays
# byte-identical across entry points.
from fabledassistant.services.article_context import seed_article_discussion
model = await get_setting(uid, "default_model", "") or ""
if item.context_prepared:
article_content = item.context_prepared
else:
raw_body = await get_or_fetch_full_article(item) or item.content or ""
article_content = await prepare_article_context(
item.title or "", item.url, raw_body, model,
)
if article_content:
async with async_session() as session:
fresh = await session.get(RssItem, item.id)
if fresh is not None:
fresh.context_prepared = article_content
await session.commit()
# Store synthetic assistant message with read_article tool result
synthetic_tool_calls = [{
"function": "read_article",
"arguments": {"url": item.url},
"result": {
"success": True,
"type": "article_content",
"url": item.url,
"content": article_content,
"truncated": False,
},
}]
await add_message(conv_id, "assistant", "", status="complete", tool_calls=synthetic_tool_calls)
# Conversational seed — invites a real discussion rather than asking for
# a one-shot summary. The model sees the article context in the tool
# result above and responds to this user turn as the start of an ongoing
# conversation the user will steer with follow-ups.
discuss_prompt = (
"I want to talk about this article. Start with a substantive summary "
"of what it's arguing and the key evidence it uses, then tell me what "
"stood out to you or seems worth pushing back on. I'll ask follow-ups "
"from there."
)
await add_message(conv_id, "user", discuss_prompt)
discuss_prompt = await seed_article_discussion(conv_id, item, model)
# Reload conversation with fresh messages to build history
conv = await get_conversation(uid, conv_id)