Skip to main content

Basic Usage

from typing import Annotated
from agentstack_sdk.a2a.extensions import (
    Citation,
    CitationExtensionServer,
    CitationExtensionSpec,
)
from agentstack_sdk.server import Server
from agentstack_sdk.server.context import RunContext
from a2a.types import Message

server = Server()

@server.agent()
async def research_agent(
    input: Message,
    context: RunContext,
    citation: Annotated[CitationExtensionServer, CitationExtensionSpec()]
):
    response_text = "Python is the most popular programming language for AI development."
    
    citations = [
        Citation(
            url="https://survey.stackoverflow.com/2023",
            title="Stack Overflow Developer Survey 2023",
            description="Annual survey of developer preferences and trends",
            start_index=0,
            end_index=47  # "Python is the most popular programming language"
        )
    ]
    
    yield citation.message(text=response_text, citations=citations)

Citation Format

Each citation requires:
  • url: Source link
  • title: Display title
  • description: Brief explanation
  • start_index: Start position in text
  • end_index: End position in text

Multiple Citations

response_text = "Python leads AI development while JavaScript dominates web development."

citations = [
    {
        "url": "https://ai-survey.com",
        "title": "AI Language Survey",
        "description": "Programming language usage in AI",
        "start_index": 0,
        "end_index": 31  # "Python leads AI development"
    },
    {
        "url": "https://web-stats.com", 
        "title": "Web Development Report",
        "description": "Web programming language statistics",
        "start_index": 38,
        "end_index": 67  # "JavaScript dominates web development"
    }
]
Citations appear as highlighted text with hover tooltips and clickable source links in the UI.