Agentic RAG Conversation Principles
This document explains how DB-GPT combines Agent + RAG to answer knowledge-base questions, from query to a cited final answer. Intended for product/design readers โ no code.
1. Agentic RAG vs Traditional RAGโ
Traditional RAG (single retrieval)
โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
โ Question โ โ โRetrieve โ โ โ Build โ โ โ LLM โ
โโโโโโโโโโโโ โ once โ โ Prompt โ โ Answer โ
โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
retrieval once stuff into ctx one-shot
Weakness: quality hinges on one similarity pass; can't iterate; no multi-step lookahead
Agentic RAG (multi-round) โ DB-GPT uses this
โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโ
โ Question โ โ โ ReAct Agent Loop โ โ โ Cited โ
โโโโโโโโโโโโ โ โโโโโโโโโโ โโโโโโโโโโ โโโโโโโโโโ โ โ Answer โ
โ โ Thoughtโโ โ Action โโ โObserve โ โ โโโโโโโโโโโโ
โ โโโโโโโโโโ โโโโโโโโโโ โโโโโโโโโโ โ
โ โ โ โ
โ โโโ not enough? โโโโโโโ โ
โ (multi-round, pick tools) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Strength: iterative retrieval, multiple tools, traceable citations
2. End-to-End Agent Conversation Flowโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ User: "What's the design philosophy of prompt caching?" โ
โโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 1: Agent Thought โ
โ "User asks about caching philosophy. Let me semantic-search the KB." โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 2: Pick Tool (Action) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Available tools (Knowledge-Agent mode, KB only):โ โ
โ โ โข kb_semantic_search โ โ
โ โ โข kb_grep / kb_cat โ โ
โ โ โข kb_ls / kb_glob โ โ
โ โ โข kb_codegraph_* โ โ
โ โ โข todowrite / terminate โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ Agent picks: kb_semantic_search(query="prompt cache design") โ
โโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 3: Execute + Observe โ
โ Tool returns 10 chunks with scores and source files โ
โ Observation: โ
โ Result 1 (0.67) [prompt cache.md] design-cost table... โ
โ Result 2 (0.66) [prompt cache.md] Hermes ephemeral injection... โ
โ ... โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 4: Agent Thought again โ
โ "Rich results but the comparison table is truncated โ read full file." โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 5: Pick Tool โ kb_cat(path="prompt cache.md") โ
โ โ Observation: full 315-line file โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 6: Collect Citations โ
โ Every tool-returned chunk goes into _cited_chunks โ
โ Dedup + strip HTML tags โ clean traceable fragments โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 7: Terminate & Generate Answer โ
โ Agent decides info is enough โ terminate(result="final answer") โ
โ โ
โ Backend post-processing: โ
โ 1. _auto_annotate_citations: insert [1][2] at citation spots โ
โ 2. _build_references_xml: append <references> payload โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Step 8: Frontend renders cited answer โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Pi rebuilds system prompt each turn[1] โ โ
โ โ Hermes freezes snapshot + ephemeral injection[2][6] โ โ
โ โ Claude-Code uses Beta Header[3] โ โ
โ โ โ โ
โ โ โ [1][2][3] are blue badges; hover shows the chunk โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
3. The ReAct Loop (core of the agent)โ
โโโโโโโโโโโโโโโโโโโ
โ User query โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Thought (LLM reasoning)โ โ analyze state, decide next step
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Action (tool + args) โ โ pick one from available tools
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Observation (tool ret) โ โ execute, get result
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โโโโโโโโโโดโโโโโโโโโ
โ โ
enough info? need more?
โ โ
โผ โ
โโโโโโโโโโโโ โ
โ Terminateโ โ
โ Answer โ โ
โโโโโโโโโโโโ โ
โ yes โ back to Thought (next round)
โ
(max N rounds to prevent loops)
Key: the agent doesn't blindly retrieve once โ it judges "is this enough?" from the observation; if not, it switches tools/queries and searches again.
4. Citation Traceability Pipelineโ
Tool exec Backend collect Frontend display
โโโโโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
kb_semantic_search -> _cited_chunks[0] = { -> [1] blue badge
Result 1: "Pi... " content: "Pi...", hover shows:
score: 0.67 recall_score: 0.67, "Pi... ยท recall 0.67"
}
kb_cat -> _cited_chunks[1] = { -> [2] blue badge
"Hermes freezes..." content: "Hermes...", hover shows:
recall_score: null, "Hermes..."
}
โ
Auto-annotate -> answer text: -> [1][2] inserted
_auto_annotate "Pi rebuilds[1]" after cited
_citations "Hermes freezes[2]" sentence
Ref panel -> <references> XML -> ๐ View References
_build_references_xml references='[{ click โ Drawer
name:"prompt cache.md", tabs per doc
chunks:[{index:1,...}, all chunks
{index:2,...}]
}]'
5. Tool Modes: Knowledge-Agent vs Full-Agentโ
KB detail-page chat (knowledge-agent) Generic agent chat (react-agent)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ KB tools only: โ โ All tools: โ
โ โข kb_semantic_search โ โ โข kb_* (knowledge) โ
โ โข kb_grep / kb_cat โ โ โข shell_interpreter โ
โ โข kb_ls / kb_glob โ โ โข sql_query โ
โ โข kb_codegraph_* โ โ โข html_interpreter โ
โ โข todowrite / terminateโ โ โข code_interpreter โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โข execute_skill_script โ
โ โ โข todowrite / terminate โ
focused on KB retrieval โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
no noise from irrelevant tools โ
ideal for pure KB Q&A capable, for complex tasks
but many tools โ easy to drift
6. Key Design Principlesโ
- Agent-driven retrieval: not one-shot; LLM decides whether to search again or switch tools based on observation
- Tools scoped to scene: pure KB chat gets only KB tools, preventing the agent from calling shell/sql
- Citations auto-collected: every tool-returned chunk enters
_cited_chunksโ doesn't rely on LLM compliance - Post-processing fallback: when the LLM ignores the "mark [1][2]" instruction, backend string-matches and inserts badges automatically
- Chunk content cleaning: HTML tags stripped before matching so clean LLM text aligns with chunk text
- References shipped with answer:
<references>XML appended to the answer; frontend parses it to render badges + panel - Closed-loop traceability: every badge โ chunk โ document โ viewable in the references panel