def synchronized(f=None, *, transition: bool = False):
    """
    Prevents the function tool from being called concurrently.

    Caveats:
    - Calls made while the function is executing are discarded.
    - The agent won't react to caller speech while the function is executing.

    Args:
        f: The function to decorate (when used without parentheses)
        transition: Whether or not to make a transition after executing the function_tool.

    Returns:
        The function_tool (or transition) response.

    Usage:
        @synchronized
        @synchronized(transition=True)
        @function_tool
        async def my_function_tool(*args, **kwargs):
            do_something()
    """

    def _decorator(func: Awaitable[Callable]) -> Awaitable[Callable]:
        is_running = False

        @wraps(func)
        async def _wrapper(*args, **kwargs) -> Any:
            # discard the call if already running
            nonlocal is_running
            if is_running:
                return None

            is_running = True
            ctx = _get_run_context_from_params(args, kwargs)
            await ctx.wait_for_playout()  # wait for agent speech to finish
            ctx.session.input.set_audio_enabled(False)  # stop reacting to caller speech

            try:
                # execute function_tool
                result = await func(*args, **kwargs)

                # return a (successful) response
                agent: BaseAgent = ctx.session.current_agent
                return await agent.transition() if transition else result
            finally:
                # enable audio, even if the function_tool raises an exception
                ctx.session.input.set_audio_enabled(True)
                # release lock
                is_running = False

        return _wrapper

    # Handle both @synchronized and @synchronized(transition=True) cases
    return _decorator(f) if f else _decorator