Skip to content

agentic_retrieve async

agentic_retrieve(
    agent_context_id: AgentContextIdentifier,
    messages: MessageList,
    *,
    config_overrides: Optional[AsyncContextClientConfig] = None,
    session_id: Optional[SessionId] = None,
    analysis_configuration: Optional[AnalysisConfiguration] = None,
    retrieval_configuration: Optional[RetrievalConfiguration] = None,
) -> AgenticRetrieveResponse

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.

Parameters:

  • agent_context_id (AgentContextIdentifier) –

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

  • messages (MessageList) –

    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.

  • session_id (Optional[SessionId], default: None ) –

    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.

  • analysis_configuration (Optional[AnalysisConfiguration], default: None ) –

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

  • retrieval_configuration (Optional[RetrievalConfiguration], default: None ) –

    Optional bounds and configuration for the agent loop.

Raises:

  • AccessDeniedException –

    You don't have sufficient access to perform this operation. Verify that you have permission to perform the operation on the resource.

  • InternalServerException –

    The request failed because of an internal error. Retry the request.

  • ThrottlingException –

    The request was denied because it exceeded a request rate quota. Wait, then retry the request.

  • ValidationException –

    The input fails to satisfy the constraints of the operation. Correct the input before you retry the request.

  • ConflictException –

    The request conflicts with the current state of the resource. Check the resource's current state before you retry the request.

  • ResourceNotFoundException –

    The specified resource was not found. Check that the ID is correct and that the resource exists in your account and Region.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Examples:

Retrieve context for a question about an agent context The following example asks which table holds customer orders and returns the retrieved context in a single response.

>>> await client.agentic_retrieve(agent_context_id='ac-0123456789abcdef0123456789abcdef', session_id='sales-analytics-chat-0001', messages=[{'role': 'USER', 'content': 'Which table holds customer order data?'}], retrieval_configuration={'maxIterations': 10})
Source code in docs_src/capo_context/_services/async_context.py
async def agentic_retrieve(
    self,
    agent_context_id: "capo_context.types.agent_context_identifier.AgentContextIdentifier",
    messages: "capo_context.types.message_list.MessageList",
    *,
    config_overrides: Optional[AsyncContextClientConfig] = None,
    session_id: Optional["capo_context.types.session_id.SessionId"] = None,
    analysis_configuration: Optional[
        "capo_context.types.analysis_configuration.AnalysisConfiguration"
    ] = None,
    retrieval_configuration: Optional[
        "capo_context.types.retrieval_configuration.RetrievalConfiguration"
    ] = None,
) -> "capo_context.types.agentic_retrieve_response.AgenticRetrieveResponse":
    """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.

    Args:
        agent_context_id: The agent context to retrieve from, by its ID or ARN.
        messages: 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.
        session_id: 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.
        analysis_configuration: Optional controls for post-call analysis of the retrieval: whether its trace is stored for analysis.
        retrieval_configuration: Optional bounds and configuration for the agent loop.

    Raises:
        capo_context.errors.access_denied_exception.AccessDeniedException: <p>You don't have sufficient access to perform this operation. Verify that you have permission to perform the operation on the resource.</p>
        capo_context.errors.internal_server_exception.InternalServerException: <p>The request failed because of an internal error. Retry the request.</p>
        capo_context.errors.throttling_exception.ThrottlingException: <p>The request was denied because it exceeded a request rate quota. Wait, then retry the request.</p>
        capo_context.errors.validation_exception.ValidationException: <p>The input fails to satisfy the constraints of the operation. Correct the input before you retry the request.</p>
        capo_context.errors.conflict_exception.ConflictException: <p>The request conflicts with the current state of the resource. Check the resource's current state before you retry the request.</p>
        capo_context.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource was not found. Check that the ID is correct and that the resource exists in your account and Region.</p>
        capo_context.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Retrieve context for a question about an agent context
        The following example asks which table holds customer orders and returns the retrieved context in a single response.

        >>> await client.agentic_retrieve(agent_context_id='ac-0123456789abcdef0123456789abcdef', session_id='sales-analytics-chat-0001', messages=[{'role': 'USER', 'content': 'Which table holds customer order data?'}], retrieval_configuration={'maxIterations': 10})
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_context.types.agentic_retrieve_request.AgenticRetrieveRequest]",
    ) -> AsyncOperationResponse[
        "capo_context.types.agentic_retrieve_response.AgenticRetrieveResponse"
    ]:
        import capo_context._operations.context.agentic_retrieve

        (
            output,
            http_response,
        ) = await capo_context._operations.context.agentic_retrieve.async_agentic_retrieve(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_context.types.agentic_retrieve_request.AgenticRetrieveRequest",
    ) -> dict[str, Any]:
        import capo_context.types.agentic_retrieve_request

        return capo_context.types.agentic_retrieve_request.redact_sensitive(input_)

    def _redact_output(
        output: "capo_context.types.agentic_retrieve_response.AgenticRetrieveResponse",
    ) -> dict[str, Any]:
        import capo_context.types.agentic_retrieve_response

        return capo_context.types.agentic_retrieve_response.redact_sensitive(output)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "AgenticRetrieve",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_context.types.agentic_retrieve_request.AgenticRetrieveRequest = {
        "agent_context_id": agent_context_id,
        "messages": messages,
    }
    if session_id is not None:
        input_["session_id"] = session_id
    if analysis_configuration is not None:
        input_["analysis_configuration"] = analysis_configuration
    if retrieval_configuration is not None:
        input_["retrieval_configuration"] = retrieval_configuration

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output