Clarifier Agent

August 21, 2026 ยท View on GitHub

The Clarifier Agent provides human-in-the-loop (HITL) interaction before deep research begins. It gathers context and, when the request is vague, optionally asks the user to narrow the scope or clarify the type of output requested.

Location: src/aiq_agent/agents/clarifier/agent.py

Purpose

Deep research is expensive in both time and compute. The Clarifier reduces wasted effort by:

  1. Gathering context (including optional tool calls such as web search) about the request
  2. Asking focused clarification questions only when the request is genuinely ambiguous
  3. Optionally clarifying the type of output the user wants (for example, report, table, comparison, prediction, or brief answer) when that is unclear

The clarifier runs on the deep research path and also when a shallow query escalates to deep. It can be disabled entirely using enable_clarifier: false in the orchestrator config.

Internal Flow

graph TD
    A[Receive ClarifierAgentState] --> B[Load clarification prompt]
    B --> C[Invoke LLM with conversation + tools]

    C --> D{Tool calls requested?}
    D -->|yes| E[Execute tools using ToolNode]
    E --> F[Append JSON reminder]
    F --> C

    D -->|no| G[Parse ClarificationResponse JSON]
    G --> H{needs_clarification?}

    H -->|yes| I{iteration < max_turns?}
    I -->|yes| J[Prompt user through HITL callback]
    J --> K[Append user response to messages]
    K --> C
    I -->|no| L[Auto-complete clarification]

    H -->|no| L[Clarification complete]
    L --> N[Return ClarifierResult<br/>with clarifier_log]

    style A fill:#e1f5fe
    style N fill:#e8f5e9
    style J fill:#fff3e0

State Model

ClarifierAgentState

FieldTypeDefaultDescription
messagesAnnotated[list[AnyMessage], add_messages]requiredConversation history with LangGraph message reducer
data_sourceslist[str] or NoneNoneData source IDs for tool filtering. None uses all configured tools; [] keeps only unmapped utility tools; a populated list scopes to the named sources plus unmapped utility tools.
available_documentslist[dict[str, Any]] or NoneNoneUser-uploaded documents (file name, summary) for context; the user may refer to these
max_turnsint3Maximum clarification Q&A turns
clarifier_logstr""Accumulated clarification dialog log
iterationint0Current clarification turn counter

Computed property:

  • remaining_questions = max_turns - iteration

ClarifierResult

Returned to the orchestrator after the clarification dialog completes:

FieldTypeDescription
clarifier_logstrFull clarification dialog log

ClarificationResponse

Structured JSON response parsed from the LLM output during clarification:

FieldTypeDescription
needs_clarificationboolWhether more clarification is needed
clarification_questionstr or NoneThe question to ask the user

Configuration

Configured through ClarifierConfig (NeMo Agent Toolkit type name: clarifier_agent):

ParameterTypeDefaultDescription
llmLLMRefrequiredLLM for generating clarification questions
toolslist[FunctionRef | FunctionGroupRef][]Tools for context gathering (for example, web search)
max_turnsint3Maximum clarification Q&A turns before auto-completing
log_response_max_charsint2000Maximum characters to log from LLM responses

Example YAML:

functions:
  clarifier_agent:
    _type: clarifier_agent
    llm: nemotron_llm
    tools:
      - web_search_tool
    max_turns: 3

Prompt Templates

Located in src/aiq_agent/agents/clarifier/prompts/:

TemplatePurpose
research_clarification.j2Generates clarification questions. Includes conditional sections for uploaded documents context. Instructs the LLM to respond with JSON containing needs_clarification and clarification_question. Template variables: clarifier_result, available_documents, tools, tool_names

HITL Interaction Patterns

The clarifier uses NeMo Agent Toolkit's user_interaction_manager to prompt the user. The callback is injected during registration:

Agent:  "Could you clarify whether you're interested in renewable energy
         adoption in all G7 nations or specific ones?"
User:   "Focus on Germany and Japan."
Agent:  "Got it. Are you interested in economic impacts from a GDP perspective,
         job creation, or both?"
User:   "Both GDP impact and job creation."
Agent:  [clarification complete, proceeds to deep research]

When the desired output form is unclear, the clarifier may instead ask which type of output you want (for example, a full report, a comparison table, or a brief answer) before research begins.