Function Signature
Purpose
Uses the LLM to determine if the question can be answered from general knowledge or if it requires searching the knowledge base. Questions about basic facts, math, or general knowledge can skip retrieval. Setsskip_retrieval: true on the context if retrieval can be skipped, which causes answer/2 to generate a response without context.
Parameters
The agent context from the pipeline
Options for the gate step
Options
Custom prompt function
fn question -> prompt_string endAllows you to customize how the LLM is asked to evaluate retrieval necessity.Override the LLM function for this stepTakes precedence over the LLM configured in context. Should accept a prompt string and return
{:ok, response} or {:error, reason}.Context Updates
Set to
true if retrieval can be skipped, false otherwiseThe LLM’s reasoning for the decision (if provided)
Examples
Basic Usage
With Custom Prompt
General Knowledge Question
Domain-Specific Question
Default Prompt
The default prompt used by the gate:Expected LLM Response
The LLM should respond with JSON:skip_retrieval: false (retrieval enabled) as a safe fallback.
Pipeline Behavior
Whenskip_retrieval: true:
- search/2 - Returns empty results immediately
- reason/2 - Skips multi-hop reasoning
- answer/2 - Generates answer without context
Telemetry Event
Emits[:arcana, :agent, :gate] with metadata:
When to Use
Usegate/2 when:
- Your system receives a mix of general and domain-specific questions
- You want to reduce unnecessary retrieval costs
- Questions like “What is 2+2?” or “Define recursion” don’t need your knowledge base
Performance Considerations
- Adds one LLM call to the pipeline
- Can save retrieval costs for general knowledge questions
- Most effective when ~30%+ of questions are general knowledge