Skip to content
Deep Agents

RAG Pipeline with Deep Agents

Build a Retrieval-Augmented Generation pipeline that searches documents with vector embeddings and answers questions with citations — using Deep Agents.

RAGvector storeembeddingsdocuments

Working Code

Deep Agents
from deepagents import create_deep_agent
from langchain_core.tools import tool
@tool
def search_documents(query: str, top_k: int = 5) -> str:
"""Search uploaded documents for relevant content."""
results = vector_store.similarity_search(query, k=top_k)
return "\n\n".join(
f"[{i+1}] {r.metadata.get('source', 'unknown')}: {r.page_content}"
for i, r in enumerate(results)
)
agent = create_deep_agent(
model="anthropic:claude-sonnet-4-5-20250929",
tools=[search_documents],
system_prompt="You are a document Q&A assistant. Search documents before answering. Cite sources using [1], [2] format.",
)
result = agent.invoke({
"messages": [("user", "What does the refund policy say about digital products?")]
})
print(result["messages"][-1].content)

Step by Step

1

Install dependencies

Install Deep Agents and the required tools for this use case.

2

Define your tools

Create the domain-specific tool functions your agent will use to interact with external services.

3

Create the agent and run

Initialize the Deep Agents agent with your tools, set the system prompt, and execute a query.

Ready to build with Deep Agents?

Generate a production-ready project with Deep Agents pre-configured — FastAPI + Next.js, auth, streaming, and more.

Get Started

Ready to build your first production AI agent?

Open-source tools, battle-tested patterns, zero boilerplate. Configure your stack and ship in minutes — not months.