mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 16:53:04 +08:00
refactor(Action): make attribute status available for all implementations of Action, StateAction needs to present its trigger status also
This commit is contained in:
@@ -25,57 +25,11 @@ sealed class Action {
|
|||||||
*/
|
*/
|
||||||
abstract val description: String
|
abstract val description: String
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
sealed interface Schedulable {
|
|
||||||
|
|
||||||
val scheduleType: ScheduleType
|
|
||||||
val scheduleContent: String
|
|
||||||
val uuid: String
|
|
||||||
var enabled: Boolean
|
|
||||||
|
|
||||||
enum class ScheduleType {
|
|
||||||
CYCLE,
|
|
||||||
ONCE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 行动模块传递的行动数据,包含行动uuid、倾向、状态、行动链、结果、发起原因、行动描述等信息。
|
|
||||||
*/
|
|
||||||
sealed class ExecutableAction : Action() {
|
|
||||||
/**
|
|
||||||
* 行动倾向
|
|
||||||
*/
|
|
||||||
abstract val tendency: String
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 行动状态
|
* 行动状态
|
||||||
*/
|
*/
|
||||||
var status: Status = Status.PREPARE
|
var status: Status = Status.PREPARE
|
||||||
|
|
||||||
/**
|
|
||||||
* 行动链
|
|
||||||
*/
|
|
||||||
abstract val actionChain: MutableMap<Int, MutableList<MetaAction>>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 行动阶段(当前阶段)
|
|
||||||
*/
|
|
||||||
var executingStage: Int = 0
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 行动结果
|
|
||||||
*/
|
|
||||||
lateinit var result: String
|
|
||||||
|
|
||||||
val history: MutableMap<Int, MutableList<HistoryAction>> = mutableMapOf()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修复上下文
|
|
||||||
*/
|
|
||||||
val additionalContext: MutableMap<Int, MutableList<String>> = mutableMapOf()
|
|
||||||
|
|
||||||
enum class Status {
|
enum class Status {
|
||||||
/**
|
/**
|
||||||
* 执行成功
|
* 执行成功
|
||||||
@@ -104,6 +58,52 @@ sealed class ExecutableAction : Action() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sealed interface Schedulable {
|
||||||
|
|
||||||
|
val scheduleType: ScheduleType
|
||||||
|
val scheduleContent: String
|
||||||
|
val uuid: String
|
||||||
|
var enabled: Boolean
|
||||||
|
|
||||||
|
enum class ScheduleType {
|
||||||
|
CYCLE,
|
||||||
|
ONCE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 行动模块传递的行动数据,包含行动uuid、倾向、状态、行动链、结果、发起原因、行动描述等信息。
|
||||||
|
*/
|
||||||
|
sealed class ExecutableAction : Action() {
|
||||||
|
/**
|
||||||
|
* 行动倾向
|
||||||
|
*/
|
||||||
|
abstract val tendency: String
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 行动链
|
||||||
|
*/
|
||||||
|
abstract val actionChain: MutableMap<Int, MutableList<MetaAction>>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 行动阶段(当前阶段)
|
||||||
|
*/
|
||||||
|
var executingStage: Int = 0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 行动结果
|
||||||
|
*/
|
||||||
|
lateinit var result: String
|
||||||
|
|
||||||
|
val history: MutableMap<Int, MutableList<HistoryAction>> = mutableMapOf()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修复上下文
|
||||||
|
*/
|
||||||
|
val additionalContext: MutableMap<Int, MutableList<String>> = mutableMapOf()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 计划行动数据类,继承自[Action],扩展了[Schedulable]相关调度属性,用于标识计划类型(单次还是周期性任务)和计划内容
|
* 计划行动数据类,继承自[Action],扩展了[Schedulable]相关调度属性,用于标识计划类型(单次还是周期性任务)和计划内容
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import work.slhaf.partner.api.agent.factory.component.annotation.InjectModule;
|
|||||||
import work.slhaf.partner.core.action.ActionCapability;
|
import work.slhaf.partner.core.action.ActionCapability;
|
||||||
import work.slhaf.partner.core.action.ActionCore;
|
import work.slhaf.partner.core.action.ActionCore;
|
||||||
import work.slhaf.partner.core.action.entity.*;
|
import work.slhaf.partner.core.action.entity.*;
|
||||||
import work.slhaf.partner.core.action.entity.ExecutableAction.Status;
|
|
||||||
import work.slhaf.partner.core.action.runner.RunnerClient;
|
import work.slhaf.partner.core.action.runner.RunnerClient;
|
||||||
import work.slhaf.partner.core.cognation.CognationCapability;
|
import work.slhaf.partner.core.cognation.CognationCapability;
|
||||||
import work.slhaf.partner.core.memory.MemoryCapability;
|
import work.slhaf.partner.core.memory.MemoryCapability;
|
||||||
@@ -62,19 +61,19 @@ public class ActionExecutor extends AbstractAgentModule.Standalone {
|
|||||||
for (ExecutableAction executableAction : actions) {
|
for (ExecutableAction executableAction : actions) {
|
||||||
platformExecutor.execute(() -> {
|
platformExecutor.execute(() -> {
|
||||||
val source = executableAction.getSource();
|
val source = executableAction.getSource();
|
||||||
if (executableAction.getStatus() != Status.PREPARE) {
|
if (executableAction.getStatus() != Action.Status.PREPARE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
val actionChain = executableAction.getActionChain();
|
val actionChain = executableAction.getActionChain();
|
||||||
if (actionChain.isEmpty()) {
|
if (actionChain.isEmpty()) {
|
||||||
executableAction.setStatus(Status.FAILED);
|
executableAction.setStatus(Action.Status.FAILED);
|
||||||
executableAction.setResult("行动链为空");
|
executableAction.setResult("行动链为空");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 注册执行中行动
|
// 注册执行中行动
|
||||||
val phaser = new Phaser();
|
val phaser = new Phaser();
|
||||||
val phaserRecord = actionCapability.putPhaserRecord(phaser, executableAction);
|
val phaserRecord = actionCapability.putPhaserRecord(phaser, executableAction);
|
||||||
executableAction.setStatus(Status.EXECUTING);
|
executableAction.setStatus(Action.Status.EXECUTING);
|
||||||
// 开始执行
|
// 开始执行
|
||||||
val stageCursor = new Object() {
|
val stageCursor = new Object() {
|
||||||
int stageCount;
|
int stageCount;
|
||||||
@@ -138,13 +137,13 @@ public class ActionExecutor extends AbstractAgentModule.Standalone {
|
|||||||
} while (stageCursor.next());
|
} while (stageCursor.next());
|
||||||
// 结束
|
// 结束
|
||||||
actionCapability.removePhaserRecord(phaser);
|
actionCapability.removePhaserRecord(phaser);
|
||||||
if (executableAction.getStatus() != Status.FAILED) {
|
if (executableAction.getStatus() != Action.Status.FAILED) {
|
||||||
// 如果是 ScheduledActionData, 则重置 ActionData 内容,记录执行历史与最终结果
|
// 如果是 ScheduledActionData, 则重置 ActionData 内容,记录执行历史与最终结果
|
||||||
if (executableAction instanceof SchedulableExecutableAction scheduledActionData) {
|
if (executableAction instanceof SchedulableExecutableAction scheduledActionData) {
|
||||||
scheduledActionData.recordAndReset();
|
scheduledActionData.recordAndReset();
|
||||||
actionScheduler.schedule(Set.of(scheduledActionData));
|
actionScheduler.schedule(Set.of(scheduledActionData));
|
||||||
} else {
|
} else {
|
||||||
executableAction.setStatus(Status.SUCCESS);
|
executableAction.setStatus(Action.Status.SUCCESS);
|
||||||
}
|
}
|
||||||
// TODO 执行过后需要回写至任务上下文(recentCompletedTask),同时触发自对话信号进行确认并记录以及是否通知用户(触发与否需要机制进行匹配,在模块链路可增加 interaction gate 门控,判断此次对话作用于谁、由谁发出、何种性质、是否需要回应等)
|
// TODO 执行过后需要回写至任务上下文(recentCompletedTask),同时触发自对话信号进行确认并记录以及是否通知用户(触发与否需要机制进行匹配,在模块链路可增加 interaction gate 门控,判断此次对话作用于谁、由谁发出、何种性质、是否需要回应等)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user