Skip to main content

Agentic RAG

Agentic execution is intentionally separate from RAGPipeline. An AgenticPipeline asks an agent for one decision at a time, executes selected tools, records observations, and stops after an explicit step budget.

Basic Ollama pipeline

The default LLMPlannerAgent requests strict JSON decisions from the injected LLM. A small local model may need a stronger instruction-following replacement if it cannot reliably produce valid decisions.

Built-in retrieval tool

Every agentic pipeline registers retrieve. The tool accepts a query and an optional top_k, uses the injected vector store, applies the optional reranker, and adds returned documents to RAGResponse.sources. The retrieve name is reserved and cannot be replaced by an application tool.

Add a Python tool

Handlers can return a string or ToolResult, synchronously or asynchronously. Tool exceptions become failed observations so the agent can recover on its next decision.

Inject a custom agent

Custom agents implement one structural method and require no inheritance:
Pass agent=RetrievalFirstAgent() to AgenticPipeline.

Asynchronous tools

Use the async entry point when an agent or tool performs asynchronous work:
Calling synchronous generate() inside an active event loop raises an actionable error rather than nesting event loops.

MCP tools

Install the MCP extra and adapt a tool from a caller-managed connected client:
RAGLight does not own the MCP connection lifecycle, authentication, or server process. Keep the official MCP client connected while awaiting pipeline.agenerate().

Step exhaustion

Each decision consumes one step. If no final answer is returned within max_steps, AgentStepLimitError exposes the trace ID, step budget, and completed events.

Agentic sessions

Agentic sessions isolate history exactly like classic sessions. Failed turns are not committed.

Native tracing

Pass tracer=LangfuseTracer() to record the root agent execution, decisions, and tool calls. See Langfuse observability.