> ## 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_agent_speech()

> Receive every utterance spoken by the agent

<Tabs>
  <Tab title="Python">
    <Warning>
      **Rarely needed.** This callback fires for every utterance spoken by the agent. Most implementations will not need it and should instead rely on higher-level callbacks like [`on_question`](/sdk-reference/on-question) or [`on_task_complete`](/sdk-reference/on-task-complete). It is most useful for implementing call surveillance or real-time transcription logging.
    </Warning>

    Register a handler to receive a callback whenever the agent speaks. The event contains what the agent said and whether it was interrupted by the caller.

    The `AgentSpeechEvent` is a pydantic model imported from `guava.events`:

    ```python theme={null}
    from guava.events import AgentSpeechEvent

    class AgentSpeechEvent(BaseEvent):
        event_type: Literal["agent-speech"] = "agent-speech"
        utterance: str
        interrupted: bool = False
    ```
  </Tab>

  <Tab title="TypeScript">
    <Warning>
      **Rarely needed.** This callback fires for every utterance spoken by the agent. Most implementations will not need it and should instead rely on higher-level callbacks like [`onQuestion`](/sdk-reference/on-question) or [`onTaskComplete`](/sdk-reference/on-task-complete). It is most useful for implementing call surveillance or real-time transcription logging.
    </Warning>

    Register a handler to receive a callback whenever the agent speaks. The event contains what the agent said and whether it was interrupted by the caller.

    The `AgentSpeechEvent` has the following shape:

    ```typescript theme={null}
    type AgentSpeechEvent = {
      event_type: "agent-speech";
      utterance: string;
      interrupted: boolean; // default: false
    };
    ```
  </Tab>
</Tabs>

## Signature

<Tabs>
  <Tab title="Python">
    ```python signature theme={null}
    @agent.on_agent_speech
    def on_agent_speech(call: guava.Call, event: AgentSpeechEvent) -> None:
        ...
    ```

    | Parameter | Type | Description |
    | - | - | - |
    | `call` | `Call` | The active call object. |
    | `event` | `AgentSpeechEvent` | Contains `utterance` (string) and `interrupted` (boolean) fields. |

    **Return value:** `None`
  </Tab>

  <Tab title="TypeScript">
    ```typescript signature theme={null}
    agent.onAgentSpeech((call: guava.Call, event: AgentSpeechEvent) => void);
    ```

    | Parameter | Type | Description |
    | - | - | - |
    | `call` | `Call` | The active call object. |
    | `event` | `AgentSpeechEvent` | Contains `utterance` (string) and `interrupted` (boolean) fields. |

    **Return value:** `void`
  </Tab>
</Tabs>

## Example

<Tabs>
  <Tab title="Python">
    ```python controller.py theme={null}
    import logging
    from guava.events import AgentSpeechEvent

    logger = logging.getLogger(__name__)


    @agent.on_agent_speech
    def on_agent_speech(call: guava.Call, event: AgentSpeechEvent):
        logger.info("agent speech event: %s", event)

    # Output:
    # [INFO  15:02:29] agent speech event: sequence=None event_type='agent-speech'
    #   utterance='Hi, thank you for calling Thai Palace. My name is Grace.
    #   I can help you with the waitlist. ' interrupted=False
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript controller.ts theme={null}
    import * as guava from "@guava-ai/guava-sdk";
    import { AgentSpeechEvent } from "@guava-ai/guava-sdk/events";

    agent.onAgentSpeech((_call: guava.Call, event: AgentSpeechEvent) => {
      console.log("agent speech event:", JSON.stringify(event));
    });
    ```
  </Tab>
</Tabs>


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