Skip to content

invoke_flow async

invoke_flow(
    flow_identifier: FlowIdentifier,
    flow_alias_identifier: FlowAliasIdentifier,
    inputs: FlowInputs,
    *,
    config_overrides: Optional[AsyncBedrockAgentRuntimeClientConfig] = None,
    enable_trace: Optional[bool] = None,
    model_performance_configuration: Optional[ModelPerformanceConfiguration] = None,
    execution_id: Optional[FlowExecutionId] = None,
) -> AsyncGenerator[InvokeFlowResponse]

Invokes an alias of a flow to run the inputs that you specify and return the output of each node as a stream. If there's an error, the error is returned. For more information, see Test a flow in Amazon Bedrock in the Amazon Bedrock User Guide.

The CLI doesn't support streaming operations in Amazon Bedrock, including InvokeFlow.

Parameters:

Raises:

  • AccessDeniedException –

    The request is denied because of missing access permissions. Check your permissions and retry your request.

  • BadGatewayException –

    There was an issue with a dependency due to a server issue. Retry your request.

  • ConflictException –

    There was a conflict performing an operation. Resolve the conflict and retry your request.

  • DependencyFailedException –

    There was an issue with a dependency. Check the resource configurations and retry the request.

  • InternalServerException –

    An internal server error occurred. Retry your request.

  • ResourceNotFoundException –

    The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.

  • ServiceQuotaExceededException –

    The number of requests exceeds the service quota. Resubmit your request later.

  • ThrottlingException –

    The number of requests exceeds the limit. Resubmit your request later.

  • ValidationException –

    Input validation failed. Check your request parameters and retry the request.

  • UnknownServiceError –

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

Source code in docs_src/capo_bedrock_agent_runtime/_services/async_bedrock_agent_runtime.py
@asynccontextmanager
async def invoke_flow(
    self,
    flow_identifier: "capo_bedrock_agent_runtime.types.flow_identifier.FlowIdentifier",
    flow_alias_identifier: "capo_bedrock_agent_runtime.types.flow_alias_identifier.FlowAliasIdentifier",
    inputs: "capo_bedrock_agent_runtime.types.flow_inputs.FlowInputs",
    *,
    config_overrides: Optional[AsyncBedrockAgentRuntimeClientConfig] = None,
    enable_trace: Optional[bool] = None,
    model_performance_configuration: Optional[
        "capo_bedrock_agent_runtime.types.model_performance_configuration.ModelPerformanceConfiguration"
    ] = None,
    execution_id: Optional[
        "capo_bedrock_agent_runtime.types.flow_execution_id.FlowExecutionId"
    ] = None,
) -> "AsyncGenerator[capo_bedrock_agent_runtime.types.invoke_flow_response.InvokeFlowResponse]":
    """<p>Invokes an alias of a flow to run the inputs that you specify and return the output of each node as a stream. If there's an error, the error is returned. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/flows-test.html">Test a flow in Amazon Bedrock</a> in the <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-service.html">Amazon Bedrock User Guide</a>.</p> <note> <p>The CLI doesn't support streaming operations in Amazon Bedrock, including <code>InvokeFlow</code>.</p> </note>

    Args:
        flow_identifier: <p>The unique identifier of the flow.</p>
        flow_alias_identifier: <p>The unique identifier of the flow alias.</p>
        inputs: <p>A list of objects, each containing information about an input into the flow.</p>
        enable_trace: <p>Specifies whether to return the trace for the flow or not. Traces track inputs and outputs for nodes in the flow. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/flows-trace.html">Track each step in your prompt flow by viewing its trace in Amazon Bedrock</a>.</p>
        model_performance_configuration: <p>Model performance settings for the request.</p>
        execution_id: <p>The unique identifier for the current flow execution. If you don't provide a value, Amazon Bedrock creates the identifier for you. </p>

    Raises:
        capo_bedrock_agent_runtime.errors.access_denied_exception.AccessDeniedException: <p>The request is denied because of missing access permissions. Check your permissions and retry your request.</p>
        capo_bedrock_agent_runtime.errors.bad_gateway_exception.BadGatewayException: <p>There was an issue with a dependency due to a server issue. Retry your request.</p>
        capo_bedrock_agent_runtime.errors.conflict_exception.ConflictException: <p>There was a conflict performing an operation. Resolve the conflict and retry your request.</p>
        capo_bedrock_agent_runtime.errors.dependency_failed_exception.DependencyFailedException: <p>There was an issue with a dependency. Check the resource configurations and retry the request.</p>
        capo_bedrock_agent_runtime.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred. Retry your request.</p>
        capo_bedrock_agent_runtime.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.</p>
        capo_bedrock_agent_runtime.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The number of requests exceeds the service quota. Resubmit your request later.</p>
        capo_bedrock_agent_runtime.errors.throttling_exception.ThrottlingException: <p>The number of requests exceeds the limit. Resubmit your request later.</p>
        capo_bedrock_agent_runtime.errors.validation_exception.ValidationException: <p>Input validation failed. Check your request parameters and retry the request.</p>
        capo_bedrock_agent_runtime.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_bedrock_agent_runtime.types.invoke_flow_request.InvokeFlowRequest]",
    ) -> AsyncOperationResponse[
        "capo_bedrock_agent_runtime.types.invoke_flow_response.InvokeFlowResponse"
    ]:
        import capo_bedrock_agent_runtime._operations.amazon_bedrock_agent_run_time_service.invoke_flow

        (
            output,
            http_response,
        ) = await capo_bedrock_agent_runtime._operations.amazon_bedrock_agent_run_time_service.invoke_flow.async_invoke_flow(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_bedrock_agent_runtime.types.invoke_flow_request.InvokeFlowRequest",
    ) -> dict[str, Any]:
        import capo_bedrock_agent_runtime.types.invoke_flow_request

        return (
            capo_bedrock_agent_runtime.types.invoke_flow_request.redact_sensitive(
                input_
            )
        )

    def _redact_output(
        output: "capo_bedrock_agent_runtime.types.invoke_flow_response.InvokeFlowResponse",
    ) -> dict[str, Any]:
        import capo_bedrock_agent_runtime.types.invoke_flow_response

        return (
            capo_bedrock_agent_runtime.types.invoke_flow_response.redact_sensitive(
                output
            )
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "InvokeFlow", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_bedrock_agent_runtime.types.invoke_flow_request.InvokeFlowRequest = {
        "flow_identifier": flow_identifier,
        "flow_alias_identifier": flow_alias_identifier,
        "inputs": inputs,
    }
    if enable_trace is not None:
        input_["enable_trace"] = enable_trace
    if model_performance_configuration is not None:
        input_["model_performance_configuration"] = model_performance_configuration
    if execution_id is not None:
        input_["execution_id"] = execution_id

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