def get_trace_component_for_action_execution(action_execution_db, liveaction_db):
    """
    Returns the trace_component compatible dict representation of an actionexecution.

    :param action_execution_db: ActionExecution to translate
    :type action_execution_db: ActionExecutionDB

    :param liveaction_db: LiveAction corresponding to the supplied ActionExecution
    :type liveaction_db: LiveActionDB

    :rtype: ``dict``
    """
    if not action_execution_db:
        raise ValueError("action_execution_db expected.")
    trace_component = {
        "id": str(action_execution_db.id),
        "ref": str(action_execution_db.action.get("ref", "")),
    }
    caused_by = {}
    parent_context = executions.get_parent_context(liveaction_db=liveaction_db)
    if liveaction_db and parent_context:
        caused_by["type"] = "action_execution"
        caused_by["id"] = liveaction_db.context["parent"].get("execution_id", None)
    elif action_execution_db.rule and action_execution_db.trigger_instance:
        # Once RuleEnforcement is available that can be used instead.
        caused_by["type"] = "rule"
        caused_by["id"] = "%s:%s" % (
            action_execution_db.rule["id"],
            action_execution_db.trigger_instance["id"],
        )

    trace_component["caused_by"] = caused_by
    return trace_component

    Returns the trace_component compatible dict representation of an actionexecution.

    :param action_execution_db: ActionExecution to translate
    :type action_execution_db: ActionExecutionDB

    :param liveaction_db: LiveAction corresponding to the supplied ActionExecution
    :type liveaction_db: LiveActionDB

    :rtype: ``dict``
    
st2common/st2common/services/trace.py