Read the answer, citations, and retrieved context
The result event of a stream, and the AgenticRetrieve response, contain three fields:
-
answer: the answer text. -
citations: the spans of the answer that retrieved context supports. Each citation has astartIndexandendIndexintoanswer, andreferencesto the supporting items. -
retrievedContext: the items the agent gathered. These are entities and relationships from the Agent context, and passages from knowledge base documents.
Each references entry names one item in retrievedContext by its nodeId, edgeId, or documentId; each retrievedContext item carries exactly one of those IDs, an entityType of NODE, EDGE, or DOCUMENT, a summary, its properties, and for documents the passage content. endIndex is exclusive, so the cited span is answer[startIndex:endIndex]. The following example result cites one knowledge base passage.
{ "answer": "1,240 orders shipped late in Q3.", "citations": [ { "startIndex": 0, "endIndex": 32, "references": [{"documentId": "doc-shipping-q3-report"}] } ], "retrievedContext": [ { "documentId": "doc-shipping-q3-report", "entityType": "DOCUMENT", "summary": "Q3 shipping report", "content": {"text": "...1,240 late shipments in Q3...", "mimeType": "text/plain"}, "properties": {} } ] }
To show a citation, take answer[startIndex:endIndex] and look up each reference in retrievedContext by the matching ID. To open an entity in the console, choose View in agent context next to a source in Chat with context. For the response fields, see AgenticRetrieveStream in the
AWS Context API Reference.
Third-party authorization. An answer can need a source such as Snowflake or Databricks that the user hasn’t authorized AWS Context to read. In that case the MCP tool context___AgenticRetrieve returns authorizationRequired with a single-use authorizationUrl. Have the user open the URL, complete authorization, and send the request again. AgenticRetrieveStream doesn’t return an authorization URL. It answers from the sources the user can read.