Skip to content

Context Strategy API

api_delete_context_strategy(cs_id)

Deletes a context strategy identified by its ID.

This API endpoint interfaces with the ContextStrategy.delete method to remove a context strategy from the system. It is used to manage the available context strategies by allowing for their removal when they are no longer needed.

Parameters:

Name Type Description Default
cs_id str

The unique identifier of the context strategy to be deleted.

required

Returns:

Name Type Description
bool bool

True if the context strategy was successfully deleted.

Raises:

Type Description
Exception

If the deletion process encounters an error.

Source code in moonshot/src/api/api_context_strategy.py
@validate_call
def api_delete_context_strategy(cs_id: str) -> bool:
    """
    Deletes a context strategy identified by its ID.

    This API endpoint interfaces with the `ContextStrategy.delete` method to remove a context strategy from the system.
    It is used to manage the available context strategies by allowing for their removal when they are no longer needed.

    Args:
        cs_id (str): The unique identifier of the context strategy to be deleted.

    Returns:
        bool: True if the context strategy was successfully deleted.

    Raises:
        Exception: If the deletion process encounters an error.
    """
    return ContextStrategy.delete(cs_id)

api_get_all_context_strategies()

Retrieves and returns the names of all context strategies currently available.

This API endpoint interfaces with the ContextStrategy.get_all_context_strategy_names method to fetch a list of all context strategy names. It's designed for clients that need to know what context strategies are available for use in sessions or other components of the system.

Returns:

Type Description
list[str]

list[str]: A list of strings, each representing the name of a context strategy.

Source code in moonshot/src/api/api_context_strategy.py
def api_get_all_context_strategies() -> list[str]:
    """
    Retrieves and returns the names of all context strategies currently available.

    This API endpoint interfaces with the `ContextStrategy.get_all_context_strategy_names` method to fetch a list
    of all context strategy names. It's designed for clients that need to know what context strategies are available for
    use in sessions or other components of the system.

    Returns:
        list[str]: A list of strings, each representing the name of a context strategy.
    """
    return ContextStrategy.get_all_context_strategies()

api_get_all_context_strategy_metadata()

Retrieves metadata for all context strategy modules.

This function retrieves the metadata for all available context strategies and returns a list of metadata dictionaries.

Returns:

Name Type Description
list list

A list of attack module metadata.

Source code in moonshot/src/api/api_context_strategy.py
def api_get_all_context_strategy_metadata() -> list:
    """
    Retrieves metadata for all context strategy modules.

    This function retrieves the metadata for all available context strategies and
    returns a list of metadata dictionaries.

    Returns:
        list: A list of attack module metadata.
    """

    return [
        ContextStrategy.load(context_strategy_name).get_metadata()  # type: ignore ; ducktyping
        for context_strategy_name in ContextStrategy.get_all_context_strategies()
    ]