async def __handle_before_agent_callback(
      self, ctx: InvocationContext
  ) -> Optional[Event]:
    """Runs the before_agent_callback if it exists.

    Returns:
      Optional[Event]: an event if callback provides content or changed state.
    """
    ret_event = None

    if not self.canonical_before_agent_callbacks:
      return ret_event

    callback_context = CallbackContext(ctx)

    for callback in self.canonical_before_agent_callbacks:
      before_agent_callback_content = callback(
          callback_context=callback_context
      )
      if inspect.isawaitable(before_agent_callback_content):
        before_agent_callback_content = await before_agent_callback_content
      if before_agent_callback_content:
        ret_event = Event(
            invocation_id=ctx.invocation_id,
            author=self.name,
            branch=ctx.branch,
            content=before_agent_callback_content,
            actions=callback_context._event_actions,
        )
        ctx.end_invocation = True
        return ret_event

    if callback_context.state.has_delta():
      ret_event = Event(
          invocation_id=ctx.invocation_id,
          author=self.name,
          branch=ctx.branch,
          actions=callback_context._event_actions,
      )

    return ret_event
Runs the before_agent_callback if it exists.

    Returns:
      Optional[Event]: an event if callback provides content or changed state.
    
src/google/adk/agents/base_agent.py