Skip to main content
Agent Search stage showing LLM reasoning loop with retriever stages as tools
The Agent Search stage uses an LLM reasoning loop to orchestrate other retriever stages as callable tools. Instead of executing a fixed sequence of stages, the LLM dynamically decides which stages to invoke, with what arguments, and how many iterations to perform based on the query and intermediate results.
Stage Category: FILTER (Adaptive retrieval)Transformation: Query → LLM reasoning (1-N iterations) → Refined documents

When to Use

Use CaseDescription
Multi-hop queriesQuestions requiring following references across documents
Iterative refinementBroad search followed by intelligent narrowing
Complex filtering logicWhen the right filter conditions depend on query semantics
Tree/hierarchy navigationNavigating hierarchical document indexes top-down
Exploratory searchWhen the best search strategy isn’t known upfront

When NOT to Use

ScenarioRecommended Alternative
Simple keyword or vector searchfeature_search
Known metadata filter conditionsattribute_filter
Fixed pipeline with known stagesChain stages directly
Latency-critical applications (< 1s)Direct stage execution
Cost-sensitive high-volume queriesPre-configured pipelines

Parameters

ParameterTypeDefaultDescription
strategystringiterative_refinementReasoning strategy (see Strategies below)
stageslist[string]from strategyWhich retriever stages the agent can invoke as tools
system_promptstringfrom strategyCustom system prompt for the LLM. Supports {{INPUT.*}} variables
max_iterationsinteger5Maximum reasoning iterations (1-20)
timeout_secondsfloat60.0Total timeout for the reasoning loop (5-300s)
providerstringautoLLM provider (openai, google, anthropic)
model_namestringautoSpecific model to use

Strategies

StrategyDefault ToolsBest For
iterative_refinementfeature_search, attribute_filterProgressive narrowing of results
multi_hopfeature_search, attribute_filter, llm_filterFollowing cross-document references
tree_navigationfeature_search, attribute_filterHierarchical index traversal
customuser-specifiedFull control over tools and prompt

Available Tools (Stages)

The agent can invoke any registered retriever stage as a tool. Each stage is presented to the LLM with a simplified parameter schema:
ToolWhat the LLM SeesTypical Use
feature_searchSemantic similarity search with query and top_kVector search
attribute_filterFilter by field, operator, and valueMetadata filtering
llm_filterFilter by natural language criteriaSemantic filtering
rerankRe-score documents by relevance to queryResult refinement
llm_enrichGenerate new fields using LLM analysisInformation extraction
taxonomy_enrichClassify documents against a taxonomyCategorization

Configuration Examples

{
  "stage_type": "filter",
  "stage_id": "agent_search",
  "parameters": {
    "strategy": "iterative_refinement",
    "max_iterations": 5,
    "timeout_seconds": 30.0
  }
}
Use the custom strategy when you need precise control over which tools the agent can access and how it should reason. The built-in strategies provide sensible defaults for common patterns.

How It Works

  1. Initialize: The LLM receives the user query, available tools, and system prompt
  2. Reason: The LLM analyzes the query and decides which tool to call with what arguments
  3. Execute: The selected stage runs as a sub-execution with the LLM-provided parameters
  4. Observe: Results are summarized and fed back to the LLM as tool call results
  5. Iterate: The LLM decides whether to call another tool or stop
  6. Return: Final accumulated results are returned as the stage output
Each tool call creates a sub-state execution of the target stage, inheriting namespace and collection context from the parent. Results from each iteration replace the previous results, giving the LLM a fresh working set to refine.

Performance

MetricValue
Latency2-30s (depends on iterations and sub-stages)
MemoryO(N) per iteration result set
CostLLM API calls + sub-stage costs per iteration
ComplexityO(iterations * sub-stage complexity)

Common Pipeline Patterns

Agent as First Stage

[
  {
    "stage_type": "filter",
    "stage_id": "agent_search",
    "parameters": {
      "strategy": "iterative_refinement",
      "stages": ["feature_search", "attribute_filter"],
      "max_iterations": 3
    }
  },
  {
    "stage_type": "sort",
    "stage_id": "rerank",
    "parameters": {
      "inference_name": "baai_bge_reranker_v2_m3",
      "query": "{{INPUT.query}}",
      "document_field": "content"
    }
  },
  {
    "stage_type": "reduce",
    "stage_id": "limit",
    "parameters": {
      "limit": 10
    }
  }
]

Complex Query Decomposition

[
  {
    "stage_type": "filter",
    "stage_id": "agent_search",
    "parameters": {
      "strategy": "custom",
      "stages": ["feature_search", "attribute_filter", "llm_filter"],
      "system_prompt": "Break down the user's complex query into sub-queries. Use feature_search for each sub-query, attribute_filter to narrow by metadata, and llm_filter to validate relevance. Combine the best results.",
      "max_iterations": 5,
      "timeout_seconds": 45.0
    }
  },
  {
    "stage_type": "reduce",
    "stage_id": "deduplicate",
    "parameters": {
      "strategy": "field",
      "fields": ["document_id"]
    }
  }
]

Response Metadata

The stage returns execution metadata in stage_statistics:
FieldDescription
iterations_usedNumber of reasoning iterations completed
timeout_hitWhether the timeout was reached
strategyStrategy that was used
stages_invokedList of tool calls made (name + arguments)
total_llm_costTotal LLM API cost for the reasoning loop
model_usedLLM model that was used

Error Handling

ErrorBehavior
Sub-stage execution failsError message returned to LLM; it can retry or try a different approach
Timeout reachedReturns results accumulated so far (graceful degradation)
Max iterations reachedReturns latest results from last successful tool call
Unknown stage in tools listStage is skipped (logged as warning)
LLM returns no tool callsLoop ends; returns current results
Empty collectionReturns empty result set (no error)