def format_search_results_for_llm(
    results: AggregateSearchResult,
) -> str:
    """
    Instead of resetting 'source_counter' to 1, we:
     - For each chunk / graph / web / doc in `results`,
     - Find the aggregator index from the collector,
     - Print 'Source [X]:' with that aggregator index.
    """
    lines = []

    # We'll build a quick helper to locate aggregator indices for each object:
    # Or you can rely on the fact that we've added them to the collector
    # in the same order. But let's do a "lookup aggregator index" approach:

    # 1) Chunk search
    if results.chunk_search_results:
        lines.append("Vector Search Results:")
        for c in results.chunk_search_results:
            lines.extend(
                (f"Source ID [{id_to_shorthand(c.id)}]:", (c.text or ""))
            )

    # 2) Graph search
    if results.graph_search_results:
        lines.append("Graph Search Results:")
        for g in results.graph_search_results:
            lines.append(f"Source ID [{id_to_shorthand(g.id)}]:")
            if isinstance(g.content, GraphCommunityResult):
                lines.extend(
                    (
                        f"Community Name: {g.content.name}",
                        f"ID: {g.content.id}",
                        f"Summary: {g.content.summary}",
                    )
                )
            elif isinstance(g.content, GraphEntityResult):
                lines.extend(
                    (
                        f"Entity Name: {g.content.name}",
                        f"Description: {g.content.description}",
                    )
                )
            elif isinstance(g.content, GraphRelationshipResult):
                lines.append(
                    f"Relationship: {g.content.subject}-{g.content.predicate}-{g.content.object}"
                )

    # Web page search results
    if results.web_page_search_results:
        lines.append("Web Page Search Results:")
        for w in results.web_page_search_results:
            lines.extend(
                (
                    f"Source ID [{id_to_shorthand(w.id)}]:",
                    f"Title: {w.title}",
                    f"Link: {w.link}",
                    f"Snippet: {w.snippet}",
                )
            )

    # Web search results
    if results.web_search_results:
        for web_search_result in results.web_search_results:
            lines.append("Web Search Results:")
            for search_result in web_search_result.organic_results:
                lines.extend(
                    (
                        f"Source ID [{id_to_shorthand(search_result.id)}]:",
                        f"Title: {search_result.title}",
                        f"Link: {search_result.link}",
                        f"Snippet: {search_result.snippet}",
                    )
                )

    # 4) Local context docs
    if results.document_search_results:
        lines.append("Local Context Documents:")
        for doc_result in results.document_search_results:
            doc_title = doc_result.title or "Untitled Document"
            doc_id = doc_result.id

            lines.extend(
                (
                    f"Full Document ID: {doc_id}",
                    f"Shortened Document ID: {id_to_shorthand(doc_id)}",
                    f"Document Title: {doc_title}",
                )
            )
            if summary := doc_result.summary:
                lines.append(f"Summary: {summary}")

            if doc_result.chunks:
                # Then each chunk inside:
                lines.extend(
                    f"\nChunk ID {id_to_shorthand(chunk['id'])}:\n{chunk['text']}"
                    for chunk in doc_result.chunks
                )

    if results.generic_tool_result:
        lines.extend(
            (f"Generic Tool Results: {tool_result}" or "")
            for tool_result in results.generic_tool_result
        )

    return "\n".join(lines)

    Instead of resetting 'source_counter' to 1, we:
     - For each chunk / graph / web / doc in `results`,
     - Find the aggregator index from the collector,
     - Print 'Source [X]:' with that aggregator index.
    
py/shared/utils/base_utils.py