Skip to content

chat async

chat(
    message: ChatInputContent,
    environment_arn: EnvironmentArn,
    *,
    config_overrides: Optional[AsyncAssuranceClientConfig] = None,
    session_id: Optional[ChatSessionId] = None,
    expected_sequence_number: Optional[ChatSequenceNumber] = None,
) -> ChatOutput

Starts a streaming chat turn with the AWS Assurance agent. Returns an event stream of chat events, including chunks, tool calls, and errors.

Parameters:

  • message (ChatInputContent) –

    The chat message to send to the AWS Assurance agent.

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

    The session to continue. Pass the sessionId returned by a previous Chat call to continue that session. If you omit it, AWS Assurance starts a new session. If the session doesn't exist or has expired, the operation returns ResourceNotFoundException. If the format isn't valid, the operation returns ValidationException.

  • environment_arn (EnvironmentArn) –

    The ARN of this governance environment.

  • expected_sequence_number (Optional[ChatSequenceNumber], default: None ) –

    The sequence number of the last message you received. If the service detects a more recent sequence number, the request fails with ConflictException, indicating a concurrent update.

Raises:

Examples:

Continue a chat session Sends a follow-up question to the AWS Assurance agent to review the open controls in a PCI-DSS assessment.

>>> await client.chat(message='Summarize the open controls in my PCI-DSS assessment.', session_id='a1b2c3d4-5678-90ab-cdef-EXAMPLE88888', environment_arn='arn:aws:assurance:us-east-1:111122223333:environment/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111', expected_sequence_number=2)
Source code in docs_src/capo_assurance/_services/async_assurance.py
async def chat(
    self,
    message: "capo_assurance.types.chat_input_content.ChatInputContent",
    environment_arn: "capo_assurance.types.environment_arn.EnvironmentArn",
    *,
    config_overrides: Optional[AsyncAssuranceClientConfig] = None,
    session_id: Optional[
        "capo_assurance.types.chat_session_id.ChatSessionId"
    ] = None,
    expected_sequence_number: Optional[
        "capo_assurance.types.chat_sequence_number.ChatSequenceNumber"
    ] = None,
) -> "capo_assurance.types.chat_output.ChatOutput":
    """<p>Starts a streaming chat turn with the AWS Assurance agent. Returns an event stream of chat events, including chunks, tool calls, and errors.</p>

    Args:
        message: <p>The chat message to send to the AWS Assurance agent.</p>
        session_id: <p>The session to continue. Pass the <code>sessionId</code> returned by a previous <code>Chat</code> call to continue that session. If you omit it, AWS Assurance starts a new session. If the session doesn't exist or has expired, the operation returns <code>ResourceNotFoundException</code>. If the format isn't valid, the operation returns <code>ValidationException</code>.</p>
        environment_arn: <p>The ARN of this governance environment.</p>
        expected_sequence_number: <p>The sequence number of the last message you received. If the service detects a more recent sequence number, the request fails with <code>ConflictException</code>, indicating a concurrent update.</p>

    Raises:
        capo_assurance.errors.access_denied_exception.AccessDeniedException: <p>You do not have sufficient access to perform this action. This error occurs when the request is unauthenticated, or is authenticated but lacks permission to invoke the operation.</p>
        capo_assurance.errors.conflict_exception.ConflictException: <p>A conflict occurred (for example, resource already exists).</p>
        capo_assurance.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred.</p>
        capo_assurance.errors.resource_not_found_exception.ResourceNotFoundException: <p>The requested resource was not found.</p>
        capo_assurance.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The request would exceed a service quota.</p>
        capo_assurance.errors.throttling_exception.ThrottlingException: <p>The request was throttled.</p>
        capo_assurance.errors.validation_exception.ValidationException: <p>The request failed validation.</p>
        capo_assurance.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Continue a chat session
        Sends a follow-up question to the AWS Assurance agent to review the open controls in a PCI-DSS assessment.

        >>> await client.chat(message='Summarize the open controls in my PCI-DSS assessment.', session_id='a1b2c3d4-5678-90ab-cdef-EXAMPLE88888', environment_arn='arn:aws:assurance:us-east-1:111122223333:environment/a1b2c3d4-5678-90ab-cdef-EXAMPLE11111', expected_sequence_number=2)
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_assurance.types.chat_input.ChatInput]",
    ) -> AsyncOperationResponse["capo_assurance.types.chat_output.ChatOutput"]:
        import capo_assurance._operations.assurance.chat

        (
            output,
            http_response,
        ) = await capo_assurance._operations.assurance.chat.async_chat(
            req.options, req.input
        )
        awatch_event_stream(output, "event_stream", req.options)
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_assurance.types.chat_input.ChatInput",
    ) -> dict[str, Any]:
        import capo_assurance.types.chat_input

        return capo_assurance.types.chat_input.redact_sensitive(input_)

    def _redact_output(
        output: "capo_assurance.types.chat_output.ChatOutput",
    ) -> dict[str, Any]:
        import capo_assurance.types.chat_output

        return capo_assurance.types.chat_output.redact_sensitive(output)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "Chat", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_assurance.types.chat_input.ChatInput = {
        "message": message,
        "environment_arn": environment_arn,
    }
    if session_id is not None:
        input_["session_id"] = session_id
    if expected_sequence_number is not None:
        input_["expected_sequence_number"] = expected_sequence_number

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