mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
ActionExecutor 的执行流程规划完毕,具体逻辑待填充
- 调整了部分代码分布,移除了某些非必需的转发方法 - 新增几个 TODO 内容,后续工作已明确 这套调度方式看起来真的有些‘探索性质’了。实际上看起来有些像把 ReAct 的逻辑显式地进行了工程实现,不管是修复、依据状态选择行动单元生成还是阶段间针对行动单元的参数提取,在 ReAct Agent 中都是由一个智能体完成的。 但在这里,它要做的事情太多了,再加上 Partner 行动链的干预逻辑、幻觉参数又不可接受所以需要自对话或者用户干预,这些东西交给一个 ReAct 模块恐怕并不合适也不放心。所以这种显式模块划分应该更符合 Partner 行动模块的需求。 这点硬要说的话,应该还是在于‘ReAct 行为’并非 Partner 的全部吧。 不过谁知道呢,也许以后也会变,但这套至少现在看来是更能实现理想行为的
This commit is contained in:
@@ -4,7 +4,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import work.slhaf.partner.api.agent.factory.capability.annotation.InjectCapability;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.Init;
|
||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
||||
import work.slhaf.partner.core.action.ActionCapability;
|
||||
import work.slhaf.partner.core.action.ActionCore;
|
||||
@@ -20,7 +19,7 @@ import java.util.concurrent.Phaser;
|
||||
|
||||
@Slf4j
|
||||
@AgentSubModule
|
||||
public class ActionExecutor extends AgentRunningSubModule<List<ImmediateActionData>, Void> implements ActivateModel {
|
||||
public class ActionExecutor extends AgentRunningSubModule<List<ImmediateActionData>, Void> {
|
||||
|
||||
@InjectCapability
|
||||
private ActionCapability actionCapability;
|
||||
@@ -37,59 +36,49 @@ public class ActionExecutor extends AgentRunningSubModule<List<ImmediateActionDa
|
||||
@Override
|
||||
public Void execute(List<ImmediateActionData> immediateActions) {
|
||||
for (ImmediateActionData actionData : immediateActions) {
|
||||
handleActionData(actionData);
|
||||
virtualExecutor.execute(() -> {
|
||||
actionData.setStatus(ActionData.ActionStatus.EXECUTING);
|
||||
Map<Integer, List<MetaAction>> actionChain = actionData.getActionChain();
|
||||
List<MetaAction> virtual = new ArrayList<>();
|
||||
List<MetaAction> platform = new ArrayList<>();
|
||||
Phaser phaser = new Phaser();
|
||||
phaser.register();
|
||||
actionCapability.putPhaserRecord(phaser, actionData);
|
||||
List<Integer> orderList = new ArrayList<>(actionChain.keySet().stream().toList());
|
||||
orderList.sort(Integer::compareTo);
|
||||
try {
|
||||
for (Integer order : orderList) {
|
||||
List<MetaAction> metaActions = actionChain.get(order);
|
||||
for (MetaAction metaAction : metaActions) {
|
||||
// 根据io类型放入合适的列表
|
||||
if (metaAction.isIo()) {
|
||||
virtual.add(metaAction);
|
||||
} else {
|
||||
platform.add(metaAction);
|
||||
}
|
||||
}
|
||||
// 使用phaser来承担同组的动态任务新增
|
||||
runGroupAction(virtual, virtualExecutor, phaser);
|
||||
runGroupAction(platform, platformExecutor, phaser);
|
||||
phaser.arriveAndAwaitAdvance();
|
||||
virtual.clear();
|
||||
platform.clear();
|
||||
}
|
||||
} finally {
|
||||
phaser.arriveAndDeregister();
|
||||
actionCapability.removePhaserRecord(phaser);
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void handleActionData(ImmediateActionData actionData) {
|
||||
virtualExecutor.execute(() -> {
|
||||
actionData.setStatus(ActionData.ActionStatus.EXECUTING);
|
||||
Map<Integer, List<MetaAction>> actionChain = actionData.getActionChain();
|
||||
List<MetaAction> virtual = new ArrayList<>();
|
||||
List<MetaAction> platform = new ArrayList<>();
|
||||
Phaser phaser = new Phaser();
|
||||
phaser.register();
|
||||
actionCapability.putPhaserRecord(phaser, actionData);
|
||||
List<Integer> orderList = new ArrayList<>(actionChain.keySet().stream().toList());
|
||||
orderList.sort(Integer::compareTo);
|
||||
try {
|
||||
for (Integer order : orderList) {
|
||||
List<MetaAction> metaActions = actionChain.get(order);
|
||||
for (MetaAction metaAction : metaActions) {
|
||||
// 根据io类型放入合适的列表
|
||||
if (metaAction.isIo()) {
|
||||
virtual.add(metaAction);
|
||||
} else {
|
||||
platform.add(metaAction);
|
||||
}
|
||||
}
|
||||
runGroupAction(virtual, platform, phaser);
|
||||
phaser.arriveAndAwaitAdvance();
|
||||
virtual.clear();
|
||||
platform.clear();
|
||||
}
|
||||
} finally {
|
||||
phaser.arriveAndDeregister();
|
||||
actionCapability.removePhaserRecord(phaser);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// 使用phaser来承担同组的动态任务新增
|
||||
private void runGroupAction(List<MetaAction> virtual, List<MetaAction> platform,
|
||||
Phaser phaser) {
|
||||
runGroupAction(virtual, virtualExecutor, phaser);
|
||||
runGroupAction(platform, platformExecutor, phaser);
|
||||
}
|
||||
|
||||
private void runGroupAction(List<MetaAction> actions, ExecutorService executor, Phaser phaser) {
|
||||
phaser.bulkRegister(actions.size());
|
||||
for (MetaAction action : actions) {
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
//TODO 使用 LLM 填充行动参数信息
|
||||
//TODO 使用 ParamsExtractor 填充行动参数信息,如果已知内容不足以满足参数需求,则进行行动链调整(ActionRepairer)
|
||||
|
||||
actionCapability.execute(action);
|
||||
MetaAction.Result result = action.getResult();
|
||||
@@ -119,14 +108,4 @@ public class ActionExecutor extends AgentRunningSubModule<List<ImmediateActionDa
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelKey() {
|
||||
return "action_executor";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withBasicPrompt() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package work.slhaf.partner.module.modules.action.dispatcher.executor;
|
||||
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
||||
import work.slhaf.partner.module.modules.action.dispatcher.executor.entity.RepairerInput;
|
||||
import work.slhaf.partner.module.modules.action.dispatcher.executor.entity.RepairerResult;
|
||||
|
||||
/**
|
||||
* 负责识别行动链的调整,可通过协调 {@link DynamicActionGenerator} 生成新的行动单元(必要时持久化)、或者依据现有输出结果与已知信息和可选行动单元直接调整行动链、如果当前局部信息无法满足,将发起自对话借助干预模块进行操作或者借助自对话通道向用户发起沟通请求
|
||||
*/
|
||||
@AgentSubModule
|
||||
public class ActionRepairer extends AgentRunningSubModule<RepairerInput, RepairerResult> implements ActivateModel {
|
||||
|
||||
@Override
|
||||
public RepairerResult execute(RepairerInput data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelKey() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withBasicPrompt() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package work.slhaf.partner.module.modules.action.dispatcher.executor;
|
||||
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
||||
import work.slhaf.partner.module.modules.action.dispatcher.executor.entity.GeneratorInput;
|
||||
import work.slhaf.partner.module.modules.action.dispatcher.executor.entity.GeneratorResult;
|
||||
|
||||
/**
|
||||
* 负责依据输入内容生成可执行的动态行动单元,并选择是否持久化至 SandboxRunner 容器内
|
||||
*/
|
||||
@AgentSubModule
|
||||
public class DynamicActionGenerator extends AgentRunningSubModule<GeneratorInput, GeneratorResult> implements ActivateModel {
|
||||
|
||||
@Override
|
||||
public GeneratorResult execute(GeneratorInput data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelKey() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withBasicPrompt() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package work.slhaf.partner.module.modules.action.dispatcher.executor;
|
||||
|
||||
import work.slhaf.partner.api.agent.factory.module.annotation.AgentSubModule;
|
||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.ActivateModel;
|
||||
import work.slhaf.partner.api.agent.runtime.interaction.flow.abstracts.AgentRunningSubModule;
|
||||
import work.slhaf.partner.module.modules.action.dispatcher.executor.entity.ParamsExtractorInput;
|
||||
|
||||
/**
|
||||
* 负责依据输入内容进行行动单元的参数信息提取
|
||||
*/
|
||||
@AgentSubModule
|
||||
public class ParamsExtractor extends AgentRunningSubModule<ParamsExtractorInput, String[]> implements ActivateModel {
|
||||
|
||||
@Override
|
||||
public String[] execute(ParamsExtractorInput data) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelKey() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean withBasicPrompt() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package work.slhaf.partner.module.modules.action.dispatcher.executor.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GeneratorInput {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package work.slhaf.partner.module.modules.action.dispatcher.executor.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GeneratorResult {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package work.slhaf.partner.module.modules.action.dispatcher.executor.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ParamsExtractorInput {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package work.slhaf.partner.module.modules.action.dispatcher.executor.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RepairerInput {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package work.slhaf.partner.module.modules.action.dispatcher.executor.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RepairerResult {
|
||||
}
|
||||
@@ -96,6 +96,7 @@ public class InterventionHandler extends AgentRunningSubModule<HandlerInput, Voi
|
||||
.map(actionKey -> actionCapability.loadMetaAction(actionKey))
|
||||
.toList();
|
||||
|
||||
//TODO 需要将干预逻辑下放至 ActionCapability ,因为 ActionExecutor 中也存在干预操作
|
||||
switch (intervention.getType()) {
|
||||
case InterventionType.APPEND -> handleAppend(actionData, intervention.getOrder(), actions);
|
||||
case InterventionType.INSERT -> handleInsert(actionData, intervention.getOrder(), actions, phaser);
|
||||
|
||||
Reference in New Issue
Block a user