mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
refactor(action-executor): emit action-finished state hint and trigger cognition turn on executable completion
This commit is contained in:
@@ -105,12 +105,12 @@ public class ActionExecutor extends AbstractAgentModule.Standalone {
|
|||||||
if (action instanceof ExecutableAction executableAction) {
|
if (action instanceof ExecutableAction executableAction) {
|
||||||
if (action.getStatus() == Action.Status.FAILED) {
|
if (action.getStatus() == Action.Status.FAILED) {
|
||||||
ensureExecutableResult(executableAction, true, null);
|
ensureExecutableResult(executableAction, true, null);
|
||||||
blockManager.emitActionFinishedBlock(executableAction);
|
emitExecutableActionFinished(executableAction);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
action.setStatus(Action.Status.SUCCESS);
|
action.setStatus(Action.Status.SUCCESS);
|
||||||
ensureExecutableResult(executableAction, false, null);
|
ensureExecutableResult(executableAction, false, null);
|
||||||
blockManager.emitActionFinishedBlock(executableAction);
|
emitExecutableActionFinished(executableAction);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (action.getStatus() == Action.Status.FAILED) {
|
if (action.getStatus() == Action.Status.FAILED) {
|
||||||
@@ -122,7 +122,7 @@ public class ActionExecutor extends AbstractAgentModule.Standalone {
|
|||||||
action.setStatus(Action.Status.FAILED);
|
action.setStatus(Action.Status.FAILED);
|
||||||
if (action instanceof ExecutableAction executableAction) {
|
if (action instanceof ExecutableAction executableAction) {
|
||||||
ensureExecutableResult(executableAction, true, e.getLocalizedMessage());
|
ensureExecutableResult(executableAction, true, e.getLocalizedMessage());
|
||||||
blockManager.emitActionFinishedBlock(executableAction);
|
emitExecutableActionFinished(executableAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -133,6 +133,15 @@ public class ActionExecutor extends AbstractAgentModule.Standalone {
|
|||||||
action.setStatus(Action.Status.FAILED);
|
action.setStatus(Action.Status.FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void emitExecutableActionFinished(ExecutableAction executableAction) {
|
||||||
|
blockManager.emitActionFinishedBlock(executableAction);
|
||||||
|
cognitionCapability.initiateTurn(
|
||||||
|
"An executable action has finished. Check the latest action-finished state and inform the user of the outcome if it is relevant to the current conversation.",
|
||||||
|
executableAction.getSource(),
|
||||||
|
"action_planner"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private void handleStateAction(StateAction stateAction) {
|
private void handleStateAction(StateAction stateAction) {
|
||||||
if (closed.get()) {
|
if (closed.get()) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import work.slhaf.partner.core.action.entity.intervention.MetaIntervention;
|
|||||||
import work.slhaf.partner.core.cognition.BlockContent;
|
import work.slhaf.partner.core.cognition.BlockContent;
|
||||||
import work.slhaf.partner.core.cognition.ContextBlock;
|
import work.slhaf.partner.core.cognition.ContextBlock;
|
||||||
import work.slhaf.partner.core.cognition.ContextWorkspace;
|
import work.slhaf.partner.core.cognition.ContextWorkspace;
|
||||||
|
import work.slhaf.partner.module.StateHintContent;
|
||||||
import work.slhaf.partner.module.action.executor.entity.HistoryAction;
|
import work.slhaf.partner.module.action.executor.entity.HistoryAction;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
@@ -382,6 +383,7 @@ class ExecutingActionBlockManager {
|
|||||||
14,
|
14,
|
||||||
24
|
24
|
||||||
));
|
));
|
||||||
|
contextWorkspace.register(buildActionFinishedStateHintBlock(snapshot, emittedAt, event));
|
||||||
}
|
}
|
||||||
|
|
||||||
private @NotNull BlockContent buildActionFinishedAbstractBlock(ExecutableActionSnapshot snapshot, String blockName, String event) {
|
private @NotNull BlockContent buildActionFinishedAbstractBlock(ExecutableActionSnapshot snapshot, String blockName, String event) {
|
||||||
@@ -406,6 +408,24 @@ class ExecutingActionBlockManager {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private @NotNull ContextBlock buildActionFinishedStateHintBlock(ExecutableActionSnapshot snapshot, String emittedAt, String event) {
|
||||||
|
return StateHintContent.createBlock(new StateHintContent(
|
||||||
|
SOURCE,
|
||||||
|
"An executable action has finished."
|
||||||
|
) {
|
||||||
|
@Override
|
||||||
|
public void fillStateContent(@NotNull Document document, @NotNull Element stateElement) {
|
||||||
|
appendTextElement(document, stateElement, "event", event);
|
||||||
|
appendTextElement(document, stateElement, "emitted_at", emittedAt);
|
||||||
|
appendTextElement(document, stateElement, "action_id", snapshot.getUuid());
|
||||||
|
appendTextElement(document, stateElement, "final_status", snapshot.getStatus().name().toLowerCase(Locale.ROOT));
|
||||||
|
appendTextElement(document, stateElement, "description", snapshot.getDescription());
|
||||||
|
appendTextElement(document, stateElement, "result", snapshot.getResult());
|
||||||
|
appendTextElement(document, stateElement, "source_user", snapshot.getSource());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private String emittedAt() {
|
private String emittedAt() {
|
||||||
return ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
return ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user