Context / Client / agentic_retrieve

agentic_retrieve

Context.Client.agentic_retrieve(**kwargs)

Retrieves ranked context from an agent context for a natural-language question, in a single response. Send the question as a user message in messages and read the ranked retrievedContext. AWS Context searches and traverses the agent context for you until it has gathered enough context or reaches maxIterations. Prefer this over SearchAgentContext when finding the context needs more than one search or hop. To stream progress and receive a generated answer, use AgenticRetrieveStream.

See also: AWS API Documentation

Request Syntax

response = client.agentic_retrieve(
    agentContextId='string',
    messages=[
        {
            'role': 'USER'|'ASSISTANT',
            'content': 'string'
        },
    ],
    sessionId='string',
    analysisConfiguration={
        'emitTrace': 'ENABLED'|'DISABLED'
    },
    retrievalConfiguration={
        'maxIterations': 123
    }
)
Parameters:
  • agentContextId (string) –

    [REQUIRED]

    The agent context to retrieve from, by its ID or ARN.

  • messages (list) –

    [REQUIRED]

    The conversation, as an ordered list of turns. A single-question caller sends one user message. The list carries multi-turn history so a follow-up resolves against earlier turns.

    • (dict) –

      A single conversation turn.

      • role (string) – [REQUIRED]

        The role of the participant that produced this turn. Valid values:

        • USER - The user asked or said this turn.

        • ASSISTANT - The assistant answered in this turn.

      • content (string) – [REQUIRED]

        The turn’s text content.

  • sessionId (string) – Optional. A key that you supply to group related calls, for example the turns of one conversation, for trace storage and analysis. Grouping is per account, across agent contexts, so use a value that is unique to each conversation.

  • analysisConfiguration (dict) –

    Optional controls for post-call analysis of the retrieval: whether its trace is stored for analysis.

    • emitTrace (string) –

      Specifies whether AWS Context stores this call’s agent trace for asynchronous analysis. Absent means ENABLED. A trace is stored only when the agent context’s traceAnalysisConfig also has status and includeContextAgentTraces ENABLED.

  • retrievalConfiguration (dict) –

    Optional bounds and configuration for the agent loop.

    • maxIterations (integer) –

      The maximum number of agent turns, from 2 to 50. One turn is roughly one round of tool calls and their results. If you omit it, AWS Context uses 30. The minimum is 2, because the agent needs at least one planning turn and one acting turn.

Return type:

dict

Returns:

Response Syntax

{
    'retrievedContext': [
        {
            'nodeId': 'string',
            'edgeId': {
                'from': 'string',
                'to': 'string'
            },
            'documentId': 'string',
            'entityType': 'NODE'|'EDGE'|'DOCUMENT',
            'summary': 'string',
            'content': {
                'byteContent': b'bytes',
                'text': 'string',
                'mimeType': 'string'
            },
            'properties': {
                'string': {
                    'stringValue': 'string',
                    'intValue': 123,
                    'longValue': 123,
                    'boolValue': True|False,
                    'floatValue': ...,
                    'doubleValue': 123.0,
                    'stringListValue': [
                        'string',
                    ],
                    'intListValue': [
                        123,
                    ],
                    'longListValue': [
                        123,
                    ],
                    'floatListValue': [
                        ...,
                    ],
                    'doubleListValue': [
                        123.0,
                    ],
                    'boolListValue': [
                        True|False,
                    ]
                }
            }
        },
    ],
    'answer': 'string',
    'citations': [
        {
            'startIndex': 123,
            'endIndex': 123,
            'references': [
                {
                    'nodeId': 'string',
                    'edgeId': {
                        'from': 'string',
                        'to': 'string'
                    },
                    'documentId': 'string'
                },
            ]
        },
    ],
    'authorizationRequired': {
        'authorizationUrl': 'string',
        'message': 'string'
    }
}

Response Structure

  • (dict) –

    The result of a retrieval. retrievedContext is always present. A response that only asks for authorization carries authorizationRequired beside an empty retrievedContext.

    • retrievedContext (list) –

      The ranked, structured context that the agent assembled across all iterations, without duplicates. Always present. Each entry is a graph node, a graph edge, or a document.

      • (dict) –

        One entity in the context that AgenticRetrieveStream returns: a graph node, a graph edge, or a document.

        • nodeId (string) –

          Identifier of the node. Set when this result is a node (one of nodeId, edgeId, or documentId).

        • edgeId (dict) –

          Identifier of the edge. Set when this result is an edge (one of nodeId, edgeId, or documentId).

          • from (string) –

            The ID of the node where the edge starts.

          • to (string) –

            The ID of the node where the edge ends.

        • documentId (string) –

          Identifier of the document. Set when this result is a document (one of nodeId, edgeId, or documentId).

        • entityType (string) –

          Specifies whether this result is a node, an edge, or a document. Valid values:

          • NODE - The result is a node.

          • EDGE - The result is an edge.

          • DOCUMENT - The result is a document.

        • summary (string) –

          Human-readable description or summary of the entity.

        • content (dict) –

          The retrieved content of the entity.

          • byteContent (bytes) –

            The binary content of the retrieved entity.

          • text (string) –

            The text content of the retrieved entity.

          • mimeType (string) –

            The Multipurpose Internet Mail Extensions (MIME) type of the retrieved content.

        • properties (dict) –

          Arbitrary key-value properties stored on the entity.

          • (string) –

            • (dict) –

              The value of a property on a node or an edge in an agent context. Exactly one member is set, and the member that is set determines the value’s type.

              Note

              This is a Tagged Union structure. Only one of the following top level keys will be set: stringValue, intValue, longValue, boolValue, floatValue, doubleValue, stringListValue, intListValue, longListValue, floatListValue, doubleListValue, boolListValue. If a client receives an unknown member it will set SDK_UNKNOWN_MEMBER as the top level key, which maps to the name or tag of the unknown member. The structure of SDK_UNKNOWN_MEMBER is as follows:

              'SDK_UNKNOWN_MEMBER': {'name': 'UnknownMemberName'}
              
              • stringValue (string) –

                A string value, up to 2,048 characters.

              • intValue (integer) –

                A 32-bit signed integer value.

              • longValue (integer) –

                A 64-bit signed integer value.

              • boolValue (boolean) –

                A Boolean value.

              • floatValue (float) –

                A single-precision (32-bit) floating-point value.

              • doubleValue (float) –

                A double-precision (64-bit) floating-point value.

              • stringListValue (list) –

                A list of up to 1,000 string values, each up to 2,048 characters.

                • (string) –

              • intListValue (list) –

                A list of up to 1,000 32-bit signed integer values.

                • (integer) –

              • longListValue (list) –

                A list of up to 1,000 64-bit signed integer values.

                • (integer) –

              • floatListValue (list) –

                A list of up to 1,000 single-precision (32-bit) floating-point values.

                • (float) –

              • doubleListValue (list) –

                A list of up to 1,000 double-precision (64-bit) floating-point values.

                • (float) –

              • boolListValue (list) –

                A list of up to 1,000 Boolean values.

                • (boolean) –

    • answer (string) –

      The synthesized natural-language answer, when one was generated.

    • citations (list) –

      Maps spans of answer to the supporting entities, when an answer was generated.

      • (dict) –

        Maps a span of the answer to the entities that support it. The span is answer[startIndex:endIndex].

        • startIndex (integer) –

          The character offset in answer where the cited span begins.

        • endIndex (integer) –

          The character offset in answer where the cited span ends (exclusive).

        • references (list) –

          The entities in retrievedContext that support the span, referenced by identity.

          • (dict) –

            A reference by entity identity into retrievedContext (one of nodeId, edgeId, or documentId).

            • nodeId (string) –

              Identifier of the referenced node. Set when the reference is a node.

            • edgeId (dict) –

              Identifier of the referenced edge. Set when the reference is an edge.

              • from (string) –

                The ID of the node where the edge starts.

              • to (string) –

                The ID of the node where the edge ends.

            • documentId (string) –

              Identifier of the referenced document. Set when the reference is a document.

    • authorizationRequired (dict) –

      Present when you must authorize access to a third-party resource. If retrievedContext is empty, no result was retrieved. Otherwise, the result leaves out one or more resources that you have not authorized. Show authorizationUrl to the user and retry after they consent.

      • authorizationUrl (string) –

        The URL the end user opens to consent. Single-use and bound to the caller’s identity.

      • message (string) –

        A short, user-facing explanation of what is being authorized.

Exceptions