refactor: tool-based RAG pipeline replacing fixed HyDE/inject pipeline - #204
Merged
Merged
Conversation
nerualauren
pushed a commit
to nerualauren/stampy-ui
that referenced
this pull request
Apr 2, 2026
Update chat UI to support the new tool-based RAG pipeline from stampy-chat (StampyAI/stampy-chat#204). - Block-based rendering: thinking, tool_use+tool_result (merged), text - Turn-based SSE protocol: handle 'turn' events with tool results - Citations extracted from tool_result ui_output blocks - Cross-turn citation reference resolution via priorCitations - Markdown rendering with react-markdown, KaTeX math support - Memoized CitationMarkdown component (avoids recreating component types per render causing unmount/remount flicker) - Tool calls displayed with friendly names in collapsible details - Model list updated to dateless Anthropic IDs (claude-sonnet-4-6 etc.) - CHATBOT_URL: production default with localhost auto-detection for dev - Payload size limit raised to 200KB for block-structured history
7 tasks
nerualauren
pushed a commit
to nerualauren/stampy-ui
that referenced
this pull request
Apr 2, 2026
Update chat UI to support the new tool-based RAG pipeline from stampy-chat (StampyAI/stampy-chat#204). - Block-based rendering: thinking, tool_use+tool_result (merged), text - Turn-based SSE protocol: handle 'turn' events with tool results - Citations extracted from tool_result ui_output blocks - Cross-turn citation reference resolution via priorCitations - Markdown rendering with react-markdown, KaTeX math support - Memoized CitationMarkdown component (avoids recreating component types per render causing unmount/remount flicker) - Tool calls displayed with friendly names in collapsible details - Model list updated to dateless Anthropic IDs (claude-sonnet-4-6 etc.) - CHATBOT_URL: production default with localhost auto-detection for dev - Payload size limit raised to 200KB for block-structured history - Removed: useIsMobile/mobile prop (unused), DOMPurify (replaced by react-markdown's React-native rendering) - Kept upstream's useGlossaryInjection and glossary popup support
nerualauren
pushed a commit
to nerualauren/stampy-ui
that referenced
this pull request
Apr 2, 2026
Update chat UI to support the new tool-based RAG pipeline from stampy-chat (StampyAI/stampy-chat#204). - Block-based rendering: thinking, tool_use+tool_result (merged), text - Turn-based SSE protocol: handle 'turn' events with tool results - Citations extracted from tool_result ui_output blocks - Cross-turn citation reference resolution via priorCitations - Markdown rendering with react-markdown, KaTeX math support - Memoized CitationMarkdown component (avoids recreating component types per render causing unmount/remount flicker) - Tool calls displayed with friendly names in collapsible details - Parallel tool_use blocks matched to tool_results by id (not adjacency) - Model list updated to dateless Anthropic IDs (claude-sonnet-4-6 etc.) - CHATBOT_URL: production default with localhost auto-detection for dev - Payload size limit raised to 200KB for block-structured history - Glossary injection skips pre and details elements (prevents corrupting tool result XML display) - Removed: useIsMobile/mobile prop (unused), DOMPurify (replaced by react-markdown's React-native rendering) - Kept upstream's useGlossaryInjection and glossary popup support
Replace the fixed retrieval pipeline (HyDE query -> Pinecone search -> inject docs into prompt -> single LLM call) with dynamic tool-calling via Anthropic's streaming tool runner. Claude now decides when and what to search, can refine queries, look up full articles, and browse by metadata. Design spec: docs/superpowers/specs/2026-03-30-tool-based-rag-design.md Backend: - New tools.py: shared tool definitions returning (model_output, ui_output) tuples, used by both MCP server and chat pipeline - chat.py rewritten as a generator yielding SSE events directly, replacing the callback/Queue/Thread pattern - Removed: llms.py (multi-provider LLM abstraction), callbacks.py, HyDE generation, fixed doc injection - mcp_server.py becomes thin wrappers around tools.py - Monotonic citation IDs across tool calls and conversation turns - Error events yielded on exception instead of silent stream termination - Tool names logged in interaction records Frontend (both web/ and stampy-ui/): - Block-based rendering: thinking, tool_use+tool_result, text blocks - Turn-based SSE protocol replacing phase-based loading states - Citations extracted from tool result ui_output - Cross-turn citation reference resolution via priorCitations - Markdown rendering with KaTeX math support (stampy-ui) - Tool calls displayed with friendly names in collapsible details Settings: - Anthropic-only model list (dateless IDs: claude-sonnet-4-6, etc.) - Default model: claude-sonnet-4-6 - max_response_tokens includes thinking budget only for thinking models - Removed: enable_hyde, hyde_max_tokens, multi-provider settings Review fixes: - XML attribute escaping in format_block (quoteattr) - Error SSE events on exception in run_query - React perf: memoized CitationMarkdown component (was recreating component types on every render via withCitationProcessing) - Token counting includes model_output in tool_result blocks - Chat tool get_doc capped at 2KB (MCP keeps 130KB default) - _search copies blocks instead of mutating in place - Restored production CHATBOT_URL (localhost auto-detected for dev) - Cleaned up: dead search_followups, accidental screenshot, callbacks.py
LeMurphant
self-requested a review
April 3, 2026 12:19
LeMurphant
approved these changes
Apr 3, 2026
nerualauren
pushed a commit
to StampyAI/stampy-ui
that referenced
this pull request
Apr 4, 2026
Update chat UI to support the new tool-based RAG pipeline from stampy-chat (StampyAI/stampy-chat#204). - Block-based rendering: thinking, tool_use+tool_result (merged), text - Turn-based SSE protocol: handle 'turn' events with tool results - Citations extracted from tool_result ui_output blocks - Cross-turn citation reference resolution via priorCitations - Markdown rendering with react-markdown, KaTeX math support - Memoized CitationMarkdown component (avoids recreating component types per render causing unmount/remount flicker) - Tool calls displayed with friendly names in collapsible details - Parallel tool_use blocks matched to tool_results by id (not adjacency) - Model list updated to dateless Anthropic IDs (claude-sonnet-4-6 etc.) - CHATBOT_URL: production default with localhost auto-detection for dev - Payload size limit raised to 200KB for block-structured history - Glossary injection skips pre and details elements (prevents corrupting tool result XML display) - Removed: useIsMobile/mobile prop (unused), DOMPurify (replaced by react-markdown's React-native rendering) - Kept upstream's useGlossaryInjection and glossary popup support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the fixed retrieval pipeline (HyDE -> Pinecone -> inject docs -> single LLM call) with dynamic tool-calling via Anthropic's streaming tool runner. Claude now decides when and what to search, can refine queries, look up full articles, and browse by metadata.
tools.pyextracts shared tool definitions frommcp_server.py, returning(model_output, ui_output)tuples.chat.pyrewritten as a generator yielding SSE events via the Anthropic streaming tool runner, replacing the callback/Queue/Thread pattern. Removedllms.py,callbacks.py, HyDE, fixed doc injection.web/andstampy-ui/): block-based rendering (thinking, tool_use+tool_result, text), turn-based SSE protocol, citations extracted from tool results, cross-turn citation reference resolution, markdown+KaTeX support.claude-sonnet-4-6default),max_response_tokensonly includes thinking budget for thinking-capable models.Design spec:
docs/superpowers/specs/2026-03-30-tool-based-rag-design.mdReview fixes included
format_block(quoteattr)CitationMarkdown(was recreating component types every render)model_outputin tool_result blocksget_doccapped at 2KB (MCP keeps 130KB)_searchcopies blocks instead of mutating in placeCHATBOT_URLwith localhost auto-detection for devsearch_followups,callbacks.py, accidental screenshotKnown follow-ups
web/andstampy-ui/SSE handlingfindCitationscalled per streaming delta (perf at scale)ui_outputbloat in history payloads_schema_from_fndoesn't handlelist[T]items or complex typesTest plan
cd api && pipenv run pytestpasses (verified)mprocsstarts API + web, chat works with tool calls visible🤖 Generated with Claude Code