Skip to content

traverse_agent_context async

traverse_agent_context(
    agent_context_id: AgentContextIdentifier,
    node_id: GenericNodeId,
    traversal_strategy: TraversalStrategy,
    *,
    config_overrides: Optional[AsyncContextClientConfig] = None,
    max_results: Optional[int] = None,
    next_token: Optional[str] = None,
) -> TraverseAgentContextResponse

Returns the neighbors of a seed node in an agent context, each with its properties, hop distance, and the edges that connect it to the seed. To get the seed node ID, call SearchAgentContext.

Parameters:

  • max_results (Optional[int], default: None ) –

    Maximum total neighbors to return per page.

  • next_token (Optional[str], default: None ) –

    Opaque continuation token from a prior response. Omit on the first page.

  • agent_context_id (AgentContextIdentifier) –

    The agent context to traverse, by ID or full Amazon Resource Name (ARN).

  • node_id (GenericNodeId) –

    The ID of the seed node to start traversal from.

  • traversal_strategy (TraversalStrategy) –

    Traversal directives: which edge types to follow, direction, and max depth.

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:

Traverse from a node The following example follows outgoing HAS_COLUMN edges one hop from an AWS Glue table node, and returns two of the table's columns with the edge that connects each one to the table.

>>> await client.traverse_agent_context(agent_context_id='ac-0123456789abcdef0123456789abcdef', node_id='glueTable:arn%3Aaws%3Aglue%3Aus-east-1%3A111122223333%3Atable%2Fsales_analytics%2Forders', max_results=2, traversal_strategy={'edgeTypes': ['AWS::CONTEXT::HAS_COLUMN'], 'direction': 'OUTGOING', 'maxDepth': 1})
Source code in docs_src/capo_context/_services/async_context.py
async def traverse_agent_context(
    self,
    agent_context_id: "capo_context.types.agent_context_identifier.AgentContextIdentifier",
    node_id: "capo_context.types.generic_node_id.GenericNodeId",
    traversal_strategy: "capo_context.types.traversal_strategy.TraversalStrategy",
    *,
    config_overrides: Optional[AsyncContextClientConfig] = None,
    max_results: Optional[int] = None,
    next_token: Optional[str] = None,
) -> "capo_context.types.traverse_agent_context_response.TraverseAgentContextResponse":
    """<p>Returns the neighbors of a seed node in an agent context, each with its properties, hop distance, and the edges that connect it to the seed. To get the seed node ID, call SearchAgentContext.</p>

    Args:
        max_results: <p>Maximum total neighbors to return per page.</p>
        next_token: <p>Opaque continuation token from a prior response. Omit on the first page.</p>
        agent_context_id: <p>The agent context to traverse, by ID or full Amazon Resource Name (ARN).</p>
        node_id: <p>The ID of the seed node to start traversal from.</p>
        traversal_strategy: <p>Traversal directives: which edge types to follow, direction, and max depth.</p>

    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:
        Traverse from a node
        The following example follows outgoing HAS_COLUMN edges one hop from an AWS Glue table node, and returns two of the table's columns with the edge that connects each one to the table.

        >>> await client.traverse_agent_context(agent_context_id='ac-0123456789abcdef0123456789abcdef', node_id='glueTable:arn%3Aaws%3Aglue%3Aus-east-1%3A111122223333%3Atable%2Fsales_analytics%2Forders', max_results=2, traversal_strategy={'edgeTypes': ['AWS::CONTEXT::HAS_COLUMN'], 'direction': 'OUTGOING', 'maxDepth': 1})
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_context.types.traverse_agent_context_request.TraverseAgentContextRequest]",
    ) -> AsyncOperationResponse[
        "capo_context.types.traverse_agent_context_response.TraverseAgentContextResponse"
    ]:
        import capo_context._operations.context.traverse_agent_context

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

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

        return capo_context.types.traverse_agent_context_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("TraverseAgentContext", redact_output=_redact_output),
    )
    input_: capo_context.types.traverse_agent_context_request.TraverseAgentContextRequest = {
        "agent_context_id": agent_context_id,
        "node_id": node_id,
        "traversal_strategy": traversal_strategy,
    }
    if max_results is not None:
        input_["max_results"] = max_results
    if next_token is not None:
        input_["next_token"] = next_token

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