def generate_tool_call_messages(
    *,
    response: Message,
    conversation_history: Union[dict[str, Any], list[dict[str, Any]]],
    client: Optional[BaseFunctionClient] = None,
    choice_index: int = 0,
) -> list[dict[str, Any]]:
    """
    Generate tool call messages from the response.

    If there are multiple tool calls in the selected Choice, each tool's function call response will
    be appended to the messages as a unique message. For instance, if there are 2 tool calls
    requested by the LiteLLM response, we will append the following payload to the
    `conversation_history` and `response` list.

    [
        {"role", "user": "content": "function_1_response_as_a_string"},
        {"role", "user": "content": "function_2_response_as_a_string"}
    ]

    Args:
        response: The chat completion response object returned by the LiteLLM.completion API.
        client: The client for managing functions, must be an instance of BaseFunctionClient.
            Defaults to None.
        conversation_history (Union[dict[str, Any], list[dict[str, Any]]]): The history of the
            conversation to prepend.
        choice_index: The index of the choice to process. Defaults to 0. Note that multiple
            choices are not supported yet.

    Returns:
        A list of messages containing the assistant message and the function call results.
    """
    client = validate_or_set_default_client(client)
    if isinstance(conversation_history, dict):
        conversation_history = [conversation_history]

    validated_history = []
    try:
        validated_history = [
            ConversationMessage(**message).model_dump() for message in conversation_history
        ]
    except ValidationError as e:
        raise ValueError("Invalid conversation history format") from e

    choice = response.choices[choice_index]

    function_calls = []
    for tool_call_data in _extract_tool_call_data_from_choice(choice):
        result = tool_call_data.execute(client)
        function_calls.append(tool_call_data.to_tool_result_message(result))

    assistant_message = choice.message.to_dict()
    return [*validated_history, assistant_message, *function_calls]

    Generate tool call messages from the response.

    If there are multiple tool calls in the selected Choice, each tool's function call response will
    be appended to the messages as a unique message. For instance, if there are 2 tool calls
    requested by the LiteLLM response, we will append the following payload to the
    `conversation_history` and `response` list.

    [
        {"role", "user": "content": "function_1_response_as_a_string"},
        {"role", "user": "content": "function_2_response_as_a_string"}
    ]

    Args:
        response: The chat completion response object returned by the LiteLLM.completion API.
        client: The client for managing functions, must be an instance of BaseFunctionClient.
            Defaults to None.
        conversation_history (Union[dict[str, Any], list[dict[str, Any]]]): The history of the
            conversation to prepend.
        choice_index: The index of the choice to process. Defaults to 0. Note that multiple
            choices are not supported yet.

    Returns:
        A list of messages containing the assistant message and the function call results.
    
ai/integrations/litellm/src/unitycatalog/ai/litellm/utils.py