> ## Documentation Index
> Fetch the complete documentation index at: https://docs.goguava.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# on_question()

> Answer caller questions the agent can't answer from context

<Tabs>
  <Tab title="Python">
    When a Guava agent is asked a question that it cannot answer from its context alone, it will invoke the `on_question` callback. Your **Expert** then has the chance to answer that question, typically using a RAG system. Our examples use the provided `DocumentQA` class, but you can use any RAG system you prefer.

    See our [Q\&A example](/getting-started/inbound-rag-example) for a step-by-step walkthrough.

    ```python signature theme={null}
    @agent.on_question
    def on_question(call: guava.Call, question: str) -> str:
        # question: natural-language question from the caller
        # return: answer to relay to caller
        ...
    ```

    <Tip>
      If you want the agent to answer questions immediately, use [`add_info`](/sdk-reference/add-info) to pre-emptively add information to the context.
    </Tip>

    * `on_question`, like all Guava callbacks, is invoked asynchronously and does not block dialog. The Guava voice agent continues to engage the caller until the question answer comes back.
    * `on_question` may be invoked multiple times, for example, if a caller asks a question and then refines it. `on_question` may be invoked speculatively before a caller is done talking.
    * `on_question` may be invoked simultaneously with [`on_action_request`](/sdk-reference/on-action-request-execute), as some requests can be both an "action" and a "question". For example, *"Do you have a lost and found?"* In this case, the agent will synthesize both responses: *"Yes, we have a lost and found. Would you like me to transfer you there?"*
  </Tab>

  <Tab title="TypeScript">
    When a Guava agent is asked a question that it cannot answer from its context alone, it will invoke the `onQuestion` callback. Your **Expert** then has the chance to answer that question, typically using a RAG system. Our examples use the provided `DocumentQA` class, but you can use any RAG system you prefer.

    See our [Q\&A example](/getting-started/inbound-rag-example) for a step-by-step walkthrough.

    ```typescript signature theme={null}
    agent.onQuestion(async (call: guava.Call, question: string) => string);
    ```

    <Tip>
      If you want the agent to answer questions immediately, use [`addInfo`](/sdk-reference/add-info) to pre-emptively add information to the context.
    </Tip>

    * `onQuestion`, like all Guava callbacks, is invoked asynchronously and does not block dialog. The Guava voice agent continues to engage the caller until the question answer comes back.
    * `onQuestion` may be invoked multiple times, for example, if a caller asks a question and then refines it. `onQuestion` may be invoked speculatively before a caller is done talking.
    * `onQuestion` may be invoked simultaneously with [`onActionRequest`](/sdk-reference/on-action-request-execute), as some requests can be both an "action" and a "question". For example, *"Do you have a lost and found?"* In this case, the agent will synthesize both responses: *"Yes, we have a lost and found. Would you like me to transfer you there?"*
  </Tab>
</Tabs>

## Example

<Tabs>
  <Tab title="Python">
    ```python support_controller.py theme={null}
    import guava
    from guava import Agent
    from guava.helpers.rag import DocumentQA
    from guava.examples.example_data import PROPERTY_INSURANCE_POLICY

    agent = Agent(
        organization="Harper Valley Property Insurance",
        purpose="Answer questions regarding property insurance policy",
    )

    document_qa = DocumentQA(documents=PROPERTY_INSURANCE_POLICY)

    @agent.on_question
    def on_question(call: guava.Call, question: str) -> str:
        return document_qa.ask(question)
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript support_controller.ts theme={null}
    import * as guava from "@guava-ai/guava-sdk";
    import { DocumentQA } from "@guava-ai/guava-sdk/helpers";
    import { PROPERTY_INSURANCE_POLICY } from "@guava-ai/guava-sdk/example-data";

    const agent = new guava.Agent({
      organization: "Harper Valley Property Insurance",
      purpose: "Answer questions regarding property insurance policy",
    });

    const documentQA = new DocumentQA({
      documents: PROPERTY_INSURANCE_POLICY,
      namespace: "harper-valley-property-insurance",
    });

    agent.onQuestion(async (call: guava.Call, question: string) => {
      return await documentQA.ask(question);
    });
    ```
  </Tab>
</Tabs>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.