function action = WP_bot(percept)
%

persistent first intentions plan

% Initialize beliefs
if isempty(first)
    clear WP_beliefs
    WP_beliefs(0,0,[],0);  % NOOP to initialize beliefs
    intentions = [];
    plan = 0;
    first = 1;
end

% Get percepts
[WP_set,planes] = WP_rgbd2WP(percept.rgbd);

% Revise beliefs
WP_beliefs(4,0,0,WP_set);

options = WP_analyzer(intentions);

intentions = WP_filter(options);

plan = WP_plan_selection(intentions,plan,percept,planes,WP_set);

action = WP_plan2action(plan);

if WP_beliefs(1,12,'info',0)==1
    index = find(plan==intentions);
    plan = 0;
    if ~isempty(index)
        if index==1
            intentions = intentions(2:end);
        elseif index==length(intentions)
            intentions = intentions(1:end-1);
        else
            intentions = [intentions(1:index-1),intentions(index+1:end)];
        end
    end
    WP_beliefs(2,12,'info',0);
end

%if terminate signal, then save beliefs
if WP_beliefs(1,7,'info',0)==1
    WP_beliefs(3,0,'beliefs',0);
end
