on session end.md

on_session_end()

Register a handler that fires when a call session ends. Use this to save call data, trigger post-call workflows, or log outcomes.

The BotSessionEnded event carries a termination_reason field that tells you why the session ended:

Value Meaning
"user-hangup" The caller hung up.
"bot-hangup" The agent ended the call (e.g. via call.hangup()).
"bot-failure" The session ended due to an internal error.
"bot-transfer" The call was transferred to another destination.
"voicemail" The outbound call reached voicemail.

Signature

@agent.on_session_end
def on_session_end(call: guava.Call, event: BotSessionEnded) -> None:
    ...
agent.onSessionEnd(async (call: guava.Call, event: BotSessionEnded) => void);

Example

import logging
from guava.events import BotSessionEnded

logger = logging.getLogger(__name__)

@agent.on_session_end
def on_session_end(call: guava.Call, event: BotSessionEnded):
    logger.info("session ended: reason=%s", event.termination_reason)
    if event.termination_reason == "user-hangup":
        # caller hung up — save any collected data
        ...
    elif event.termination_reason == "bot-transfer":
        # call was transferred to a human agent
        ...
import * as guava from "@guava-ai/guava-sdk";
import type { BotSessionEnded } from "@guava-ai/guava-sdk";

agent.onSessionEnd(async (_call: guava.Call, event: BotSessionEnded) => {
  console.log("session ended:", event.termination_reason);
  if (event.termination_reason === "user-hangup") {
    // caller hung up — save any collected data
  } else if (event.termination_reason === "bot-transfer") {
    // call was transferred to a human agent
  }
});