def index_on_length(patterns: list[str]) -> dict[int, list[str]]:
    """
    >>> index_on_length(['abcd', 'cde', 'agd'])
    {4: ['abcd'], 3: ['cde', 'agd']}
    """
    length_index = {}
    for pattern in patterns:
        length_index.setdefault(len(pattern), []).append(pattern)

    return length_index