Skip to content

azad.task_lifecycle Module

azad.task_lifecycle

Parameter type definitions and utilities for task lifecycle tools.

Attributes

Classes

TaskLifecycleType

Bases: str, Enum

Enum defining task lifecycle operation types.

Functions

extract_parameters_by_type

extract_parameters_by_type(tool_result: Dict[str, Any], tool_metadata: ToolMetadata, param_type: TaskParameterType) -> List[Any]

Extract parameters of a specific type from tool results.

Parameters:

  • tool_result (Dict[str, Any]) –

    The tool execution result

  • tool_metadata (ToolMetadata) –

    The tool metadata

  • param_type (TaskParameterType) –

    The parameter type to extract

Returns:

  • List[Any]

    List of values for parameters of the specified type

Source code in azad/task_lifecycle.py
def extract_parameters_by_type(
    tool_result: Dict[str, Any], 
    tool_metadata: ToolMetadata,
    param_type: TaskParameterType
) -> List[Any]:
    """
    Extract parameters of a specific type from tool results.

    Args:
        tool_result: The tool execution result
        tool_metadata: The tool metadata
        param_type: The parameter type to extract

    Returns:
        List of values for parameters of the specified type
    """
    values = []

    # Check if tool metadata has output keypairs defined
    output_keypairs = tool_metadata.task_lifecycle_output_keypairs

    if output_keypairs:
        # Use the keypairs mapping for direct parameter extraction
        for param_name, parameter_type in output_keypairs.items():
            # Check if this parameter matches the requested type
            if parameter_type == param_type:
                # Extract the value if it exists in the tool result
                if param_name in tool_result:
                    values.append(tool_result[param_name])
    else:
        # Fallback for tools without keypairs - basic parameter extraction
        # Just look for direct keys in the result
        for param_name in tool_result:
            if param_name == param_type.value:
                values.append(tool_result[param_name])

    return values

get_parameter_key_name

get_parameter_key_name(tool_metadata: ToolMetadata, param_type: TaskParameterType) -> Optional[str]

Get the key name for a specific parameter type from tool metadata.

Parameters:

Returns:

  • Optional[str]

    The key name if found, None otherwise

Source code in azad/task_lifecycle.py
def get_parameter_key_name(
    tool_metadata: ToolMetadata,
    param_type: TaskParameterType
) -> Optional[str]:
    """
    Get the key name for a specific parameter type from tool metadata.

    Args:
        tool_metadata: The tool metadata
        param_type: The parameter type to look up

    Returns:
        The key name if found, None otherwise
    """
    # Check if tool metadata has output keypairs defined
    output_keypairs = tool_metadata.task_lifecycle_output_keypairs

    if output_keypairs:
        # Look for a parameter of the specified type
        for param_name, parameter_type in output_keypairs.items():
            if parameter_type == param_type:
                return param_name

    # Fallback - use the parameter type value as the key
    # This assumes direct mapping from enum values to keys
    return param_type.value