Skip to content

Commit 40b92fc

Browse files
Add agentic RAG with authorization example (#44)
1 parent 333583d commit 40b92fc

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

agentic-rag-authorization/README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ definition document {
194194

195195
### 2. State Flow
196196

197-
**Default Mode**
197+
**Default Mode (`max_attempts=1`)**
198198
```
199199
User Query
200200
@@ -205,6 +205,40 @@ Authorization Node ← SpiceDB filters (SECURITY BOUNDARY - cannot be bypassed)
205205
Generation Node ← Answer with authorized context + explanations
206206
```
207207

208+
**Adaptive Mode (`max_attempts > 1`)**
209+
210+
When `max_attempts` is set above 1, a reasoning node activates if authorization fails. The LLM analyzes why access was denied and decides whether a different retrieval strategy might find documents the user *can* access:
211+
212+
```
213+
User Query
214+
215+
Retrieval Node
216+
217+
Authorization Node ← still deterministic, still non-bypassable
218+
219+
some docs authorized? → Yes → Generation Node
220+
↓ No
221+
Reasoning Node ← LLM decides: retry with different query, or give up?
222+
223+
attempts left? → Yes → Retrieval Node (loop)
224+
↓ No
225+
Generation Node ← explains the denial
226+
```
227+
228+
For example, if Bob (sales) asks about "microservices architecture" and the first retrieval returns only engineering-only docs, the reasoning node might try a broader query that surfaces a shared architecture doc Bob can actually access.
229+
230+
Enable it by setting `MAX_RETRIEVAL_ATTEMPTS` in `.env` (or passing `max_attempts` directly):
231+
232+
```bash
233+
MAX_RETRIEVAL_ATTEMPTS=3 # default is 1
234+
```
235+
236+
Or in code:
237+
238+
```python
239+
result = run_agentic_rag(query="...", subject_id="bob", max_attempts=3)
240+
```
241+
208242
### 3. Security Guarantees
209243

210244
- **Authorization always runs**: Hardcoded in LangGraph workflow, agent cannot skip

0 commit comments

Comments
 (0)