async def custom_arun(*args, **kwargs):
        """Custom arun that includes overlapping citations."""
        # Setup like the original
        await agent._setup(kwargs.get('system_instruction'))

        messages = kwargs.get('messages', [])
        if messages:
            for m in messages:
                await agent.conversation.add_message(m)

        # Initialize citation tracker
        citation_tracker = CitationTracker()
        citation_payloads = {}

        # Track streaming citations for final persistence
        agent.streaming_citations = []

        # Create text with overlapping citations (citation spans that overlap)
        response_content = "This text has overlapping citations [abc1234] part of which [def5678] overlap."

        # Yield the message event
        yield agent._format_sse_event("message", {"content": response_content})

        # Manually create overlapping citation spans
        # For simplicity, we'll define the spans directly rather than using regex
        citation_spans = {
            "abc1234": [(30, 39)],  # This span includes "[abc1234]"
            "def5678": [(55, 64)]   # This span includes "[def5678]"
        }

        # Process the citations
        for cid, spans in citation_spans.items():
            for span in spans:
                # Mark as processed in the tracker
                citation_tracker.is_new_span(cid, span)

                # Look up the source document for this citation
                source_doc = agent.search_results_collector.find_by_short_id(cid)

                # Create citation payload
                citation_payload = {
                    "document_id": source_doc.get("document_id", f"doc_{cid}"),
                    "text": source_doc.get("text", f"This is document text for {cid}"),
                    "metadata": source_doc.get("metadata", {"source": f"source_{cid}"}),
                }

                # Store the payload by citation ID
                citation_payloads[cid] = citation_payload

                # Track for persistence
                agent.streaming_citations.append({
                    "id": cid,
                    "span": {"start": span[0], "end": span[1]},
                    "payload": citation_payload
                })

                # Emit citation event
                citation_event = {
                    "id": cid,
                    "object": "citation",
                    "span": {"start": span[0], "end": span[1]},
                    "payload": citation_payload
                }

                yield agent._format_sse_event("citation", citation_event)

        # Add assistant message with citation metadata to conversation
        await agent.conversation.add_message(
            Message(
                role="assistant",
                content=response_content,
                metadata={"citations": agent.streaming_citations}
            )
        )

        # Prepare consolidated citations for final answer
        consolidated_citations = []

        # Group citations by ID with all their spans
        for cid, spans in citation_tracker.get_all_spans().items():
            if cid in citation_payloads:
                consolidated_citations.append({
                    "id": cid,
                    "object": "citation",
                    "spans": [{"start": s[0], "end": s[1]} for s in spans],
                    "payload": citation_payloads[cid]
                })

        # Create and emit final answer event
        final_evt_payload = {
            "id": "msg_final",
            "object": "agent.final_answer",
            "generated_answer": response_content,
            "citations": consolidated_citations
        }

        # Emit final answer event
        yield agent._format_sse_event("agent.final_answer", final_evt_payload)

        # Signal the end of the SSE stream
        yield "event: done\ndata: {}\n\n"
Custom arun that includes overlapping citations.
py/tests/unit/agent/test_agent_citations_old.py