mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
refactor(action): emit full execution lifecycle/correction blocks and carry correction reason in CorrectorResult
This commit is contained in:
@@ -20,14 +20,18 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class ActionExecutor extends AbstractAgentModule.Standalone {
|
public class ActionExecutor extends AbstractAgentModule.Standalone {
|
||||||
|
|
||||||
private static final int MAX_EXTRACTOR_ATTEMPTS = 3;
|
private static final int MAX_EXTRACTOR_ATTEMPTS = 3;
|
||||||
|
|
||||||
private final AssemblyHelper assemblyHelper = new AssemblyHelper();
|
private final AssemblyHelper assemblyHelper = new AssemblyHelper();
|
||||||
|
|
||||||
@InjectCapability
|
@InjectCapability
|
||||||
private ActionCapability actionCapability;
|
private ActionCapability actionCapability;
|
||||||
@InjectCapability
|
@InjectCapability
|
||||||
private MemoryCapability memoryCapability;
|
private MemoryCapability memoryCapability;
|
||||||
@InjectCapability
|
@InjectCapability
|
||||||
private CognitionCapability cognitionCapability;
|
private CognitionCapability cognitionCapability;
|
||||||
|
|
||||||
@InjectModule
|
@InjectModule
|
||||||
private ParamsExtractor paramsExtractor;
|
private ParamsExtractor paramsExtractor;
|
||||||
@InjectModule
|
@InjectModule
|
||||||
@@ -35,6 +39,8 @@ public class ActionExecutor extends AbstractAgentModule.Standalone {
|
|||||||
@InjectModule
|
@InjectModule
|
||||||
private ActionCorrectionRecognizer actionCorrectionRecognizer;
|
private ActionCorrectionRecognizer actionCorrectionRecognizer;
|
||||||
|
|
||||||
|
private ExecutingActionBlockManager blockManager;
|
||||||
|
|
||||||
private ExecutorService virtualExecutor;
|
private ExecutorService virtualExecutor;
|
||||||
private ExecutorService platformExecutor;
|
private ExecutorService platformExecutor;
|
||||||
private RunnerClient runnerClient;
|
private RunnerClient runnerClient;
|
||||||
@@ -44,6 +50,7 @@ public class ActionExecutor extends AbstractAgentModule.Standalone {
|
|||||||
virtualExecutor = actionCapability.getExecutor(ActionCore.ExecutorType.VIRTUAL);
|
virtualExecutor = actionCapability.getExecutor(ActionCore.ExecutorType.VIRTUAL);
|
||||||
platformExecutor = actionCapability.getExecutor(ActionCore.ExecutorType.PLATFORM);
|
platformExecutor = actionCapability.getExecutor(ActionCore.ExecutorType.PLATFORM);
|
||||||
runnerClient = actionCapability.runnerClient();
|
runnerClient = actionCapability.runnerClient();
|
||||||
|
blockManager = new ExecutingActionBlockManager(cognitionCapability.contextWorkspace());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(Action action) {
|
public void execute(Action action) {
|
||||||
@@ -76,9 +83,13 @@ 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);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
action.setStatus(Action.Status.SUCCESS);
|
||||||
ensureExecutableResult(executableAction, false, null);
|
ensureExecutableResult(executableAction, false, null);
|
||||||
|
blockManager.emitActionFinishedBlock(executableAction);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (action.getStatus() == Action.Status.FAILED) {
|
if (action.getStatus() == Action.Status.FAILED) {
|
||||||
return;
|
return;
|
||||||
@@ -89,6 +100,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -100,6 +112,7 @@ public class ActionExecutor extends AbstractAgentModule.Standalone {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleStateAction(StateAction stateAction) {
|
private void handleStateAction(StateAction stateAction) {
|
||||||
|
blockManager.emitStateActionTriggeredBlock(stateAction);
|
||||||
stateAction.getTrigger().onTrigger();
|
stateAction.getTrigger().onTrigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +130,9 @@ public class ActionExecutor extends AbstractAgentModule.Standalone {
|
|||||||
// 注册执行中行动
|
// 注册执行中行动
|
||||||
val phaser = new Phaser();
|
val phaser = new Phaser();
|
||||||
executableAction.setStatus(Action.Status.EXECUTING);
|
executableAction.setStatus(Action.Status.EXECUTING);
|
||||||
|
|
||||||
|
blockManager.emitActionLaunchedBlock(executableAction);
|
||||||
|
|
||||||
// 开始执行
|
// 开始执行
|
||||||
val stageCursor = new Object() {
|
val stageCursor = new Object() {
|
||||||
int stageCount;
|
int stageCount;
|
||||||
@@ -167,7 +183,11 @@ public class ActionExecutor extends AbstractAgentModule.Standalone {
|
|||||||
// 立即尝试推进,本次推进中,如果前方仍有未执行 stage,将执行一次阶段推进
|
// 立即尝试推进,本次推进中,如果前方仍有未执行 stage,将执行一次阶段推进
|
||||||
stageCursor.requestAdvance();
|
stageCursor.requestAdvance();
|
||||||
}
|
}
|
||||||
boolean shouldRunCorrector = hasFailedMetaAction(metaActions);
|
|
||||||
|
blockManager.emitActionStageSettledBlock(executableAction);
|
||||||
|
|
||||||
|
boolean hasFailedMetaAction = hasFailedMetaAction(metaActions);
|
||||||
|
boolean shouldRunCorrector = hasFailedMetaAction;
|
||||||
try {
|
try {
|
||||||
if (!shouldRunCorrector) {
|
if (!shouldRunCorrector) {
|
||||||
val recognizerResult = resolveRecognizerResult(recognizerRecord);
|
val recognizerResult = resolveRecognizerResult(recognizerRecord);
|
||||||
@@ -177,6 +197,13 @@ public class ActionExecutor extends AbstractAgentModule.Standalone {
|
|||||||
val correctorInput = assemblyHelper.buildCorrectorInput(executableAction);
|
val correctorInput = assemblyHelper.buildCorrectorInput(executableAction);
|
||||||
val correctorResult = actionCorrector.execute(correctorInput);
|
val correctorResult = actionCorrector.execute(correctorInput);
|
||||||
actionCapability.handleInterventions(correctorResult.getMetaInterventionList(), executableAction);
|
actionCapability.handleInterventions(correctorResult.getMetaInterventionList(), executableAction);
|
||||||
|
|
||||||
|
blockManager.emitActionCorrectionBlock(
|
||||||
|
executableAction,
|
||||||
|
hasFailedMetaAction ? "has_failed_meta_action" : correctorResult.getCorrectionReason(),
|
||||||
|
correctorResult.getMetaInterventionList()
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ import java.util.List;
|
|||||||
@Data
|
@Data
|
||||||
public class CorrectorResult {
|
public class CorrectorResult {
|
||||||
private List<MetaIntervention> metaInterventionList;
|
private List<MetaIntervention> metaInterventionList;
|
||||||
|
private String correctionReason;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user