agentic-rag
БесплатноБез исполняемых скриптовНе проверенAgent-driven RAG patterns. Self-RAG, Corrective RAG (CRAG) with web fallback, Adaptive RAG with routing classifier, ReAct with retrieval tool, multi-hop…
от claude-dev-suite★ 51 звезда на GitHubОб этом скилле
Agentic RAG
When to Go Agentic
| Signal | Static RAG | Agentic RAG |
|---|---|---|
| Known single-hop questions | Yes | No |
| Unknown retrieval depth | No | Yes |
| Multi-source (docs + web + DB) | No | Yes |
| Need to detect retrieval failure and recover | No | Yes |
| Latency budget < 2s | Yes | No |
| Audit trail / explainability | Harder | Natural |
Agentic adds latency and cost; use when static cannot recover from retrieval failure or needs multiple steps.
ReAct with Retrieval Tool
from langchain_core.tools import tool
from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import create_react_agent
@tool
def search_kb(query: str) -> str:
"""Search the internal knowledge base. Returns top passages."""
docs = retriever.invoke(query)
return "\n\n".join(f"[{d.metadata['id']}] {d.page_content}" for d in docs[:5])
@tool
def search_web(query: str) -> str:
"""Search the open web. Use for recent events or things not in the KB."""
return tavily_client.search(query, max_results=5)
llm = ChatAnthropic(model="claude-sonnet-4-5-20250929")
agent = create_react_agent(llm, tools=[search_kb, search_web])
result = agent.invoke({"messages": [("human", "What changed in our refund policy since the 2024 update?")]})
Agent decides when and what to search; handles multi-hop automatically via tool-loop.
Self-RAG (self-reflection tokens)
Generate, self-critique retrieval, critique answer, regenerate if needed.
from typing import Literal
from pydantic import BaseModel, Field
class RetrievalDecision(BaseModel):
needs_retrieval: Literal["yes", "no"]
reason: str
class Grade(BaseModel):
score: Literal["relevant", "irrelevant"]
reason: str
class Support(BaseModel):
support: Literal["fully_supported", "partially_supported", "not_supported"]
reason: str
decider = llm.with_structured_output(RetrievalDecision)
grader = llm.with_structured_output(Grade)
supporter = llm.with_structured_output(Support)
def self_rag(question: str, max_retries: int = 2):
decision = decider.invoke(f"Does answering '{question}' require retrieval from the KB?")
if decision.needs_retrieval == "no":
return llm.invoke(question).content
for attempt in range(max_retries + 1):
docs = retriever.invoke(question)
relevant = [d for d in docs
if grader.invoke(f"Q: {question}\nPassage: {d.page_content}").score == "relevant"]
if not relevant and attempt < max_retries:
question = rewrite(question) # query rewrite
continue
answer = generate_answer(question, relevant)
sup = supporter.invoke(f"Answer: {answer}\nContext: {[d.page_content for d in relevant]}")
if sup.support == "fully_supported":
return answer
if attempt == max_retries:
return answer + "\n\n(Partial support only.)"
return "I could not find enough information."
Paper: Asai et al., 2023. The structured critics are the core contribution.
Corrective RAG (CRAG)
Grade retrieval confidence; on low confidence, rewrite the query and fall back to web search.
from langgraph.graph import StateGraph, END
from typing import TypedDict
class CRAGState(TypedDict):
question: str
docs: list
web_docs: list
grade: str
answer: str
def retrieve_node(s: CRAGState) -> CRAGState:
s["docs"] = retriever.invoke(s["question"])
return s
def grade_node(s: CRAGState) -> CRAGState:
grades = [grader.invoke(f"Q:{s['question']}\nPassage:{d.page_content}").score for d in s["docs"]]
relevant = sum(1 for g in grades if g == "relevant")
if relevant >= 2:
s["grade"] = "correct"
elif relevant >= 1:
s["grade"] = "ambiguous"
else:
s["grade"] = "incorrect"
s["docs"] = [d for d, g in zip(s["docs"], grades) if g == "relevant"]
return s
def web_fallback_node(s: CRAGState) -> CRAGState:
rewritten = rewrite(s["question"])
s["web_docs"] = tavily_client.search(rewritten, max_results=5)
return s
def generate_node(s: CRAGState) -> CRAGState:
ctx = s["docs"] + s.get("web_docs", [])
s["answer"] = generate_answer(s["question"], ctx)
return s
def route_after_grade(s: CRAGState) -> str:
return "generate" if s["grade"] == "correct" else "web_fallback"
g = StateGraph(CRAGState)
g.add_node("retrieve", retrieve_node)
g.add_node("grade", grade_node)
g.add_node("web_fallback", web_fallback_node)
g.add_node("generate", generate_node)
g.set_entry_point("retrieve")
g.add_edge("retrieve", "grade")
g.add_conditional_edges("grade", route_after_grade,
{"generate": "generate", "web_fallback": "web_fallback"})
g.add_edge("web_fallback", "generate")
g.add_edge("generate", END)
crag = g.compile()
result = crag.invoke({"question": "What is our refund window for enterprise contracts?"})
Web search is the correction leg; works when the KB is narrower than user demand.
Установить agentic-rag в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobWriteEditFAQ
Что делает скилл agentic-rag?
Agent-driven RAG patterns. Self-RAG, Corrective RAG (CRAG) with web fallback, Adaptive RAG with routing classifier, ReAct with retrieval tool, multi-hop retrieval, plan-and-execute, LangGraph state machines for RAG. USE WHEN: user mentions "agentic RAG", "Self-RAG", "Corrective RAG", "CRAG", "Adaptive RAG", "multi-hop retrieval", "LangGraph RAG", "ReAct RAG", "plan and execute RAG" DO NOT USE FOR: static retrieval pipelines - use `rag-architecture`; query rewriting only - use `query-transformations`; evaluation - use `rag-evaluation`
Как установить скилл agentic-rag?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл agentic-rag запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic