def generate_tool_call_messages(
    *,
    response: Message,
    conversation_history: Union[Dict[str, Any], List[Dict[str, Any]]],
    client: Optional[BaseFunctionClient] = None,
) -> List[Dict[str, Any]]:
    """
    Generates tool call messages based on the response from Anthropic and conversation history.

    Args:
        response (Message): The response from Anthropic.
        conversation_history (Union[Dict[str, Any], List[Dict[str, Any]]]): The history of the conversation to prepend.
        client (Optional[BaseFunctionClient]): The client for executing Unity Catalog functions.

    Returns:
        List[Dict[str, Any]]: A list of messages including tool execution results and conversation history.
    """
    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

    tool_calls_data = extract_tool_call_data(response)

    tool_results = []
    if tool_calls_data:
        for tool_call_data in tool_calls_data:
            result = tool_call_data.execute(client)

            tool_results.append(tool_call_data.to_tool_result_message(result))

    assistant_message_content = [block.to_dict() for block in response.content]

    assistant_message = {"role": response.role, "content": assistant_message_content}

    function_calls = []
    if tool_results:
        function_calls.append({"role": "user", "content": tool_results})

    return [*validated_history, assistant_message, *function_calls]

    Generates tool call messages based on the response from Anthropic and conversation history.

    Args:
        response (Message): The response from Anthropic.
        conversation_history (Union[Dict[str, Any], List[Dict[str, Any]]]): The history of the conversation to prepend.
        client (Optional[BaseFunctionClient]): The client for executing Unity Catalog functions.

    Returns:
        List[Dict[str, Any]]: A list of messages including tool execution results and conversation history.
    
ai/integrations/anthropic/src/unitycatalog/ai/anthropic/utils.py